Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logger #3

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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
Expand Down
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
2 changes: 1 addition & 1 deletion lib/relaton_isbn/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIsbn
VERSION = "1.18.1".freeze
VERSION = "1.19.0".freeze
end
2 changes: 1 addition & 1 deletion relaton_isbn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.

Loading