isbndb 1.5.5 → 2.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.
@@ -0,0 +1,76 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <ISBNdb server_time="2012-06-16T19:10:15Z">
4
+ <BookList total_results="5811" page_size="10" page_number="1" shown_results="10">
5
+ <BookData book_id="1000s_of_amazing_uses_for_everyday_products" isbn="1605533408" isbn13="9781605533407">
6
+ <Title>1000s of Amazing Uses for Everyday Products</Title>
7
+ <TitleLong></TitleLong>
8
+ <AuthorsText>Betsy Rossen Elliot, </AuthorsText>
9
+ <PublisherText publisher_id="publications_international_ltd">Publications International, Ltd.</PublisherText>
10
+ <Details change_time="2011-02-15T19:26:11Z" price_time="2011-12-03T20:38:20Z" edition_info="Hardcover; 2010-01-15" language="" physical_description_text="6.9&quot;x9.1&quot;x1.5&quot;; 2.8 lb; 448 pages" lcc_number="" dewey_decimal_normalized="" dewey_decimal="" />
11
+ </BookData>
12
+ <BookData book_id="1000_more_amazing_facts_for_kids" isbn="0706364333" isbn13="9780706364330">
13
+ <Title>1000 more amazing facts for kids</Title>
14
+ <TitleLong></TitleLong>
15
+ <AuthorsText>Keith Smithcartoons by David Mostyn</AuthorsText>
16
+ <PublisherText publisher_id="ward_lock">London Ward Lock c1986</PublisherText>
17
+ <Details change_time="2006-05-11T22:47:47Z" price_time="2012-06-16T10:52:07Z" edition_info="" language="eng" physical_description_text="112p ill 32x13cm pbk" lcc_number="AG243" dewey_decimal_normalized="32.02" dewey_decimal="032/.02" />
18
+ </BookData>
19
+ <BookData book_id="1001_amazing_animal_facts" isbn="1848372299" isbn13="9781848372290">
20
+ <Title>1001 Amazing Animal Facts</Title>
21
+ <TitleLong></TitleLong>
22
+ <AuthorsText>Marc Powell, </AuthorsText>
23
+ <PublisherText publisher_id="arcturus_publishing_ltd">Arcturus Publishing Ltd</PublisherText>
24
+ <Details change_time="2009-11-13T06:24:54Z" price_time="2011-06-09T06:39:01Z" edition_info="Paperback; 2009-06-01" language="" physical_description_text="8.2&quot;x9.9&quot;x0.6&quot;; 1.2 lb; 208 pages" lcc_number="" dewey_decimal_normalized="" dewey_decimal="" />
25
+ </BookData>
26
+ <BookData book_id="1001_amazing_facts" isbn="0603552714" isbn13="9780603552717">
27
+ <Title>1001 Amazing Facts</Title>
28
+ <TitleLong></TitleLong>
29
+ <AuthorsText></AuthorsText>
30
+ <PublisherText publisher_id="egmont_childrens_books">Egmont Childrens Books</PublisherText>
31
+ <Details change_time="2006-03-08T07:05:13Z" price_time="2011-04-02T10:36:53Z" edition_info="Paperback; 1994-07-14" language="" physical_description_text="" lcc_number="" dewey_decimal_normalized="" dewey_decimal="" />
32
+ </BookData>
33
+ <BookData book_id="1001_stupid_sports_quotes" isbn="1599210126" isbn13="9781599210124">
34
+ <Title>1001 Stupid Sports Quotes</Title>
35
+ <TitleLong>1001 Stupid Sports Quotes: Jaw-Dropping, Stupefying, and Amazing Expressions from the World's Best Athletes</TitleLong>
36
+ <AuthorsText>Randy Howe (Editor)</AuthorsText>
37
+ <PublisherText publisher_id="the_lyons_press">The Lyons Press</PublisherText>
38
+ <Details change_time="2010-04-06T17:19:18Z" price_time="2012-05-26T18:31:10Z" edition_info="Hardcover; 2007-06-01" language="" physical_description_text="5.7&quot;x7.0&quot;x1.3&quot;; 1.1 lb; 352 pages" lcc_number="" dewey_decimal_normalized="818.602080357" dewey_decimal="818.602080357" />
39
+ </BookData>
40
+ <BookData book_id="100_amazing_americans" isbn="0440842638" isbn13="9780440842637">
41
+ <Title>100 Amazing Americans</Title>
42
+ <TitleLong></TitleLong>
43
+ <AuthorsText></AuthorsText>
44
+ <PublisherText publisher_id="the_trumpet_club">The Trumpet Club</PublisherText>
45
+ <Details change_time="2007-10-09T14:45:31Z" price_time="2011-06-26T13:55:19Z" edition_info="Paperback; 1990" language="" physical_description_text="" lcc_number="" dewey_decimal_normalized="" dewey_decimal="" />
46
+ </BookData>
47
+ <BookData book_id="100_amazing_answers_to_prayer" isbn="0800758315" isbn13="9780800758318">
48
+ <Title>100 amazing answers to prayer</Title>
49
+ <TitleLong></TitleLong>
50
+ <AuthorsText>William J. Petersen and Randy Petersen</AuthorsText>
51
+ <PublisherText publisher_id="f_h_revell">Grand Rapids, MI : F.H. Revell, c2003.</PublisherText>
52
+ <Details change_time="2009-06-02T07:33:42Z" price_time="2012-05-03T17:23:32Z" edition_info="" language="eng" physical_description_text="224 p. ; 23 cm." lcc_number="BV220" dewey_decimal_normalized="248.32" dewey_decimal="248.3/2" />
53
+ </BookData>
54
+ <BookData book_id="100_amazing_answers_to_prayer_a01" isbn="0800787684" isbn13="9780800787684">
55
+ <Title>100 Amazing Answers to Prayer</Title>
56
+ <TitleLong></TitleLong>
57
+ <AuthorsText>William J. Petersen, Randy Petersen, </AuthorsText>
58
+ <PublisherText publisher_id="revell">Revell</PublisherText>
59
+ <Details change_time="2009-07-29T13:09:42Z" price_time="2011-03-06T01:11:29Z" edition_info="Mass Market Paperback; 2009-02-01" language="" physical_description_text="4.2&quot;x6.8&quot;x0.9&quot;; 0.5 lb; 256 pages" lcc_number="" dewey_decimal_normalized="248" dewey_decimal="248" />
60
+ </BookData>
61
+ <BookData book_id="100_amazing_award_winning_science_fair_projects" isbn="1402719108" isbn13="9781402719103">
62
+ <Title>100 Amazing Award-Winning Science Fair Projects</Title>
63
+ <TitleLong></TitleLong>
64
+ <AuthorsText>Glen Vecchione, </AuthorsText>
65
+ <PublisherText publisher_id="sterling">Sterling</PublisherText>
66
+ <Details change_time="2007-01-10T02:57:39Z" price_time="2012-05-31T20:22:37Z" edition_info="Paperback; 2005-02-01" language="" physical_description_text="208 pages" lcc_number="" dewey_decimal_normalized="507.8" dewey_decimal="507.8" />
67
+ </BookData>
68
+ <BookData book_id="100_amazing_crosswords" isbn="1402712391" isbn13="9781402712395">
69
+ <Title>100 Amazing Crosswords</Title>
70
+ <TitleLong></TitleLong>
71
+ <AuthorsText>Thomas Joseph, </AuthorsText>
72
+ <PublisherText publisher_id="puzzlewright">Puzzlewright</PublisherText>
73
+ <Details change_time="2009-12-22T22:37:49Z" price_time="2012-05-03T19:37:58Z" edition_info="Paperback; 2004-03-28" language="" physical_description_text="6.2&quot;x9.4&quot;x0.4&quot;; 0.3 lb; 128 pages" lcc_number="" dewey_decimal_normalized="793" dewey_decimal="793" />
74
+ </BookData>
75
+ </BookList>
76
+ </ISBNdb>
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <ISBNdb server_time="2012-06-16T20:30:57Z">
4
+ <SubjectList total_results="58" page_size="10" page_number="1" shown_results="10">
5
+ <SubjectData subject_id="ruby_napdowe_eksploatacja_podrcznik_akademicki" book_count="1" marc_field="650" marc_indicator_1=" " marc_indicator_2="9">
6
+ <Name>ruby akademicki</Name>
7
+ </SubjectData>
8
+ <SubjectData subject_id="bell_ruby" book_count="2" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
9
+ <Name>Bell, Ruby</Name>
10
+ </SubjectData>
11
+ <SubjectData subject_id="bell_ruby_1942" book_count="2" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
12
+ <Name>Bell, Ruby,1942</Name>
13
+ </SubjectData>
14
+ <SubjectData subject_id="braff_ruby_1927_2003" book_count="1" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
15
+ <Name>Braff, Ruby,1927-2003</Name>
16
+ </SubjectData>
17
+ <SubjectData subject_id="bridges_ruby" book_count="4" marc_field="600" marc_indicator_1="1" marc_indicator_2="1">
18
+ <Name>Bridges, Ruby</Name>
19
+ </SubjectData>
20
+ <SubjectData subject_id="bridges_ruby_comic_books_strips_etc" book_count="2" marc_field="600" marc_indicator_1="0" marc_indicator_2="0">
21
+ <Name>Bridges, Ruby -- Comic books, strips, etc</Name>
22
+ </SubjectData>
23
+ <SubjectData subject_id="crane_ruby_fictitious_character_fiction" book_count="1" marc_field="650" marc_indicator_1=" " marc_indicator_2="0">
24
+ <Name>Crane, Ruby (Fictitious character) -- Fiction</Name>
25
+ </SubjectData>
26
+ <SubjectData subject_id="cress_ruby_1911_correspondence" book_count="2" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
27
+ <Name>Cress, Ruby,1911-Correspondence</Name>
28
+ </SubjectData>
29
+ <SubjectData subject_id="dee_ruby" book_count="7" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
30
+ <Name>Dee, Ruby</Name>
31
+ </SubjectData>
32
+ <SubjectData subject_id="duncan_ruby" book_count="2" marc_field="600" marc_indicator_1="1" marc_indicator_2="0">
33
+ <Name>Duncan, Ruby</Name>
34
+ </SubjectData>
35
+ </SubjectList>
36
+ </ISBNdb>
@@ -0,0 +1,14 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+ require 'shoulda'
6
+ require 'webmock/rspec'
7
+
8
+ Dir[File.expand_path('spec/support/**/*.rb')].each { |f| require f }
9
+
10
+ require 'isbndb'
11
+
12
+ RSpec.configure do |config|
13
+ config.include Helpers
14
+ end
@@ -0,0 +1,8 @@
1
+ module Helpers
2
+ # Stub YAML::load to return the hash of keys that we specify
3
+ def stub_access_keys(*keys)
4
+ YAML.stub(:load) do
5
+ { 'access_keys' => keys }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe ISBNdb::AccessKeySet do
4
+ before do
5
+ stub_access_keys('ABC123', 'DEF456', 'GHI789')
6
+ @access_key_set = ISBNdb::AccessKeySet.new
7
+ end
8
+
9
+ context 'size' do
10
+ it 'should return 0 if there are no keys' do
11
+ stub_access_keys
12
+ ISBNdb::AccessKeySet.new.size.should == 0
13
+ end
14
+
15
+ it 'should return the number of access keys' do
16
+ @access_key_set.size.should == 3
17
+ end
18
+ end
19
+
20
+ context 'current_index' do
21
+ it 'should return the current index' do
22
+ @access_key_set.current_index.should == 0
23
+ end
24
+ end
25
+
26
+ context 'current_key' do
27
+ it 'should return the current key' do
28
+ @access_key_set.current_key.should == 'ABC123'
29
+ end
30
+ end
31
+
32
+ context 'next_key!' do
33
+ it 'should advance to the next key' do
34
+ expect{ @access_key_set.next_key! }.to change{ @access_key_set.current_key }.from('ABC123').to('DEF456')
35
+ end
36
+
37
+ it 'should return the new key' do
38
+ @access_key_set.next_key!.should == 'DEF456'
39
+ end
40
+ end
41
+
42
+ context 'next_key' do
43
+ it 'should return the next key' do
44
+ @access_key_set.next_key.should == 'DEF456'
45
+ end
46
+ end
47
+
48
+ context 'prev_key!' do
49
+ before do
50
+ @access_key_set.instance_variable_set('@current_index', 1)
51
+ end
52
+
53
+ it 'should de-advance to the prev key' do
54
+ expect{ @access_key_set.prev_key! }.to change{ @access_key_set.current_key }.from('DEF456').to('ABC123')
55
+ end
56
+
57
+ it 'should return the new key' do
58
+ @access_key_set.prev_key!.should == 'ABC123'
59
+ end
60
+ end
61
+
62
+ context 'prev_key' do
63
+ before do
64
+ @access_key_set.instance_variable_set('@current_index', 1)
65
+ end
66
+
67
+ it 'should return the prev key' do
68
+ @access_key_set.prev_key.should == 'ABC123'
69
+ end
70
+ end
71
+
72
+ context 'use_key' do
73
+ it 'should use an existing key' do
74
+ @access_key_set.use_key('GHI789').should == 'GHI789'
75
+ end
76
+
77
+ it 'should create a new key if it does not already exist' do
78
+ @access_key_set.use_key('NEW_KEY').should == 'NEW_KEY'
79
+ @access_key_set.instance_variable_get('@access_keys').should include('NEW_KEY')
80
+ end
81
+ end
82
+
83
+ context 'remove_key' do
84
+ it 'should do nothing if the key does not exist' do
85
+ expect{ @access_key_set.remove_key('NOPE') }.not_to change{ @access_key_set.instance_variable_get('@access_keys') }
86
+ end
87
+
88
+ it 'should remove the key if it exists' do
89
+ expect{ @access_key_set.remove_key('ABC123') }.to change{ @access_key_set.instance_variable_get('@access_keys') }.from(['ABC123', 'DEF456', 'GHI789']).to(['DEF456', 'GHI789'])
90
+ end
91
+ end
92
+
93
+ context 'to_s' do
94
+ it 'should return the correct string' do
95
+ @access_key_set.to_s.should == '#<AccessKeySet @keys=["ABC123", "DEF456", "GHI789"]>'
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe NilClass do
4
+ context 'blank?' do
5
+ it 'should return true' do
6
+ nil.blank?.should be_true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe ISBNdb::Query do
4
+ before do
5
+ stub_access_keys('ABC123')
6
+ end
7
+
8
+ context 'find' do
9
+ context 'without params[:where]' do
10
+ it 'should throw an exception' do
11
+ lambda{ ISBNdb::Query.find }.should raise_error, 'No parameters specified! You must specify at least one parameter!'
12
+ end
13
+ end
14
+
15
+ context 'with params[:where]' do
16
+ context 'as a string' do
17
+ it 'should throw an exception' do
18
+ lambda{ ISBNdb::Query.find(:where => 'anything') }.should raise_error, 'params[:where] cannot be a String! It must be a Hash!'
19
+ end
20
+ end
21
+
22
+ context 'as an array' do
23
+ it 'should throw an exception' do
24
+ lambda{ ISBNdb::Query.find(:where => ['anything', 'else']) }.should raise_error, 'params[:where] cannot be an Array! It must be a Hash!'
25
+ end
26
+ end
27
+
28
+ context 'as a hash' do
29
+ before do
30
+ stub_request(:get, "http://isbndb.com/api/books.xml?access_key=ABC123&index1=title&results=details&value1=amazing").
31
+ to_return(:body => File.new('spec/responses/search.xml'), :headers => {'Content-Type'=>'text/xml'})
32
+ end
33
+
34
+ it 'should not throw an exception' do
35
+ lambda{ ISBNdb::Query.find(:where => {:title => 'amazing'} ) }.should_not raise_error
36
+ end
37
+
38
+ it 'should return an ISBNdb::ResultSet' do
39
+ ISBNdb::Query.find(:where => {:title => 'amazing'}).should be_a(ISBNdb::ResultSet)
40
+ end
41
+ end
42
+
43
+ context 'with an access key error' do
44
+ before do
45
+ stub_request(:get, "http://isbndb.com/api/books.xml?access_key=ABC123&index1=title&results=details&value1=amazing").to_return(:body => File.new('spec/responses/access_key_error.xml'), :headers => {'Content-Type'=>'text/xml'})
46
+ end
47
+
48
+ it 'should raise an exception' do
49
+ lambda{ ISBNdb::Query.find(:where => {:title => 'amazing'}) }.should raise_error ISBNdb::AccessKeyError
50
+ end
51
+
52
+ after do
53
+ ISBNdb::Query.access_key_set.prev_key!
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'keystats' do
60
+ before do
61
+ stub_request(:get, 'http://isbndb.com/api/books.xml?access_key=ABC123&results=keystats').to_return(:body => File.new('spec/responses/keystats.xml'), :headers => { 'Content-Type' => 'text/xml' })
62
+ end
63
+
64
+ it 'should return an Hash' do
65
+ ISBNdb::Query.keystats.should be_a(Hash)
66
+ end
67
+
68
+ it('should return the number of granted requests'){ ISBNdb::Query.keystats['granted'].should == '2' }
69
+ it('should return the access key'){ ISBNdb::Query.keystats['access_key'].should == 'ABC123' }
70
+ it('should return the number of requests made'){ ISBNdb::Query.keystats['requests'].should == '5' }
71
+ it('should return the account limit'){ ISBNdb::Query.keystats['limit'].should == '0' }
72
+ end
73
+
74
+ context 'to_s' do
75
+ it 'the properly formatted string' do
76
+ ISBNdb::Query.to_s.should =='#<ISBNdb::Query, @access_key=ABC123>'
77
+ end
78
+ end
79
+
80
+ context 'method_missing' do
81
+ context 'for a valid method it can handle' do
82
+ it 'should work for books' do
83
+ stub_request(:get, "http://isbndb.com/api/books.xml?access_key=ABC123&index1=title&results=details&value1=hello").to_return(:body => File.new('spec/responses/books_hello.xml'), :headers => {'Content-Type'=>'text/xml'})
84
+
85
+ lambda{ ISBNdb::Query.find_book_by_title('hello') }.should_not raise_error
86
+ lambda{ ISBNdb::Query.find_books_by_title('hello') }.should_not raise_error
87
+
88
+ @books = ISBNdb::Query.find_books_by_title('hello')
89
+ @books.size.should == 10
90
+
91
+ @book = @books.first
92
+ @book.book_id.should == '100th_day_of_school_a04'
93
+ @book.isbn.should == '1590543947'
94
+ @book.isbn13.should == '9781590543948'
95
+ @book.title.should == '100th Day of School'
96
+ @book.title_long.should == '100th Day of School (Hello Reader Level 2)'
97
+ @book.authors_text.should == 'Angela Shelf Medearis, '
98
+ @book.publisher_text.should be_a(Hash)
99
+ @book.details.should be_a(Hash)
100
+ end
101
+
102
+ it 'should work for subjects' do
103
+ stub_request(:get, "http://isbndb.com/api/subjects.xml?access_key=ABC123&index1=name&results=details&value1=Ruby").to_return(:body => File.new('spec/responses/subjects_ruby.xml'), :headers => {'Content-Type'=>'text/xml'})
104
+
105
+ lambda{ ISBNdb::Query.find_subject_by_name('Ruby') }.should_not raise_error
106
+ lambda{ ISBNdb::Query.find_subjects_by_name('Ruby') }.should_not raise_error
107
+
108
+ @subjects = ISBNdb::Query.find_subjects_by_name('Ruby')
109
+ @subjects.size.should == 10
110
+
111
+ @subject = @subjects.first
112
+ @subject.subject_id.should == 'ruby_napdowe_eksploatacja_podrcznik_akademicki'
113
+ @subject.book_count.should == '1'
114
+ @subject.marc_field.should == '650'
115
+ @subject.marc_indicator_1.should be_nil
116
+ @subject.marc_indicator_2.should == '9'
117
+ @subject.name.should == 'ruby akademicki'
118
+ end
119
+
120
+ it 'should work for categories' do
121
+ stub_request(:get, "http://isbndb.com/api/categories.xml?access_key=ABC123&index1=name&results=details&value1=fiction").to_return(:body => File.new('spec/responses/categories_fiction.xml'), :headers => {'Content-Type'=>'text/xml'})
122
+
123
+ lambda{ ISBNdb::Query.find_category_by_name('fiction') }.should_not raise_error
124
+ lambda{ ISBNdb::Query.find_categories_by_name('fiction') }.should_not raise_error
125
+
126
+ @categories = ISBNdb::Query.find_categories_by_name('fiction')
127
+ @categories.size.should == 10
128
+
129
+ @category = @categories.first
130
+ @category.category_id.should == 'society.religion.christianity.denominations.catholicism.literature.fiction'
131
+ @category.parent_id.should == 'society.religion.christianity.denominations.catholicism.literature'
132
+ @category.name.should == 'Fiction'
133
+ @category.details.should be_a(Hash)
134
+ end
135
+
136
+ it 'should work for authors' do
137
+ stub_request(:get, "http://isbndb.com/api/authors.xml?access_key=ABC123&index1=name&results=details&value1=Seth").to_return(:body => File.new('spec/responses/authors_seth.xml'), :headers => {'Content-Type'=>'text/xml'})
138
+
139
+ lambda{ ISBNdb::Query.find_author_by_name('Seth') }.should_not raise_error
140
+ lambda{ ISBNdb::Query.find_authors_by_name('Seth') }.should_not raise_error
141
+
142
+ @authors = ISBNdb::Query.find_authors_by_name('Seth')
143
+ @authors.size.should == 10
144
+
145
+ @author = @authors.first
146
+ @author.person_id.should == 'abraham_seth'
147
+ @author.name.should == 'Abraham, Seth'
148
+ @author.details.should be_a(Hash)
149
+ end
150
+
151
+ it 'should work for publishers' do
152
+ stub_request(:get, "http://isbndb.com/api/publishers.xml?access_key=ABC123&index1=name&results=details&value1=Francis").to_return(:body => File.new('spec/responses/publishers_francis.xml'), :headers => {'Content-Type'=>'text/xml'})
153
+
154
+ lambda{ ISBNdb::Query.find_publisher_by_name('Francis') }.should_not raise_error
155
+ lambda{ ISBNdb::Query.find_publishers_by_name('Francis') }.should_not raise_error
156
+
157
+ @publishers = ISBNdb::Query.find_publishers_by_name('Francis')
158
+ @publishers.size.should == 10
159
+
160
+ @publisher = @publishers.first
161
+ @publisher.publisher_id.should == 'taylor_francis_a01'
162
+ @publisher.name.should == ': Taylor & Francis'
163
+ @publisher.details.should be_a(Hash)
164
+ end
165
+ end
166
+
167
+ context 'for an invalid method it can handle' do
168
+ it 'should throw an exception' do
169
+ lambda{ ISBNdb::Query.find_foo_by_bar('totes') }.should raise_error
170
+ end
171
+ end
172
+
173
+ context 'for a method is can\'t handle' do
174
+ it 'should throw an exception' do
175
+ lambda{ ISBNdb::Query.foo_bar }.should raise_error
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe ISBNdb::ResultSet do
4
+ before do
5
+ stub_request(:get, /http:\/\/isbndb\.com\/api\/books\.xml\?access_key=ABC123&index1=title(&page_number=(.+))?&results=details&value1=hello/).to_return(:body => File.new('spec/responses/books_hello.xml'), :headers => {'Content-Type'=>'text/xml'})
6
+ @result_set = ISBNdb::ResultSet.new('/books.xml?access_key=ABC123&index1=title&results=details&value1=hello', :books)
7
+ end
8
+
9
+ context 'initialize' do
10
+ it 'should set all the instance variables' do
11
+ @result_set.instance_variable_get('@uri').should == '/books.xml?access_key=ABC123&index1=title&results=details&value1=hello'
12
+ @result_set.instance_variable_get('@collection').should == 'Book'
13
+ @result_set.instance_variable_get('@current_page').should == 1
14
+ @result_set.instance_variable_get('@parsed_response').should == {"server_time"=>"2012-06-16T20:10:13Z", "BookList"=>{"total_results"=>"1664", "page_size"=>"10", "page_number"=>"1", "shown_results"=>"10", "BookData"=>[{"book_id"=>"100th_day_of_school_a04", "isbn"=>"1590543947", "isbn13"=>"9781590543948", "Title"=>"100th Day of School", "TitleLong"=>"100th Day of School (Hello Reader Level 2)", "AuthorsText"=>"Angela Shelf Medearis, ", "PublisherText"=>{"publisher_id"=>"fitzgerald_books", "__content__"=>"Fitzgerald Books"}, "Details"=>{"change_time"=>"2011-03-08T18:28:45Z", "price_time"=>"2012-05-29T16:45:46Z", "edition_info"=>"Unknown Binding; 2007-01", "language"=>"", "physical_description_text"=>"6.0\"x9.0\"x0.5\"; 0.4 lb; 32 pages", "lcc_number"=>"", "dewey_decimal_normalized"=>"", "dewey_decimal"=>""}}, {"book_id"=>"100th_day_the", "isbn"=>"0439330173", "isbn13"=>"9780439330176", "Title"=>"100th Day, The", "TitleLong"=>"100th Day, The (level 1) (Hello Reader Level 1)", "AuthorsText"=>"Alayne Pick, Grace Maccarone, Laura Freeman (Illustrator)", "PublisherText"=>{"publisher_id"=>"cartwheel", "__content__"=>"Cartwheel"}, "Details"=>{"change_time"=>"2006-02-27T21:34:15Z", "price_time"=>"2012-05-29T16:46:08Z", "edition_info"=>"Paperback; 2002-12-01", "language"=>"", "physical_description_text"=>"32 pages", "lcc_number"=>"", "dewey_decimal_normalized"=>"", "dewey_decimal"=>""}}, {"book_id"=>"2011_hello_kitty_engagement_calendar", "isbn"=>"1423803558", "isbn13"=>"9781423803553", "Title"=>"2011 Hello Kitty Engagement Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream (Contributor)", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2010-09-21T21:20:39Z", "price_time"=>"2012-03-24T04:44:44Z", "edition_info"=>"Calendar; 2010-08-01", "language"=>"", "physical_description_text"=>"7.0\"x8.5\"x0.9\"; 1.1 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"741", "dewey_decimal"=>"741"}}, {"book_id"=>"2011_hello_kitty_wall_calendar", "isbn"=>"1423803981", "isbn13"=>"9781423803980", "Title"=>"2011 Hello Kitty Wall Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream (Contributor)", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2010-09-21T18:46:02Z", "price_time"=>"2012-04-25T20:26:40Z", "edition_info"=>"Calendar; 2010-08-01", "language"=>"", "physical_description_text"=>"10.8\"x11.8\"x0.2\"; 0.3 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"", "dewey_decimal"=>""}}, {"book_id"=>"2012_hello_kitty_2_year_pocket_planner_calendar", "isbn"=>"1423809424", "isbn13"=>"9781423809425", "Title"=>"2012 Hello Kitty 2 Year Pocket Planner Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream, ", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2012-01-17T22:23:43Z", "price_time"=>"2012-03-04T05:32:03Z", "edition_info"=>"Calendar; 2011-07-01", "language"=>"", "physical_description_text"=>"3.5\"x6.2\"x0.0\"; 0.1 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"636", "dewey_decimal"=>"636"}}, {"book_id"=>"2012_hello_kitty_juvenile_activity_calendar", "isbn"=>"1423811194", "isbn13"=>"9781423811190", "Title"=>"2012 Hello Kitty Juvenile Activity Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream, ", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2012-05-15T00:52:54Z", "price_time"=>"2012-06-16T20:10:13Z", "edition_info"=>"Calendar; 2011-07-01", "language"=>"", "physical_description_text"=>"11.0\"x12.0\"x0.3\"; 0.8 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"741", "dewey_decimal"=>"741"}}, {"book_id"=>"2012_hello_kitty_mini_calendar", "isbn"=>"1423809165", "isbn13"=>"9781423809166", "Title"=>"2012 Hello Kitty Mini Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream, ", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2012-01-17T22:24:12Z", "price_time"=>"2012-02-09T06:11:01Z", "edition_info"=>"Calendar; 2011-07-01", "language"=>"", "physical_description_text"=>"6.2\"x6.9\"x0.2\"; 0.1 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"741", "dewey_decimal"=>"741"}}, {"book_id"=>"2012_hello_kitty_wall_calendar", "isbn"=>"1423809696", "isbn13"=>"9781423809692", "Title"=>"2012 Hello Kitty Wall Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream, ", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2012-01-17T22:14:27Z", "price_time"=>"2012-02-09T06:02:14Z", "edition_info"=>"Calendar; 2011-07-01", "language"=>"", "physical_description_text"=>"10.6\"x11.8\"x0.2\"; 0.5 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"741", "dewey_decimal"=>"741"}}, {"book_id"=>"2012_hello_kitty_weekly_engagement_calendar", "isbn"=>"1423809092", "isbn13"=>"9781423809098", "Title"=>"2012 Hello Kitty Weekly Engagement Calendar", "TitleLong"=>nil, "AuthorsText"=>"Day Dream, ", "PublisherText"=>{"publisher_id"=>"day_dream", "__content__"=>"Day Dream"}, "Details"=>{"change_time"=>"2012-01-17T22:14:34Z", "price_time"=>"2012-02-08T12:37:05Z", "edition_info"=>"Calendar; 2011-07-01", "language"=>"", "physical_description_text"=>"7.2\"x8.5\"x0.9\"; 1.0 lb", "lcc_number"=>"", "dewey_decimal_normalized"=>"741", "dewey_decimal"=>"741"}}, {"book_id"=>"2_grrrls_hello_gorgeous", "isbn"=>"0439187370", "isbn13"=>"9780439187374", "Title"=>"Hello gorgeous", "TitleLong"=>"Hello gorgeous: a guide to style", "AuthorsText"=>"by Kristen Kemp", "PublisherText"=>{"publisher_id"=>"scholastic", "__content__"=>"New York : Scholastic, c2000."}, "Details"=>{"change_time"=>"2009-09-29T18:09:13Z", "price_time"=>"2011-03-25T22:20:05Z", "edition_info"=>"(pbk.) :$3.99", "language"=>"eng", "physical_description_text"=>"64 p. : ill. (some col.) ; 20 cm.", "lcc_number"=>"", "dewey_decimal_normalized"=>"", "dewey_decimal"=>""}}]}}
15
+ end
16
+ end
17
+
18
+ context 'size' do
19
+ it 'should return the size of @results' do
20
+ @result_set.size.should == 10
21
+ end
22
+ end
23
+
24
+ context 'each' do
25
+ it 'should iterate over @results' do
26
+ @result_set.each_with_index do |result,index|
27
+ result.should == @result_set.instance_variable_get('@results')[index]
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'go_to_page' do
33
+ it 'should get the total number of pages' do
34
+ expect{ @result_set.go_to_page(1) }.to change { @result_set.instance_variable_get('@total_pages') }.to(167)
35
+ end
36
+
37
+ it 'should return if the page is invalid' do
38
+ @result_set.go_to_page('foo').should be_nil
39
+ @result_set.go_to_page(-1).should be_nil
40
+ @result_set.go_to_page(138193289).should be_nil
41
+ end
42
+
43
+ it 'should return a new result set' do
44
+ @result_set.go_to_page(2).should be_a(ISBNdb::ResultSet)
45
+ @result_set.go_to_page(2).instance_variable_get('@uri').should include('page_number=2')
46
+ end
47
+ end
48
+
49
+ context 'next_page' do
50
+ it 'should go to the next page' do
51
+ @result_set.next_page.should == @result_set.go_to_page(2)
52
+ end
53
+
54
+ it 'should return nil when there are no more pages' do
55
+ @result_set.go_to_page(167).next_page.should be_nil
56
+ end
57
+ end
58
+
59
+ context 'prev_page' do
60
+ it 'should go to the previous page' do
61
+ @result_set.go_to_page(2).prev_page.should == @result_set.go_to_page(1)
62
+ end
63
+
64
+ it 'should return nil when there is no previous page' do
65
+ @result_set.go_to_page(1).prev_page.should be_nil
66
+ end
67
+ end
68
+
69
+ context 'to_s' do
70
+ it 'should return the correct string' do
71
+ @result_set.to_s.should == '#<ResultSet::Book :total_results => 10>'
72
+ end
73
+ end
74
+
75
+ context 'check_results' do
76
+ it 'should raise an exception if there is an error message' do
77
+ stub_request(:get, /http:\/\/isbndb\.com\/api\/books\.xml\?access_key=ABC123&index1=title(&page_number=(.+))?&results=details&value1=hello/).to_return(:body => File.new('spec/responses/access_key_error.xml'), :headers => {'Content-Type'=>'text/xml'})
78
+ proc = lambda{ ISBNdb::ResultSet.new('/books.xml?access_key=ABC123&index1=title&results=details&value1=hello', :books) }
79
+
80
+ proc.should raise_error(ISBNdb::AccessKeyError)
81
+ end
82
+ end
83
+
84
+ context 'get_total_pages' do
85
+ it 'should get the total number of pages' do
86
+ @result_set.send(:get_total_pages).should == 167
87
+ end
88
+ end
89
+ end