Class: Olibrary::Data

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



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

def authors
  @authors
end

#classificationsObject

Returns the value of attribute classifications.



9
10
11
# File 'lib/olibrary/data.rb', line 9

def classifications
  @classifications
end

#coverObject

Returns the value of attribute cover.



15
16
17
# File 'lib/olibrary/data.rb', line 15

def cover
  @cover
end

#ebooksObject

Returns the value of attribute ebooks.



16
17
18
# File 'lib/olibrary/data.rb', line 16

def ebooks
  @ebooks
end

#excerptsObject

Returns the value of attribute excerpts.



13
14
15
# File 'lib/olibrary/data.rb', line 13

def excerpts
  @excerpts
end

#identifiersObject

Returns the value of attribute identifiers.



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

def identifiers
  @identifiers
end

Returns the value of attribute links.



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

def links
  @links
end

#pagesObject

Returns the value of attribute pages.



17
18
19
# File 'lib/olibrary/data.rb', line 17

def pages
  @pages
end

#publish_dateObject

Returns the value of attribute publish_date.



12
13
14
# File 'lib/olibrary/data.rb', line 12

def publish_date
  @publish_date
end

#publish_placesObject

Returns the value of attribute publish_places.



11
12
13
# File 'lib/olibrary/data.rb', line 11

def publish_places
  @publish_places
end

#publishersObject

Returns the value of attribute publishers.



11
12
13
# File 'lib/olibrary/data.rb', line 11

def publishers
  @publishers
end

#subject_peopleObject

Returns the value of attribute subject_people.



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

def subject_people
  @subject_people
end

#subject_placesObject

Returns the value of attribute subject_places.



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

def subject_places
  @subject_places
end

#subject_timesObject

Returns the value of attribute subject_times.



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

def subject_times
  @subject_times
end

#subjectsObject

Returns the value of attribute subjects.



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

def subjects
  @subjects
end

#subtitleObject

Returns the value of attribute subtitle.



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

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

Class Method Details

.find(type, key) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/olibrary/data.rb', line 36

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.title = book["title"] 
    book_meta.subtitle = book["subtitle"]
    book_meta.authors = book["authors"]
    book_meta.identifiers = book["identifiers"]
    book_meta.classifications = book["classifications"]
    book_meta.subjects = book["subjects"]
    book_meta.subject_places = book["subject_places"]
    book_meta.subject_people = book["subject_people"]
    book_meta.subject_times = book["subject_times"]
    book_meta.publishers = book["publishers"]
    book_meta.publish_places = book["publish_places"]
    book_meta.publish_date = book["publish_date"]
    book_meta.excerpts = book["excerpts"]
    book_meta.links = book["links"]
    book_meta.cover = book["cover"]
    book_meta.ebooks = book["ebooks"]
    book_meta.pages = book["number_of_pages"]
    book_meta.weight = book["weight"]
    
    book_meta
  else
    nil
  end    
end

.find_by_isbn(key) ⇒ Object



20
21
22
# File 'lib/olibrary/data.rb', line 20

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

.find_by_lccn(key) ⇒ Object



24
25
26
# File 'lib/olibrary/data.rb', line 24

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

.find_by_oclc(key) ⇒ Object



28
29
30
# File 'lib/olibrary/data.rb', line 28

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

.find_by_olid(key) ⇒ Object



32
33
34
# File 'lib/olibrary/data.rb', line 32

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