ruby-alibris 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,445 @@
1
+ require 'helper'
2
+
3
+ class TestAlibrisSearch < Test::Unit::TestCase
4
+ context "For using the Alibris API, to search: " do
5
+ ### Default limiting parameters are: mtype=B, chunk=25, qsort=r
6
+ setup do
7
+ @default_chunk = 25
8
+ @search = Alibris::Search.new({:api_key => "#{API_KEY}", :output_type => "json"})
9
+ end
10
+ # context "needs an API key" do
11
+ # lambda {
12
+ # client = Alibris::Search.new
13
+ # client.works("kids")
14
+ # }.should raise_error(Exception)
15
+ # end
16
+
17
+ context "for all works: " do
18
+ context "by search text" do
19
+ setup do
20
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids", "search_by_wquery.json"
21
+ @wquery = "kids"
22
+ @results = @search.works(@wquery)
23
+ end
24
+ should "return success" do
25
+ @results.message.should eql("Success")
26
+ @results.status.should eql("0")
27
+ end
28
+ should "return atleast one work" do
29
+ @results.work.size.should >= 1
30
+ end
31
+ should "not return more than #{@default_chunk} works" do
32
+ @results.work.size.should_not > @default_chunk
33
+ end
34
+ should "include the parameter in the title" do
35
+ @results.work.first.title.downcase.should include(@wquery.downcase)
36
+ end
37
+ context "in work: " do
38
+ should "have a property work_id" do
39
+ @results.work.first.should respond_to(:work_id)
40
+ @results.work.first.work_id.should == "3030846"
41
+ end
42
+ should "have a property author" do
43
+ @results.work.first.should respond_to(:author)
44
+ @results.work.first.author.should == "Faber, Adele"
45
+ end
46
+ should "have a property basic" do
47
+ @results.work.first.should respond_to(:basic)
48
+ @results.work.first.basic.should == "Family & Relationships / Parenting / General # Family & Relationships / Conflict Resolution # Family & Relationships / Life Stages / Adolescence"
49
+ end
50
+ should "have a property geo_code" do
51
+ @results.work.first.should respond_to(:geo_code)
52
+ @results.work.first.geo_code.should == "United States"
53
+ end
54
+ should "have a property imageurl" do
55
+ @results.work.first.should respond_to(:imageurl)
56
+ @results.work.first.imageurl.should == "http://images.alibris.com/isbn/9780380570003.gif"
57
+ end
58
+ should "have a property lc_subject" do
59
+ @results.work.first.should respond_to(:lc_subject)
60
+ @results.work.first.lc_subject.should == "Family # Interpersonal communication # Parenting # Secular # United States"
61
+ end
62
+ should "have a property minprice" do
63
+ @results.work.first.should respond_to(:minprice)
64
+ @results.work.first.minprice.should == "0.99"
65
+ end
66
+ should "have a property qty_avail" do
67
+ @results.work.first.should respond_to(:qty_avail)
68
+ @results.work.first.qty_avail.should == "500"
69
+ end
70
+ should "have a property synopsis" do
71
+ @results.work.first.should respond_to(:synopsis)
72
+ @results.work.first.synopsis.should == "A new, updated edition of the popular how-to classic that shows parents how to communicate more effectively with their children. Faber and Mazlish share their latest insights and suggestions based on feedback they've received over the years. Illustrations."
73
+ end
74
+ should "have a property title" do
75
+ @results.work.first.should respond_to(:title)
76
+ @results.work.first.title.should == "How to Talk So Kids Will Listen and Listen So Kids Will Talk"
77
+ end
78
+ end
79
+
80
+ end
81
+ context "by author" do
82
+ setup do
83
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wauth=Dan%20Brown", "search_books_by_wauth.json"
84
+ @results = @search.works(nil, "Dan Brown")
85
+ end
86
+
87
+ should "return success" do
88
+ @results.message.should eql("Success")
89
+ @results.status.should eql("0")
90
+ end
91
+ should "return atleast one work" do
92
+ @results.work.size.should >= 1
93
+ end
94
+ should "not return more than #{@default_chunk} works" do
95
+ @results.work.size.should_not > @default_chunk
96
+ end
97
+ should "include the parameter in the author" do
98
+ @results.work.first.author.should include("Dan", "Brown")
99
+ end
100
+ end
101
+ context "by title" do
102
+ setup do
103
+ @title = "The Fountainhead"
104
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wtit=The%20Fountainhead", "search_books_by_wtit.json"
105
+ @results = @search.works(nil, nil, @title)
106
+ end
107
+
108
+ should "return success" do
109
+ @results.message.should eql("Success")
110
+ @results.status.should eql("0")
111
+ end
112
+ should "return atleast one work" do
113
+ @results.work.size.should >= 1
114
+ end
115
+ should "not return more than #{@default_chunk} works" do
116
+ @results.work.size.should_not > @default_chunk
117
+ end
118
+ should "include the parameter in the title" do
119
+ @results.work.first.title.downcase.should include(@title.downcase)
120
+ end
121
+ end
122
+ context "by topic: " do
123
+ setup do
124
+ @topic = "photography"
125
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wtopic=photography", "search_books_by_wtopic.json"
126
+ @results = @search.works(nil, nil, nil, @topic)
127
+ end
128
+
129
+ should "return success" do
130
+ @results.message.should eql("Success")
131
+ @results.status.should eql("0")
132
+ end
133
+ should "return atleast one work" do
134
+ @results.work.size.should >= 1
135
+ end
136
+ should "not return more than #{@default_chunk} works" do
137
+ @results.work.size.should_not > @default_chunk
138
+ end
139
+ should "include the parameter in the basic" do
140
+ @results.work.first.basic.downcase.should include(@topic.downcase)
141
+ end
142
+ end
143
+ end
144
+
145
+ context "for books: " do
146
+ context "by search text" do
147
+ context "sorted by rating/price (default)" do
148
+ setup do
149
+ @wquery = "kids"
150
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=B", "search_by_wquery.json"
151
+ @results = @search.books(@wquery)
152
+ end
153
+ should "return success" do
154
+ @results.message.should eql("Success")
155
+ @results.status.should eql("0")
156
+ end
157
+ should "return atleast one work" do
158
+ @results.work.size.should >= 1
159
+ end
160
+ should "not return more than #{@default_chunk} works" do
161
+ @results.work.size.should_not > @default_chunk
162
+ end
163
+ should "include the parameter in the title" do
164
+ @results.work.first.title.downcase.should include(@wquery.downcase)
165
+ end
166
+ end
167
+ context "sorted by title" do
168
+ setup do
169
+ @wquery = "kids"
170
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=B&qsort=t", "search_by_wquery_sort_by_title.json"
171
+ @results = @search.books(@wquery, nil, nil, nil, {:qsort => 't'})
172
+ end
173
+ should "return success" do
174
+ @results.message.should eql("Success")
175
+ @results.status.should eql("0")
176
+ end
177
+ should "return atleast one work" do
178
+ @results.work.size.should >= 1
179
+ end
180
+ should "not return more than #{@default_chunk} works" do
181
+ @results.work.size.should_not > @default_chunk
182
+ end
183
+ should "return first book sorted by title" do
184
+ @results.work.first.author.should eql("Tim Podell")
185
+ @results.work.first.title.should eql("\"All About the Book! \" a Kid's Video Guide to Holes (All About the Book)")
186
+ @results.work.first.work_id.should eql("-158543054")
187
+ end
188
+ should "return last book sorted by title" do
189
+ @results.work.last.author.should eql("Scholastic")
190
+ @results.work.last.title.should eql("\"Why Do Leaves Change Color? \" (Questions Kids Ask)")
191
+ @results.work.last.work_id.should eql("-43933782")
192
+ end
193
+ end
194
+ context "sorted by reverse title and limited to 10 records" do
195
+ setup do
196
+ @wquery = "kids"
197
+ @num_records = 10
198
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=B&qsort=tr&chunk=10", "search_by_wquery_sort_by_reverse_title.json"
199
+ ### Specify number of records to be returned at the query level, rather than in the constructor
200
+ @results = @search.books(@wquery, nil, nil, nil, {:qsort => 'tr', :chunk => @num_records})
201
+ end
202
+ should "return success" do
203
+ @results.message.should eql("Success")
204
+ @results.status.should eql("0")
205
+ end
206
+ should "return atleast one work" do
207
+ @results.work.size.should >= 1
208
+ end
209
+ should "not return more than #{@num_records} works" do
210
+ @results.work.size.should_not > @num_records
211
+ end
212
+ should "return first book sorted by title" do
213
+ @results.work.first.author.should eql("Scoville, Sanny {Designs By}")
214
+ @results.work.first.title.should eql("{Knitting and Crochet} Kids' Fun Vests to Knit and Crochet in Sizes 4 to 14")
215
+ @results.work.first.work_id.should eql("-88195278")
216
+ end
217
+ should "return last book sorted by title" do
218
+ @results.work.last.author.should eql("Warshaw, Hallie")
219
+ @results.work.last.title.should eql("Zany Rainy Days: Indoor Ideas for Active Kids")
220
+ @results.work.last.work_id.should eql("7377616")
221
+ end
222
+ end
223
+ context "limited to 10 records" do
224
+ setup do
225
+ @wquery = "kids"
226
+ @num_records = 10
227
+ ### Specify number of records to be returned in the constructor
228
+ @search_less = Alibris::Search.new({:api_key => "#{API_KEY}", :output_type => "json", :num_results => @num_records})
229
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=B&chunk=10", "search_by_wquery_sort_by_reverse_title.json"
230
+ @results = @search_less.books(@wquery, nil, nil, nil)
231
+ end
232
+ should "return success" do
233
+ @results.message.should eql("Success")
234
+ @results.status.should eql("0")
235
+ end
236
+ should "return atleast one work" do
237
+ @results.work.size.should >= 1
238
+ end
239
+ should "not return more than #{@num_records} works" do
240
+ @results.work.size.should_not > @num_records
241
+ end
242
+ should "return first book sorted by title" do
243
+ @results.work.first.author.should eql("Scoville, Sanny {Designs By}")
244
+ @results.work.first.title.should eql("{Knitting and Crochet} Kids' Fun Vests to Knit and Crochet in Sizes 4 to 14")
245
+ @results.work.first.work_id.should eql("-88195278")
246
+ end
247
+ end
248
+ end
249
+ context "by author" do
250
+ context "sorted by rating/price (default)" do
251
+ setup do
252
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=B&wauth=Dan%20Brown", "search_books_by_wauth.json"
253
+ @results = @search.books_by_author("Dan Brown")
254
+ end
255
+ should "return success" do
256
+ @results.message.should eql("Success")
257
+ @results.status.should eql("0")
258
+ end
259
+ should "return atleast one work" do
260
+ @results.work.size.should >= 1
261
+ end
262
+ should "not return more than #{@default_chunk} works" do
263
+ @results.work.size.should_not > @default_chunk
264
+ end
265
+ should "include the parameter in the author" do
266
+ @results.work.first.author.should include("Dan", "Brown")
267
+ end
268
+ end
269
+ context "sorted by title: " do
270
+ setup do
271
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=B&wauth=Dan%20Brown&qsort=t", "search_books_by_wauth.json"
272
+ @results = @search.books_by_author("Dan Brown", {:qsort => 't'})
273
+ end
274
+
275
+ should "return success" do
276
+ @results.message.should eql("Success")
277
+ @results.status.should eql("0")
278
+ end
279
+ should "return atleast one work" do
280
+ @results.work.size.should >= 1
281
+ end
282
+ should "not return more than #{@default_chunk} works" do
283
+ @results.work.size.should_not > @default_chunk
284
+ end
285
+ should "include the parameter in the basic" do
286
+ @results.work.first.author.should include("Dan", "Brown")
287
+ end
288
+ end
289
+ context "sorted by title in reverse: " do
290
+ setup do
291
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=B&wauth=Dan%20Brown&qsort=tr", "search_books_by_wauth.json"
292
+ @results = @search.books_by_author("Dan Brown", {:qsort => 'tr'})
293
+ end
294
+
295
+ should "return success" do
296
+ @results.message.should eql("Success")
297
+ @results.status.should eql("0")
298
+ end
299
+ should "return atleast one work" do
300
+ @results.work.size.should >= 1
301
+ end
302
+ should "not return more than #{@default_chunk} works" do
303
+ @results.work.size.should_not > @default_chunk
304
+ end
305
+ should "include the parameter in the basic" do
306
+ @results.work.first.author.should include("Dan", "Brown")
307
+ end
308
+ end
309
+ end
310
+ context "by title" do
311
+ setup do
312
+ @title = "The Fountainhead"
313
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=B&wtit=The%20Fountainhead", "search_books_by_wtit.json"
314
+ @results = @search.books_by_title(@title)
315
+ end
316
+
317
+ should "return success" do
318
+ @results.message.should eql("Success")
319
+ @results.status.should eql("0")
320
+ end
321
+ should "return atleast one work" do
322
+ @results.work.size.should >= 1
323
+ end
324
+ should "not return more than #{@default_chunk} works" do
325
+ @results.work.size.should_not > @default_chunk
326
+ end
327
+ should "include the parameter in the title" do
328
+ @results.work.first.title.downcase.should include(@title.downcase)
329
+ end
330
+ end
331
+ context "by topic: " do
332
+ context "sorted by rating/price (default)" do
333
+ setup do
334
+ @topic = "photography"
335
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=B&wtopic=photography", "search_books_by_wtopic.json"
336
+ @results = @search.books_by_topic(@topic)
337
+ end
338
+
339
+ should "return success" do
340
+ @results.message.should eql("Success")
341
+ @results.status.should eql("0")
342
+ end
343
+ should "return atleast one work" do
344
+ @results.work.size.should >= 1
345
+ end
346
+ should "not return more than #{@default_chunk} works" do
347
+ @results.work.size.should_not > @default_chunk
348
+ end
349
+ should "include the parameter in the basic" do
350
+ @results.work.first.basic.downcase.should include(@topic.downcase)
351
+ end
352
+ end
353
+ end
354
+ end
355
+
356
+ context "for music: " do
357
+ context "by search text" do
358
+ setup do
359
+ @wquery = "kids"
360
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=M", "search_by_wquery.json"
361
+ @results = @search.music(@wquery)
362
+ end
363
+ should "return success" do
364
+ @results.message.should eql("Success")
365
+ @results.status.should eql("0")
366
+ end
367
+ should "return atleast one work" do
368
+ @results.work.size.should >= 1
369
+ end
370
+ should "not return more than #{@default_chunk} works" do
371
+ @results.work.size.should_not > @default_chunk
372
+ end
373
+ should "include the parameter in the title" do
374
+ @results.work.first.title.downcase.should include(@wquery.downcase)
375
+ end
376
+ end
377
+ context "by author" do
378
+ setup do
379
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=M&wauth=Cedarmont%20Kids", "search_music_by_wauth.json"
380
+ @results = @search.music_by_author("Cedarmont Kids")
381
+ end
382
+ should "return success" do
383
+ @results.message.should eql("Success")
384
+ @results.status.should eql("0")
385
+ end
386
+ should "return atleast one work" do
387
+ @results.work.size.should >= 1
388
+ end
389
+ should "not return more than #{@default_chunk} works" do
390
+ @results.work.size.should_not > @default_chunk
391
+ end
392
+ should "include the parameter in the author" do
393
+ @results.work.first.author.should include("Cedarmont", "Kids")
394
+ end
395
+ end
396
+ end
397
+
398
+ context "for videos: " do
399
+ context "by search text" do
400
+ setup do
401
+ @wquery = "kids"
402
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&wquery=kids&mtype=V", "search_by_wquery.json"
403
+ @results = @search.videos(@wquery)
404
+ end
405
+ should "return success" do
406
+ @results.message.should eql("Success")
407
+ @results.status.should eql("0")
408
+ end
409
+ should "return atleast one work" do
410
+ @results.work.size.should >= 1
411
+ end
412
+ should "not return more than #{@default_chunk} works" do
413
+ @results.work.size.should_not > @default_chunk
414
+ end
415
+ should "include the parameter in the title" do
416
+ @results.work.first.title.downcase.should include(@wquery.downcase)
417
+ end
418
+ end
419
+ context "by title" do
420
+ setup do
421
+ @title = "kids"
422
+ stub_get "http://api.alibris.com/v1/public/search/?outputtype=json&apikey=#{API_KEY}&mtype=V&wtit=kids", "search_videos_by_wtit.json"
423
+ @results = @search.videos_by_title(@title)
424
+ end
425
+
426
+ should "return success" do
427
+ @results.message.should eql("Success")
428
+ @results.status.should eql("0")
429
+ end
430
+ should "return atleast one work" do
431
+ @results.work.size.should >= 1
432
+ end
433
+ should "not return more than #{@default_chunk} works" do
434
+ @results.work.size.should_not > @default_chunk
435
+ end
436
+ should "include the parameter in the title" do
437
+ @results.work.first.title.downcase.should include(@title.downcase)
438
+ end
439
+ end
440
+ end
441
+
442
+ end
443
+
444
+
445
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-alibris
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Rupak Ganguly
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-27 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.7.0
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.10.1
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jnunemaker-matchy
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.0
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: mocha
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.12
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: fakeweb
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.0
79
+ type: :development
80
+ version_requirements: *id006
81
+ description: Wrapper for Alibris API, the premier online marketplace for independent sellers of new and used books, music, and movies, as well as rare and collectible titles.
82
+ email:
83
+ - rupakg@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.markdown
95
+ - Rakefile
96
+ - changelog.markdown
97
+ - lib/alibris.rb
98
+ - lib/alibris/version.rb
99
+ - ruby-alibris.gemspec
100
+ - test/fixtures/search_books_by_wauth.json
101
+ - test/fixtures/search_books_by_wtit.json
102
+ - test/fixtures/search_books_by_wtopic.json
103
+ - test/fixtures/search_by_wquery.json
104
+ - test/fixtures/search_by_wquery_sort_by_reverse_title.json
105
+ - test/fixtures/search_by_wquery_sort_by_title.json
106
+ - test/fixtures/search_music_by_wauth.json
107
+ - test/fixtures/search_videos_by_wtit.json
108
+ - test/helper.rb
109
+ - test/test_alibris_search.rb
110
+ homepage: http://github.com/rupakg/ruby-alibris
111
+ licenses:
112
+ - MIT
113
+ post_install_message:
114
+ rdoc_options: []
115
+
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.7.2
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Wrapper for Alibris API
137
+ test_files: []
138
+
139
+ has_rdoc: