From 6da59413df8a4b66376da7e42e2539c30ef32aed Mon Sep 17 00:00:00 2001 From: Andrei Kislichenko Date: Mon, 25 Mar 2024 19:04:54 -0400 Subject: [PATCH] WIP --- lib/relaton_isbn.rb | 1 - lib/relaton_isbn/config.rb | 10 ---------- lib/relaton_isbn/open_library.rb | 8 ++++---- lib/relaton_isbn/util.rb | 5 +---- spec/relaton_isbn/config_spec.rb | 10 ---------- spec/relaton_isbn/openlibrary_spec.rb | 8 ++++---- spec/relaton_isbn/util_spec.rb | 5 ----- spec/vcr_cassettes/success.yml | 8 +++++--- 8 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 lib/relaton_isbn/config.rb delete mode 100644 spec/relaton_isbn/config_spec.rb delete mode 100644 spec/relaton_isbn/util_spec.rb diff --git a/lib/relaton_isbn.rb b/lib/relaton_isbn.rb index af74ad7..1943b1e 100644 --- a/lib/relaton_isbn.rb +++ b/lib/relaton_isbn.rb @@ -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" diff --git a/lib/relaton_isbn/config.rb b/lib/relaton_isbn/config.rb deleted file mode 100644 index ca15c93..0000000 --- a/lib/relaton_isbn/config.rb +++ /dev/null @@ -1,10 +0,0 @@ -module RelatonIsbn - module Config - include RelatonBib::Config - end - extend Config - - class Configuration < RelatonBib::Configuration - PROGNAME = "relaton-isbn".freeze - end -end diff --git a/lib/relaton_isbn/open_library.rb b/lib/relaton_isbn/open_library.rb index c26a459..0a9f359 100644 --- a/lib/relaton_isbn/open_library.rb +++ b/lib/relaton_isbn/open_library.rb @@ -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 diff --git a/lib/relaton_isbn/util.rb b/lib/relaton_isbn/util.rb index 3b01b2b..94566f8 100644 --- a/lib/relaton_isbn/util.rb +++ b/lib/relaton_isbn/util.rb @@ -1,9 +1,6 @@ module RelatonIsbn module Util extend RelatonBib::Util - - def self.logger - RelatonIsbn.configuration.logger - end + PROGNAME = "relaton-isbn".freeze end end diff --git a/spec/relaton_isbn/config_spec.rb b/spec/relaton_isbn/config_spec.rb deleted file mode 100644 index 70ded07..0000000 --- a/spec/relaton_isbn/config_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -describe RelatonIsbn do - after { described_class.instance_variable_set :@configuration, nil } - - it "configure" do - described_class.configure do |conf| - conf.logger = :logger - end - expect(described_class.configuration.logger).to eq :logger - end -end diff --git a/spec/relaton_isbn/openlibrary_spec.rb b/spec/relaton_isbn/openlibrary_spec.rb index 32ae25f..9841db6 100644 --- a/spec/relaton_isbn/openlibrary_spec.rb +++ b/spec/relaton_isbn/openlibrary_spec.rb @@ -6,8 +6,8 @@ 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 @@ -15,14 +15,14 @@ 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 diff --git a/spec/relaton_isbn/util_spec.rb b/spec/relaton_isbn/util_spec.rb deleted file mode 100644 index 385a9ef..0000000 --- a/spec/relaton_isbn/util_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -describe RelatonIsbn::Util do - it "#respond_to_missing?" do - expect(described_class.respond_to?(:warn)).to be true - end -end diff --git a/spec/vcr_cassettes/success.yml b/spec/vcr_cassettes/success.yml index a94ffd6..b27fc75 100644 --- a/spec/vcr_cassettes/success.yml +++ b/spec/vcr_cassettes/success.yml @@ -13,6 +13,8 @@ http_interactions: - "*/*" User-Agent: - Ruby + Host: + - openlibrary.org response: status: code: 200 @@ -21,7 +23,7 @@ http_interactions: Server: - nginx/1.18.0 (Ubuntu) Date: - - Thu, 29 Feb 2024 00:50:22 GMT + - Sun, 17 Mar 2024 16:59:40 GMT Content-Type: - application/json Transfer-Encoding: @@ -29,7 +31,7 @@ http_interactions: Connection: - keep-alive X-Ol-Stats: - - '"IB 6 0.115 MC 13 0.012 OT 1 0.330 TT 0 0.495"' + - '"IB 4 0.166 MC 10 0.013 TT 0 0.217"' Referrer-Policy: - no-referrer-when-downgrade body: @@ -100,5 +102,5 @@ http_interactions: YXN0X21vZGlmaWVkIjogeyJ0eXBlIjogIi90eXBlL2RhdGV0aW1lIiwgInZh bHVlIjogIjIwMjMtMDQtMDRUMDQ6MzM6MjguNDQ5MzUzIn19fX19LCAiaXRl bXMiOiBbXX0= - recorded_at: Thu, 29 Feb 2024 00:50:22 GMT + recorded_at: Sun, 17 Mar 2024 16:59:40 GMT recorded_with: VCR 6.2.0