Class: Olibrary::Details

Inherits:
Object
  • Object
show all
Defined in:
lib/olibrary/details.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bib_keyObject

Returns the value of attribute bib_key.



5
6
7
# File 'lib/olibrary/details.rb', line 5

def bib_key
  @bib_key
end

#detailsObject

Returns the value of attribute details.



8
9
10
# File 'lib/olibrary/details.rb', line 8

def details
  @details
end

#info_urlObject

Returns the value of attribute info_url.



4
5
6
# File 'lib/olibrary/details.rb', line 4

def info_url
  @info_url
end

#preview_urlObject

Returns the value of attribute preview_url.



6
7
8
# File 'lib/olibrary/details.rb', line 6

def preview_url
  @preview_url
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



7
8
9
# File 'lib/olibrary/details.rb', line 7

def thumbnail_url
  @thumbnail_url
end

Class Method Details

.find(type, key) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/olibrary/details.rb', line 26

def self.find(type,key)
  type_for_uri = URI.encode_www_form_component(type)
  key_for_uri = URI.encode_www_form_component(key)

  response = RestClient.get "http://openlibrary.org/api/books" +
    "?bibkeys=#{type_for_uri}:#{key_for_uri}&format=json&jscmd=data"
  response_data = JSON.parse(response)
  book = response_data["#{type}:#{key}"]

  if book 
    book_meta = new  

    book_meta.info_url = book["info_url"]
    book_meta.bib_key = book["bib_key"]
    book_meta.preview_url = book["preview_url"]
    book_meta.thumbnail_url = book["thumbnail_url"]
    book_meta.details = book["details"]
    
    book_meta
  else
    nil
  end    
end

.find_by_isbn(key) ⇒ Object



10
11
12
# File 'lib/olibrary/details.rb', line 10

def self.find_by_isbn(key)
  find("ISBN",key)
end

.find_by_lccn(key) ⇒ Object



14
15
16
# File 'lib/olibrary/details.rb', line 14

def self.find_by_lccn(key)
  find("LCCN",key)
end

.find_by_oclc(key) ⇒ Object



18
19
20
# File 'lib/olibrary/details.rb', line 18

def self.find_by_oclc(key)
  find("OCLC",key)
end

.find_by_olid(key) ⇒ Object



22
23
24
# File 'lib/olibrary/details.rb', line 22

def self.find_by_olid(key)
  find("OLID",key)
end