openlibrary 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.rdoc +62 -0
- data/Rakefile +1 -0
- data/lib/openlibrary.rb +10 -0
- data/lib/openlibrary/data.rb +75 -0
- data/lib/openlibrary/details.rb +0 -0
- data/lib/openlibrary/version.rb +3 -0
- data/lib/openlibrary/view.rb +53 -0
- data/openlibrary.gemspec +25 -0
- metadata +98 -0
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
== Openlibrary
|
2
|
+
|
3
|
+
|
4
|
+
OPENLIBRARY is a simple wrapper for the Openlibrary REST-API.
|
5
|
+
|
6
|
+
For more information on the REST calls, you can view the api docuemtation at [http://openlibrary.org/developers/api].
|
7
|
+
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
The gem is tested against Ruby 1.9.2 and runs smoothly with Rails 3.
|
12
|
+
|
13
|
+
gem install openlibrary
|
14
|
+
|
15
|
+
or in your Gemfile:
|
16
|
+
|
17
|
+
gem 'openlibrary'
|
18
|
+
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
You can retrieve a book's Openlibrary listing information.
|
23
|
+
|
24
|
+
# just require
|
25
|
+
require 'openlibrary'
|
26
|
+
|
27
|
+
Initiate your search
|
28
|
+
|
29
|
+
# create a class proxy
|
30
|
+
view = Openlibrary::View
|
31
|
+
|
32
|
+
# lookup an item with the ISBN-10 or ISBN-13
|
33
|
+
book_view = view.find_by_isbn("0451526538")
|
34
|
+
|
35
|
+
or you can use the other built-in finder methods:
|
36
|
+
|
37
|
+
find_by_lccn # Library of congress catalog number
|
38
|
+
find_by_oclc # Worldcat Control Number
|
39
|
+
find_by_olid # Openlibrary ID
|
40
|
+
|
41
|
+
Extract the book information:
|
42
|
+
|
43
|
+
# have a look at the book's info URL on Openlibrary.org
|
44
|
+
book_view.info_url
|
45
|
+
|
46
|
+
# or grab the URL of the book's thumbnail as shown on Openlibrary.org
|
47
|
+
book_view.thumbnail_url
|
48
|
+
|
49
|
+
You can also retrieve a book's full metadata details.
|
50
|
+
|
51
|
+
# create a class proxy
|
52
|
+
details = Openlibrary::Data
|
53
|
+
|
54
|
+
# lookup an item with the ISBN-10 or ISBN-13
|
55
|
+
book_details = details.find_by_isbn("0451526538")
|
56
|
+
|
57
|
+
# have a look at the book's title
|
58
|
+
book_details.title
|
59
|
+
|
60
|
+
# or an array of authors
|
61
|
+
book_view.authors
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/openlibrary.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
module Openlibrary
|
2
|
+
|
3
|
+
class Data
|
4
|
+
attr_accessor :url
|
5
|
+
attr_accessor :title
|
6
|
+
attr_accessor :subtitle
|
7
|
+
attr_accessor :authors
|
8
|
+
attr_accessor :identifiers
|
9
|
+
attr_accessor :classifications
|
10
|
+
attr_accessor :subjects, :subject_places, :subject_people, :subject_times
|
11
|
+
attr_accessor :publishers, :publish_places
|
12
|
+
attr_accessor :date_published
|
13
|
+
attr_accessor :excerpts
|
14
|
+
attr_accessor :links
|
15
|
+
attr_accessor :cover
|
16
|
+
attr_accessor :ebooks
|
17
|
+
attr_accessor :pages
|
18
|
+
attr_accessor :weight
|
19
|
+
|
20
|
+
def self.find_by_isbn(key)
|
21
|
+
find("ISBN",key)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find_by_lccn(key)
|
25
|
+
find("LCCN",key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_by_oclc(key)
|
29
|
+
find("OCLC",key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.find_by_olid(key)
|
33
|
+
find("OLID",key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.find(type,key)
|
37
|
+
request_url = "http://openlibrary.org/api/books?bibkeys=#{type}:#{key}&format=json&jscmd=data"
|
38
|
+
response = RestClient.get request_url
|
39
|
+
response_data = JSON.parse(response)
|
40
|
+
book = response_data["#{type}:#{key}"]
|
41
|
+
if book
|
42
|
+
book_meta = new
|
43
|
+
|
44
|
+
book_meta.title = book["title"]
|
45
|
+
book_meta.subtitle = book["subtitle"]
|
46
|
+
book_meta.authors = book["authors"]
|
47
|
+
book_meta.identifiers = book["identifiers"]
|
48
|
+
book_meta.classifications = book["classifications"]
|
49
|
+
book_meta.subjects = book["subjects"]
|
50
|
+
book_meta.subject_places = book["subject_places"]
|
51
|
+
book_meta.subject_people = book["subject_people"]
|
52
|
+
book_meta.publishers = book["publishers"]
|
53
|
+
book_meta.publish_places = book["publish_places"]
|
54
|
+
book_meta.date_published = book["date_published"]
|
55
|
+
book_meta.excerpts = book["excerpts"]
|
56
|
+
book_meta.links = book["links"]
|
57
|
+
book_meta.cover = book["cover"]
|
58
|
+
book_meta.ebooks = book["ebooks"]
|
59
|
+
book_meta.pages = book["pages"]
|
60
|
+
book_meta.weight = book["weight"]
|
61
|
+
|
62
|
+
#for debugging purposes
|
63
|
+
#puts book_meta
|
64
|
+
|
65
|
+
book_meta
|
66
|
+
else
|
67
|
+
puts "OPENLIBRARY: Using #{type} with #{key}, not found on Openlibrary.org"
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Openlibrary
|
2
|
+
|
3
|
+
class View
|
4
|
+
attr_accessor :bib_key
|
5
|
+
attr_accessor :info_url
|
6
|
+
attr_accessor :preview
|
7
|
+
attr_accessor :preview_url
|
8
|
+
attr_accessor :thumbnail_url
|
9
|
+
|
10
|
+
def self.find_by_isbn(key)
|
11
|
+
find("ISBN",key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_by_lccn(key)
|
15
|
+
find("LCCN",key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_by_oclc(key)
|
19
|
+
find("OCLC",key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_by_olid(key)
|
23
|
+
find("OLID",key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(key)
|
27
|
+
response = RestClient.get "http://openlibrary.org/api/books?bibkeys=ISBN:#{key}&format=json&jscmd=viewapi"
|
28
|
+
|
29
|
+
response_data = JSON.parse(response)
|
30
|
+
view = response_data["#{type}:#{key}"]
|
31
|
+
if view
|
32
|
+
view_meta = new
|
33
|
+
|
34
|
+
view_meta.bib_key = view["bib_key"]
|
35
|
+
view_meta.info_url = view["info_url"]
|
36
|
+
view_meta.preview = view["preview"]
|
37
|
+
view_meta.preview_url = view["preview_url"]
|
38
|
+
view_meta.thumbnail_url = view["thumbnail_url"]
|
39
|
+
|
40
|
+
#for debugging purposes
|
41
|
+
#puts view_meta
|
42
|
+
|
43
|
+
view_meta
|
44
|
+
else
|
45
|
+
puts "OPENLIBRARY: #{key} was not found on Openlibrary.org"
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
data/openlibrary.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "openlibrary/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "openlibrary"
|
7
|
+
s.version = Openlibrary::VERSION
|
8
|
+
s.authors = ["Jay Fajardo"]
|
9
|
+
s.email = ["jmrfajardo@gmail.com"]
|
10
|
+
s.homepage = "http://www.proudcloud.net"
|
11
|
+
s.summary = %q{Ruby Interface for the OpenLibrary API}
|
12
|
+
s.description = %q{OpenLibrary API Interface}
|
13
|
+
|
14
|
+
s.rubyforge_project = "openlibrary"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "json"
|
24
|
+
s.add_runtime_dependency "rest-client"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openlibrary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.4
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jay Fajardo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-03 00:00:00 +08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rest-client
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: OpenLibrary API Interface
|
50
|
+
email:
|
51
|
+
- jmrfajardo@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- README.rdoc
|
62
|
+
- Rakefile
|
63
|
+
- lib/openlibrary.rb
|
64
|
+
- lib/openlibrary/data.rb
|
65
|
+
- lib/openlibrary/details.rb
|
66
|
+
- lib/openlibrary/version.rb
|
67
|
+
- lib/openlibrary/view.rb
|
68
|
+
- openlibrary.gemspec
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://www.proudcloud.net
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project: openlibrary
|
93
|
+
rubygems_version: 1.6.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby Interface for the OpenLibrary API
|
97
|
+
test_files: []
|
98
|
+
|