Class: Olibrary::View

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bib_keyObject

Returns the value of attribute bib_key.



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

def bib_key
  @bib_key
end

#info_urlObject

Returns the value of attribute info_url.



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

def info_url
  @info_url
end

#previewObject

Returns the value of attribute preview.



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

def preview
  @preview
end

#preview_urlObject

Returns the value of attribute preview_url.



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

def preview_url
  @preview_url
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



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

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/view.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=viewapi"
  response_data = JSON.parse(response)
  view = response_data["#{type}:#{key}"]

  if view 
    view_meta = new  

    view_meta.bib_key = view["bib_key"] 
    view_meta.info_url = view["info_url"]
    view_meta.preview = view["preview"]
    view_meta.preview_url = view["preview_url"]
    view_meta.thumbnail_url = view["thumbnail_url"]
    
    view_meta
  else
    nil
  end    
end

.find_by_isbn(key) ⇒ Object



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

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

.find_by_lccn(key) ⇒ Object



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

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

.find_by_oclc(key) ⇒ Object



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

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

.find_by_olid(key) ⇒ Object



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

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