Method: RelatonIsbn::OpenLibrary#get

Defined in:
lib/relaton_isbn/open_library.rb

#get(ref, _date = nil, _opts = {}) ⇒ Object

rubocop:disable Metrics/MethodLength



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/relaton_isbn/open_library.rb', line 10

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

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

  resp = request_api isbn
  unless resp
    Util.info "Not found.", key: ref
    return
  end

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