risbn 0.3.0 → 0.4.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/VERSION +1 -1
- data/lib/risbn/gdata.rb +10 -1
- data/lib/risbn/version.rb +1 -1
- data/risbn.gemspec +1 -1
- data/spec/gdata_spec.rb +18 -13
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/risbn/gdata.rb
CHANGED
@@ -44,7 +44,7 @@ class RISBN
|
|
44
44
|
# returns an openstruct with a massaged version of the original xml data.
|
45
45
|
def data
|
46
46
|
return @data if @data
|
47
|
-
h, data = to_hash,
|
47
|
+
h, data = to_hash, BookData.new
|
48
48
|
|
49
49
|
data.creator = h[:creator]
|
50
50
|
data.date = h[:date]
|
@@ -74,6 +74,15 @@ class RISBN
|
|
74
74
|
@data = data
|
75
75
|
end
|
76
76
|
|
77
|
+
class BookData < OpenStruct
|
78
|
+
def to_hash
|
79
|
+
@table.dup
|
80
|
+
end
|
81
|
+
|
82
|
+
def keys
|
83
|
+
@table.keys
|
84
|
+
end
|
85
|
+
end
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
data/lib/risbn/version.rb
CHANGED
data/risbn.gemspec
CHANGED
data/spec/gdata_spec.rb
CHANGED
@@ -16,23 +16,28 @@ describe RISBN::GData do
|
|
16
16
|
expect { RISBN::GData(RISBN("6660596101992")) }.to raise_exception(RISBN::InvalidISBN)
|
17
17
|
end
|
18
18
|
|
19
|
-
context "
|
20
|
-
|
21
|
-
|
22
|
-
@isbn.gdata.stub!(:xml).and_return(File.read(GDATA_FIXTURE_PATH))
|
23
|
-
end
|
19
|
+
context "#data" do
|
20
|
+
let(:isbn) { RISBN("9780596101992") }
|
21
|
+
before { isbn.gdata.stub!(:xml).and_return(File.read(GDATA_FIXTURE_PATH)) }
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
let(:required_keys) do
|
24
|
+
more = [:open_access, :rating_max, :rating_min, :thumbnail_url,
|
25
|
+
:info_url, :annotation_url, :alternate_url, :self_url]
|
26
|
+
isbn.gdata.to_hash.keys.uniq - [:link, :openAccess] + more
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
subject { isbn.gdata.data }
|
30
|
+
|
31
|
+
it { should be_an_instance_of(RISBN::GData::BookData) }
|
32
|
+
|
33
|
+
it "maps the attributes of the hash form of the google response to an struct" do
|
34
|
+
required_keys.each { |key| should respond_to(key) }
|
35
|
+
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
it "is able to convert the struct to a hash and return its keys" do
|
38
|
+
isbn.gdata.data.to_hash.should be_an_instance_of(Hash)
|
39
|
+
isbn.gdata.data.keys.should be_an_instance_of(Array)
|
40
|
+
isbn.gdata.data.keys.should_not be_empty
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|