Module: Olibrary::Books

Included in:
Client
Defined in:
lib/olibrary/client/books.rb

Instance Method Summary collapse

Instance Method Details

#book(olid) ⇒ Object

Find books in Open Library by OLID, ISBN, LCCN, or OCLC



5
6
7
8
# File 'lib/olibrary/client/books.rb', line 5

def book(olid)
  data = request("/books/#{olid}")
  Hashie::Mash.new(data)
end

#book_by_isbn(isbn) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/olibrary/client/books.rb', line 10

def book_by_isbn(isbn)
  type = "/type/edition"
  if isbn.length == 10
    data = query("type=#{type}&isbn_10=#{isbn}")
  elsif isbn.length == 13
    data = query("type=#{type}&isbn_13=#{isbn}")
  else
    raise ArgumentError, "ISBN must be 10 or 13 characters."
  end
end

#book_by_lccn(lccn) ⇒ Object



21
22
23
24
# File 'lib/olibrary/client/books.rb', line 21

def book_by_lccn(lccn)
  type = "/type/edition"
  data = query("type=#{type}&lccn=#{lccn}")
end

#book_by_oclc(oclc) ⇒ Object



26
27
28
29
# File 'lib/olibrary/client/books.rb', line 26

def book_by_oclc(oclc)
  type = "/type/edition"
  data = query("type=#{type}&oclc_numbers=#{oclc}")
end