openlibrary 0.0.9 → 1.0.0
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 +1 -0
- data/README.rdoc +10 -12
- data/lib/openlibrary.rb +2 -1
- data/lib/openlibrary/data.rb +6 -6
- data/lib/openlibrary/version.rb +1 -1
- data/lib/openlibrary/view.rb +5 -7
- data/spec/openlibrary_spec.rb +45 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
== Openlibrary
|
2
2
|
|
3
3
|
|
4
|
-
OPENLIBRARY is a simple wrapper for the
|
4
|
+
OPENLIBRARY is a simple wrapper for the Open Library REST-API.
|
5
5
|
|
6
|
-
For more information on the REST calls, you can view the
|
6
|
+
For more information on the REST calls, you can view the Open Library Books API documentation here[http://openlibrary.org/dev/docs/api/books], or visit the {Open Library Developer Center}[http://openlibrary.org/developers/api].
|
7
7
|
|
8
8
|
|
9
9
|
== Installation
|
@@ -19,7 +19,7 @@ or in your Gemfile:
|
|
19
19
|
|
20
20
|
== Usage
|
21
21
|
|
22
|
-
You can retrieve a book's
|
22
|
+
You can retrieve a book's Open Library listing information.
|
23
23
|
|
24
24
|
# just require
|
25
25
|
require 'openlibrary'
|
@@ -58,15 +58,13 @@ You can also retrieve a book's full metadata details.
|
|
58
58
|
book_details.title
|
59
59
|
|
60
60
|
# or an array of authors
|
61
|
-
|
61
|
+
book_details.authors
|
62
62
|
|
63
63
|
== CONTRIBUTORS
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
Write Tests
|
65
|
+
* Jay Fajardo https://github.com/jayfajardo
|
66
|
+
* Robert Berry https://github.com/bdigital
|
67
|
+
* Eric Larson https://github.com/ewlarson
|
68
|
+
* Charles Horn https://github.com/hornc
|
69
|
+
* John Shutt https://github.com/pemulis
|
70
|
+
* Alex Grant https://github.com/grantovich
|
data/lib/openlibrary.rb
CHANGED
data/lib/openlibrary/data.rb
CHANGED
@@ -34,10 +34,14 @@ module Openlibrary
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.find(type,key)
|
37
|
-
|
38
|
-
|
37
|
+
type_for_uri = URI.encode_www_form_component(type)
|
38
|
+
key_for_uri = URI.encode_www_form_component(key)
|
39
|
+
|
40
|
+
response = RestClient.get "http://openlibrary.org/api/books" +
|
41
|
+
"?bibkeys=#{type_for_uri}:#{key_for_uri}&format=json&jscmd=data"
|
39
42
|
response_data = JSON.parse(response)
|
40
43
|
book = response_data["#{type}:#{key}"]
|
44
|
+
|
41
45
|
if book
|
42
46
|
book_meta = new
|
43
47
|
|
@@ -60,12 +64,8 @@ module Openlibrary
|
|
60
64
|
book_meta.pages = book["number_of_pages"]
|
61
65
|
book_meta.weight = book["weight"]
|
62
66
|
|
63
|
-
#for debugging purposes
|
64
|
-
#puts book_meta
|
65
|
-
|
66
67
|
book_meta
|
67
68
|
else
|
68
|
-
puts "OPENLIBRARY: Using #{type} with #{key}, not found on Openlibrary.org"
|
69
69
|
nil
|
70
70
|
end
|
71
71
|
end
|
data/lib/openlibrary/version.rb
CHANGED
data/lib/openlibrary/view.rb
CHANGED
@@ -24,10 +24,14 @@ module Openlibrary
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.find(type,key)
|
27
|
-
|
27
|
+
type_for_uri = URI.encode_www_form_component(type)
|
28
|
+
key_for_uri = URI.encode_www_form_component(key)
|
28
29
|
|
30
|
+
response = RestClient.get "http://openlibrary.org/api/books" +
|
31
|
+
"?bibkeys=#{type_for_uri}:#{key_for_uri}&format=json&jscmd=viewapi"
|
29
32
|
response_data = JSON.parse(response)
|
30
33
|
view = response_data["#{type}:#{key}"]
|
34
|
+
|
31
35
|
if view
|
32
36
|
view_meta = new
|
33
37
|
|
@@ -37,17 +41,11 @@ module Openlibrary
|
|
37
41
|
view_meta.preview_url = view["preview_url"]
|
38
42
|
view_meta.thumbnail_url = view["thumbnail_url"]
|
39
43
|
|
40
|
-
#for debugging purposes
|
41
|
-
#puts view_meta
|
42
|
-
|
43
44
|
view_meta
|
44
45
|
else
|
45
|
-
puts "OPENLIBRARY: #{key} was not found on Openlibrary.org"
|
46
46
|
nil
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
|
52
51
|
end
|
53
|
-
|
data/spec/openlibrary_spec.rb
CHANGED
@@ -6,3 +6,48 @@ describe Openlibrary do
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
describe Openlibrary::View do
|
10
|
+
before do
|
11
|
+
@book_view = Openlibrary::View.new
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { @book_view }
|
15
|
+
|
16
|
+
it { should_not respond_to(:some_random_thing) }
|
17
|
+
|
18
|
+
it { should respond_to(:bib_key) }
|
19
|
+
it { should respond_to(:info_url) }
|
20
|
+
it { should respond_to(:preview) }
|
21
|
+
it { should respond_to(:preview_url) }
|
22
|
+
it { should respond_to(:thumbnail_url) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Openlibrary::Data do
|
26
|
+
before do
|
27
|
+
@book_data = Openlibrary::Data.new
|
28
|
+
end
|
29
|
+
|
30
|
+
subject { @book_data }
|
31
|
+
|
32
|
+
it { should_not respond_to(:some_random_thing) }
|
33
|
+
|
34
|
+
it { should respond_to(:url) }
|
35
|
+
it { should respond_to(:title) }
|
36
|
+
it { should respond_to(:subtitle) }
|
37
|
+
it { should respond_to(:authors) }
|
38
|
+
it { should respond_to(:identifiers) }
|
39
|
+
it { should respond_to(:classifications) }
|
40
|
+
it { should respond_to(:subjects) }
|
41
|
+
it { should respond_to(:subject_places) }
|
42
|
+
it { should respond_to(:subject_people) }
|
43
|
+
it { should respond_to(:subject_times) }
|
44
|
+
it { should respond_to(:publishers) }
|
45
|
+
it { should respond_to(:publish_places) }
|
46
|
+
it { should respond_to(:publish_date) }
|
47
|
+
it { should respond_to(:excerpts) }
|
48
|
+
it { should respond_to(:links) }
|
49
|
+
it { should respond_to(:cover) }
|
50
|
+
it { should respond_to(:ebooks) }
|
51
|
+
it { should respond_to(:pages) }
|
52
|
+
it { should respond_to(:weight) }
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: openlibrary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 1.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jay Fajardo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2013-02-02 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|