Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Mar 25, 2024
1 parent 60771a1 commit 6da5941
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 41 deletions.
1 change: 0 additions & 1 deletion lib/relaton_isbn.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "net/http"
require "relaton_bib"
require_relative "relaton_isbn/version"
require_relative "relaton_isbn/config"
require_relative "relaton_isbn/util"
require_relative "relaton_isbn/isbn"
require_relative "relaton_isbn/parser"
Expand Down
10 changes: 0 additions & 10 deletions lib/relaton_isbn/config.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/relaton_isbn/open_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ module OpenLibrary
ENDPOINT = "http://openlibrary.org/api/volumes/brief/isbn/".freeze

def get(ref, _date = nil, _opts = {}) # rubocop:disable Metrics/MethodLength
Util.warn "(#{ref}) Fetching from OpenLibrary ..."
Util.info "Fetching from OpenLibrary ...", key: ref

isbn = Isbn.new(ref).parse
unless isbn
Util.warn "(#{ref}) Incorrect ISBN."
Util.info "Incorrect ISBN.", key: ref
return
end

resp = request_api isbn
unless resp
Util.warn "(#{ref}) Not found."
Util.info "Not found.", key: ref
return
end

bib = Parser.parse resp
Util.warn "(#{ref}) Found: `#{bib.docidentifier.first.id}`"
Util.info "Found: `#{bib.docidentifier.first.id}`", key: ref
bib
end

Expand Down
5 changes: 1 addition & 4 deletions lib/relaton_isbn/util.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module RelatonIsbn
module Util
extend RelatonBib::Util

def self.logger
RelatonIsbn.configuration.logger
end
PROGNAME = "relaton-isbn".freeze
end
end
10 changes: 0 additions & 10 deletions spec/relaton_isbn/config_spec.rb

This file was deleted.

8 changes: 4 additions & 4 deletions spec/relaton_isbn/openlibrary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
bib = double "bib", docidentifier: [double("id", id: "id")]
expect(RelatonIsbn::Parser).to receive(:parse).with(:doc).and_return bib
expect(described_class.get("ISBN 9780120644810")).to eq bib
end.to output(include("[relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ...",
"[relaton-isbn] (ISBN 9780120644810) Found: `id`")).to_stderr_from_any_process
end.to output(include("[relaton-isbn] INFO: (ISBN 9780120644810) Fetching from OpenLibrary ...",
"[relaton-isbn] INFO: (ISBN 9780120644810) Found: `id`")).to_stderr_from_any_process
end

it "not found" do
expect do
expect(described_class).to receive(:request_api).with("9780120644810").and_return nil
expect(RelatonIsbn::Parser).not_to receive(:parse)
expect(described_class.get("ISBN 9780120644810")).to be_nil
end.to output(include("[relaton-isbn] (ISBN 9780120644810) Not found.")).to_stderr_from_any_process
end.to output(include("[relaton-isbn] INFO: (ISBN 9780120644810) Not found.")).to_stderr_from_any_process
end

it "incorrect ISBN" do
expect do
expect(described_class).not_to receive(:request_api)
expect(described_class.get("ISBN")).to be_nil
end.to output(include("[relaton-isbn] (ISBN) Incorrect ISBN.")).to_stderr_from_any_process
end.to output(include("[relaton-isbn] INFO: (ISBN) Incorrect ISBN.")).to_stderr_from_any_process
end
end

Expand Down
5 changes: 0 additions & 5 deletions spec/relaton_isbn/util_spec.rb

This file was deleted.

8 changes: 5 additions & 3 deletions spec/vcr_cassettes/success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6da5941

Please sign in to comment.