From 6da59413df8a4b66376da7e42e2539c30ef32aed Mon Sep 17 00:00:00 2001 From: Andrei Kislichenko Date: Mon, 25 Mar 2024 19:04:54 -0400 Subject: [PATCH 1/2] 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 From 5b5b5c45a7558ba817a302e66916038085a4f16f Mon Sep 17 00:00:00 2001 From: Andrei Kislichenko Date: Wed, 3 Jul 2024 16:24:26 -0400 Subject: [PATCH 2/2] update README --- README.adoc | 19 ++++++------------- lib/relaton_isbn/version.rb | 2 +- relaton_isbn.gemspec | 2 +- spec/vcr_cassettes/success.yml | 6 +++--- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/README.adoc b/README.adoc index 94f8fce..2db2cf1 100644 --- a/README.adoc +++ b/README.adoc @@ -39,26 +39,15 @@ $ gem install relaton-isbn == Usage -=== Configuration +=== Retrieving bibliographic items using OpenLibrary API -Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonIsbn.configure` block. +To retrieve bibliographic items, use `RelatonIsbn::OpenLibrary.get` method with ISBN-10 or ISBN-13 as an argument. Allowed prefixes are `ISBN`, `isbn:`. Prefix and hyphens are optional. The method returns `RelatonBib::BibliographicItem` object. [source,ruby] ---- require 'relaton_isbn' => true -RelatonIsbn.configure do |config| - config.logger.level = Logger::DEBUG -end ----- - -=== Retrieving bibliographic items using OpenLibrary API - -To retrieve bibliographic items, use `RelatonIsbn::OpenLibrary.get` method with ISBN-10 or ISBN-13 as an argument. Allowed prefixes are `ISBN`, `isbn:`. Prefix and hyphens are optional. The method returns `RelatonBib::BibliographicItem` object. - -[source,ruby] ----- # get document by ISBN-13 > ibitem = RelatonIsbn::OpenLibrary.get "ISBN 978-0-12-064481-0" [relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ... @@ -129,6 +118,10 @@ To retrieve bibliographic items, use `RelatonIsbn::OpenLibrary.get` method with "place"=>[{"city"=>"Boston"}, {"city"=>"London"}]} ---- +=== Logging + +RelatonIsbn uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the https://github.com/relaton/relaton-logger#usage[relaton-logger] documentation. + == Development After checking out the repo, run `bin/setup` to install dependencies. Then, run diff --git a/lib/relaton_isbn/version.rb b/lib/relaton_isbn/version.rb index 2198a20..26546ca 100644 --- a/lib/relaton_isbn/version.rb +++ b/lib/relaton_isbn/version.rb @@ -1,3 +1,3 @@ module RelatonIsbn - VERSION = "1.18.1".freeze + VERSION = "1.19.0".freeze end diff --git a/relaton_isbn.gemspec b/relaton_isbn.gemspec index 02b11ef..16c7948 100644 --- a/relaton_isbn.gemspec +++ b/relaton_isbn.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem - spec.add_dependency "relaton-bib", "~> 1.18.0" + spec.add_dependency "relaton-bib", "~> 1.19.0" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/spec/vcr_cassettes/success.yml b/spec/vcr_cassettes/success.yml index b27fc75..eda9c10 100644 --- a/spec/vcr_cassettes/success.yml +++ b/spec/vcr_cassettes/success.yml @@ -23,7 +23,7 @@ http_interactions: Server: - nginx/1.18.0 (Ubuntu) Date: - - Sun, 17 Mar 2024 16:59:40 GMT + - Mon, 01 Jul 2024 20:06:11 GMT Content-Type: - application/json Transfer-Encoding: @@ -31,7 +31,7 @@ http_interactions: Connection: - keep-alive X-Ol-Stats: - - '"IB 4 0.166 MC 10 0.013 TT 0 0.217"' + - '"IB 6 0.132 MC 13 0.006 OT 1 0.529 TT 0 0.702"' Referrer-Policy: - no-referrer-when-downgrade body: @@ -102,5 +102,5 @@ http_interactions: YXN0X21vZGlmaWVkIjogeyJ0eXBlIjogIi90eXBlL2RhdGV0aW1lIiwgInZh bHVlIjogIjIwMjMtMDQtMDRUMDQ6MzM6MjguNDQ5MzUzIn19fX19LCAiaXRl bXMiOiBbXX0= - recorded_at: Sun, 17 Mar 2024 16:59:40 GMT + recorded_at: Mon, 01 Jul 2024 20:06:11 GMT recorded_with: VCR 6.2.0