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 CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
+ *~
@@ -1,9 +1,9 @@
1
1
  == Openlibrary
2
2
 
3
3
 
4
- OPENLIBRARY is a simple wrapper for the Openlibrary REST-API.
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 api documentation at [here](http://openlibrary.org/developers/api).
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 Openlibrary listing information.
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
- book_view.authors
61
+ book_details.authors
62
62
 
63
63
  == CONTRIBUTORS
64
64
 
65
- {Jay Fajardo}[http://github.com/jayfajardo]
66
- {Robert Berry}[http://github.com/bdigital]
67
- {Eric Larson}[http://github.com/ewlarson]
68
- {Charles Horn}[http://github.com/hornc]
69
-
70
- == TO DO
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
@@ -1,6 +1,7 @@
1
- require "openlibrary/version"
1
+ require 'openlibrary/version'
2
2
  require 'json'
3
3
  require 'rest-client'
4
+ require 'uri'
4
5
 
5
6
  module Openlibrary
6
7
 
@@ -34,10 +34,14 @@ module Openlibrary
34
34
  end
35
35
 
36
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
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
@@ -1,3 +1,3 @@
1
1
  module Openlibrary
2
- VERSION = "0.0.9"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -24,10 +24,14 @@ module Openlibrary
24
24
  end
25
25
 
26
26
  def self.find(type,key)
27
- response = RestClient.get "http://openlibrary.org/api/books?bibkeys=#{type}:#{key}&format=json&jscmd=viewapi"
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
-
@@ -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
@@ -1,8 +1,8 @@
1
1
  require 'rspec'
2
2
  require 'openlibrary'
3
+ require 'rest-client'
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.color_enabled = true
6
7
  config.formatter = 'documentation'
7
8
  end
8
-
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openlibrary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.9
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: 2012-06-21 00:00:00 Z
13
+ date: 2013-02-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec