risbn 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +19 -0
- data/VERSION +1 -1
- data/lib/risbn/gdata.rb +30 -24
- data/lib/risbn/version.rb +1 -1
- data/risbn.gemspec +2 -1
- data/spec/fixtures/0072253592.xml +1 -0
- data/spec/gdata_spec.rb +10 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -2
data/Rakefile
CHANGED
@@ -43,3 +43,22 @@ Rake::RDocTask.new do |rdoc|
|
|
43
43
|
rdoc.rdoc_files.include('README*')
|
44
44
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
45
|
end
|
46
|
+
|
47
|
+
|
48
|
+
task :fixturize do
|
49
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
50
|
+
require 'risbn'
|
51
|
+
require 'risbn/gdata'
|
52
|
+
|
53
|
+
isbn = RISBN(ENV["ISBN"])
|
54
|
+
|
55
|
+
if isbn.valid?
|
56
|
+
fpath = File.join(File.dirname(__FILE__), "spec", "fixtures", "#{ENV["ISBN"]}.xml")
|
57
|
+
|
58
|
+
File.open(fpath, "w") do |f|
|
59
|
+
f << isbn.gdata.xml
|
60
|
+
end
|
61
|
+
else
|
62
|
+
puts "provide a valid ISBN as an env var."
|
63
|
+
end
|
64
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/risbn/gdata.rb
CHANGED
@@ -21,14 +21,16 @@ class RISBN
|
|
21
21
|
|
22
22
|
# performs a google search by isbn to retrieve the actual google book id.
|
23
23
|
def entry_url
|
24
|
-
@info ||= ( Nokogiri(open(search_url).read) / "entry" / "id" ).inner_text
|
24
|
+
@info ||= ( Nokogiri(open(search_url).read) / "entry:first" / "id" ).first.inner_text
|
25
|
+
rescue => e
|
26
|
+
raise RuntimeError, "coult not open search url: #{search_url} : \n#{e}"
|
25
27
|
end
|
26
28
|
|
27
29
|
# returns the original book xml from google.
|
28
30
|
def xml
|
29
31
|
@entry ||= open(entry_url).read
|
30
32
|
rescue => e
|
31
|
-
raise RuntimeError, "coult not open url: #{entry_url} : \n#{e}"
|
33
|
+
raise RuntimeError, "coult not open entry url: #{entry_url} : \n#{e}"
|
32
34
|
end
|
33
35
|
|
34
36
|
# nokogiri nodes from the xml
|
@@ -44,28 +46,32 @@ class RISBN
|
|
44
46
|
# returns an openstruct with a massaged version of the original xml data.
|
45
47
|
def data
|
46
48
|
return @data if @data
|
47
|
-
|
48
|
-
|
49
|
-
data.creator =
|
50
|
-
data.date =
|
51
|
-
data.description =
|
52
|
-
data.format =
|
53
|
-
data.id =
|
54
|
-
data.identifier =
|
55
|
-
data.language =
|
56
|
-
data.publisher =
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
data.
|
65
|
-
data.
|
66
|
-
data.
|
67
|
-
|
68
|
-
|
49
|
+
google_hash, data = to_hash, BookData.new
|
50
|
+
|
51
|
+
data.creator = google_hash[:creator]
|
52
|
+
data.date = google_hash[:date]
|
53
|
+
data.description = google_hash[:description]
|
54
|
+
data.format = google_hash[:format]
|
55
|
+
data.id = google_hash[:id]
|
56
|
+
data.identifier = google_hash[:identifier]
|
57
|
+
data.language = google_hash[:language]
|
58
|
+
data.publisher = google_hash[:publisher]
|
59
|
+
|
60
|
+
if google_hash[:rating] && google_hash[:rating][:attributes]
|
61
|
+
data.rating = google_hash[:rating][:attributes][:average].to_f
|
62
|
+
data.rating_max = google_hash[:rating][:attributes][:max].to_f
|
63
|
+
data.rating_min = google_hash[:rating][:attributes][:min].to_f
|
64
|
+
end
|
65
|
+
|
66
|
+
data.subject = google_hash[:subject].map { |s| s.split(/ [\-\/] /) }.flatten.map(&:strip).uniq.sort
|
67
|
+
data.title = google_hash[:title].uniq.join(" ")
|
68
|
+
data.updated = google_hash[:updated]
|
69
|
+
data.category = google_hash[:category]
|
70
|
+
data.embeddability = google_hash[:embeddability][:value]
|
71
|
+
data.open_access = google_hash[:openAccess][:value]
|
72
|
+
data.viewability = google_hash[:viewability][:value]
|
73
|
+
|
74
|
+
google_hash[:link].each do |link|
|
69
75
|
href = link.is_a?(Hash) ? link[:attributes][:href] : link.last[:href]
|
70
76
|
rel = link.is_a?(Hash) ? link[:attributes][:rel] : link.last[:rel]
|
71
77
|
data.send("#{rel[/thumbnail|info|annotation|alternate|self/]}_url=", href)
|
data/lib/risbn/version.rb
CHANGED
data/risbn.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{risbn}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Emmanuel Oga"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/risbn/scanner.rb",
|
30
30
|
"lib/risbn/version.rb",
|
31
31
|
"risbn.gemspec",
|
32
|
+
"spec/fixtures/0072253592.xml",
|
32
33
|
"spec/fixtures/book.xml",
|
33
34
|
"spec/gdata_spec.rb",
|
34
35
|
"spec/risbn_spec.rb",
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gbs='http://schemas.google.com/books/2008' xmlns:dc='http://purl.org/dc/terms' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'><id>http://www.google.com/books/feeds/volumes/nbioljTdxSgC</id><updated>2010-04-19T19:50:16.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/books/2008#volume'/><title type='text'>Data structures demystified</title><link rel='http://schemas.google.com/books/2008/thumbnail' type='image/x-unknown' href='http://bks0.books.google.com/books?id=nbioljTdxSgC&printsec=frontcover&img=1&zoom=5&edge=curl&sig=ACfU3U04iS8ZeFWNuSVKvnuMOC3g3dB0Kg&source=gbs_gdata'/><link rel='http://schemas.google.com/books/2008/info' type='text/html' href='http://books.google.com/books?id=nbioljTdxSgC&ie=ISO-8859-1&source=gbs_gdata'/><link rel='http://schemas.google.com/books/2008/annotation' type='application/atom+xml' href='http://www.google.com/books/feeds/users/me/volumes'/><link rel='alternate' type='text/html' href='http://books.google.com/books?id=nbioljTdxSgC&ie=ISO-8859-1'/><link rel='self' type='application/atom+xml' href='http://www.google.com/books/feeds/volumes/nbioljTdxSgC'/><gbs:embeddability value='http://schemas.google.com/books/2008#embeddable'/><gbs:openAccess value='http://schemas.google.com/books/2008#disabled'/><gbs:viewability value='http://schemas.google.com/books/2008#view_partial'/><dc:creator>James Edward Keogh</dc:creator><dc:creator>Ken Davidson</dc:creator><dc:date>2004-02-23</dc:date><dc:description>Whether you are an entry-level or seasoned designer or programmer, learn all about data structures in this easy-to-understand, self-teaching guide that can be directly applied to any programming language. From memory and addresses to hashtables, authors Keogh and Davidson, provide clear explanations that demystify this “algebra of programming.”</dc:description><dc:format>Dimensions 18.5x24.0x1.8 cm</dc:format><dc:format>291 pages</dc:format><dc:format>book</dc:format><dc:identifier>nbioljTdxSgC</dc:identifier><dc:identifier>ISBN:0072253592</dc:identifier><dc:identifier>ISBN:9780072253597</dc:identifier><dc:language>en</dc:language><dc:publisher>McGraw-Hill Professional</dc:publisher><dc:subject>Data structures (Computer science)</dc:subject><dc:subject>Computer programming</dc:subject><dc:subject>Data structures (Computer science)</dc:subject><dc:subject>File organization (Computer science)</dc:subject><dc:subject>File organization (Computer science)</dc:subject><dc:subject>Computers / Database Management / General</dc:subject><dc:subject>Computers / Programming / General</dc:subject><dc:subject>Computers / Programming / Algorithms</dc:subject><dc:title>Data structures demystified</dc:title></entry>
|
data/spec/gdata_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe RISBN::GData do
|
|
18
18
|
|
19
19
|
context "#data" do
|
20
20
|
let(:isbn) { RISBN("9780596101992") }
|
21
|
-
before { isbn.gdata.stub!(:xml).and_return(
|
21
|
+
before { isbn.gdata.stub!(:xml).and_return(FIXTURE["book.xml"]) }
|
22
22
|
|
23
23
|
let(:required_keys) do
|
24
24
|
more = [:open_access, :rating_max, :rating_min, :thumbnail_url,
|
@@ -27,7 +27,6 @@ describe RISBN::GData do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
subject { isbn.gdata.data }
|
30
|
-
|
31
30
|
it { should be_an_instance_of(RISBN::GData::BookData) }
|
32
31
|
|
33
32
|
it "maps the attributes of the hash form of the google response to an struct" do
|
@@ -40,4 +39,13 @@ describe RISBN::GData do
|
|
40
39
|
isbn.gdata.data.keys.should_not be_empty
|
41
40
|
end
|
42
41
|
end
|
42
|
+
|
43
|
+
context "specific cases" do
|
44
|
+
context "0072253592" do
|
45
|
+
let(:isbn) { RISBN("0072253592") }
|
46
|
+
before { isbn.gdata.stub!(:xml).and_return(FIXTURE["#{isbn.to_s}.xml"]) }
|
47
|
+
subject { isbn.gdata.data }
|
48
|
+
it { should be_an_instance_of(RISBN::GData::BookData) }
|
49
|
+
end
|
50
|
+
end
|
43
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,7 @@ require 'risbn/gdata'
|
|
6
6
|
require 'spec'
|
7
7
|
require 'spec/autorun'
|
8
8
|
|
9
|
-
|
9
|
+
FIXTURE = lambda { |f| File.read File.join(File.dirname(__FILE__), 'fixtures', f) }
|
10
10
|
|
11
11
|
Spec::Runner.configure do |config|
|
12
12
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 2
|
9
|
+
version: 0.4.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Emmanuel Oga
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/risbn/scanner.rb
|
66
66
|
- lib/risbn/version.rb
|
67
67
|
- risbn.gemspec
|
68
|
+
- spec/fixtures/0072253592.xml
|
68
69
|
- spec/fixtures/book.xml
|
69
70
|
- spec/gdata_spec.rb
|
70
71
|
- spec/risbn_spec.rb
|