productwars-api 0.1.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.
Files changed (32) hide show
  1. data/.document +5 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +40 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/productwars/client.rb +120 -0
  9. data/lib/productwars/errors.rb +6 -0
  10. data/lib/productwars/product.rb +4 -0
  11. data/lib/productwars/response.rb +4 -0
  12. data/lib/productwars/stats.rb +4 -0
  13. data/lib/productwars/war.rb +4 -0
  14. data/lib/productwars.rb +12 -0
  15. data/productwars-api.gemspec +98 -0
  16. data/spec/cassettes/ProductWars/_all_wars/successful_wars_index_request.yml +28 -0
  17. data/spec/cassettes/ProductWars/_global_leaders/successful_products_index_request.yml +29 -0
  18. data/spec/cassettes/ProductWars/_leaders_in_war/successful_request.yml +28 -0
  19. data/spec/cassettes/ProductWars/_leaders_in_war/unsuccessful_request.yml +26 -0
  20. data/spec/cassettes/ProductWars/_product/successful_request.yml +28 -0
  21. data/spec/cassettes/ProductWars/_product/unsuccessful_request.yml +26 -0
  22. data/spec/cassettes/ProductWars/_product_stats/successful_request.yml +28 -0
  23. data/spec/cassettes/ProductWars/_product_stats/unsuccessful_request.yml +26 -0
  24. data/spec/cassettes/ProductWars/_products_in_war/successful_products_index_request.yml +28 -0
  25. data/spec/cassettes/ProductWars/_products_in_war/unsuccessful_request.yml +26 -0
  26. data/spec/cassettes/ProductWars/_war/successful_request.yml +28 -0
  27. data/spec/cassettes/ProductWars/_war/unsuccessful_request.yml +26 -0
  28. data/spec/cassettes/ProductWars/_wars_containing_product/successful_request.yml +28 -0
  29. data/spec/cassettes/ProductWars/_wars_containing_product/unsuccessful_request.yml +26 -0
  30. data/spec/product_wars_spec.rb +337 -0
  31. data/spec/spec_helper.rb +12 -0
  32. metadata +236 -0
@@ -0,0 +1,337 @@
1
+ require 'spec_helper'
2
+ require 'product_wars'
3
+ require 'errors'
4
+
5
+ PRODUCT_KEYS = [
6
+ "active",
7
+ "asset_url",
8
+ "created_at",
9
+ "description",
10
+ "dp_id",
11
+ "fights",
12
+ "global_rank",
13
+ "image_url",
14
+ "manufacturer",
15
+ "name",
16
+ "permalink",
17
+ "updated_at",
18
+ "wins"
19
+ ]
20
+
21
+ WAR_KEYS = [
22
+ 'name',
23
+ 'created_at',
24
+ 'updated_at',
25
+ 'id',
26
+ 'fights',
27
+ 'description',
28
+ 'active'
29
+ ]
30
+
31
+ STATS_KEYS = [
32
+ 'dp_id',
33
+ 'fights',
34
+ 'global_rank',
35
+ 'name',
36
+ 'manufacturer',
37
+ 'wins',
38
+ 'win_rate'
39
+ ]
40
+
41
+ describe 'ProductWars' do
42
+ describe "::product" do
43
+
44
+ context "successful request" do
45
+ use_vcr_cassette
46
+
47
+ it "should retrieve a ProductWars::Product" do
48
+ response = ProductWars.product(42067)
49
+ response.class.should == ProductWars::Product
50
+ end
51
+
52
+ it "the reponse should contain the keys specified in the API docs" do
53
+ product = ProductWars.product(42067)
54
+
55
+ for key in PRODUCT_KEYS do
56
+ product.has_key?(key).should == true
57
+ #TODO This fails because the "id" attribute isn't accounted for.
58
+ # This is because the dp_id takes the place of the product id in
59
+ # all circumstances. In other words, the Product Wars app has a bug.
60
+ product.keys.count.should == PRODUCT_KEYS.count
61
+ end
62
+ end
63
+ end
64
+
65
+ context "unsuccessful request" do
66
+ use_vcr_cassette
67
+
68
+ it "should raise a NotFound error if the specified resource doesn't exist" do
69
+ lambda{
70
+ ProductWars.product('bad_id')
71
+ }.should raise_error(ProductWars::Errors::NotFound)
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "::wars_containing_product" do
77
+ context "successful request" do
78
+ use_vcr_cassette
79
+
80
+ it "should retrieve an Array" do
81
+ wars_array = ProductWars.wars_containing_product(42067)
82
+ wars_array.class.should == Array
83
+ end
84
+
85
+ it "should retrieve an Array containing ProductWars::War objects" do
86
+ wars_array = ProductWars.wars_containing_product(42067)
87
+
88
+ for h in wars_array do
89
+ h.class.should == ProductWars::War
90
+ end
91
+ end
92
+
93
+ it "should contain properly formatted war hashes" do
94
+ wars_array = ProductWars.wars_containing_product(42067)
95
+
96
+ for w in wars_array
97
+ for key in WAR_KEYS do
98
+ w.has_key?(key).should == true
99
+ w.keys.count.should == WAR_KEYS.count
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ context "unsuccessful request" do
106
+ use_vcr_cassette
107
+
108
+ it "should raise a NotFound error if the specified resource doesn't exist" do
109
+ lambda{
110
+ ProductWars.wars_containing_product('bad_id')
111
+ }.should raise_error(ProductWars::Errors::NotFound)
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "::all_wars" do
117
+ context "successful wars index request" do
118
+ use_vcr_cassette
119
+
120
+ it "should retrieve an Array" do
121
+ wars_array = ProductWars.all_wars
122
+ wars_array.class.should == Array
123
+ end
124
+
125
+ it "should retrieve an Array containing ProductWars::War objects" do
126
+ wars_array = ProductWars.all_wars
127
+
128
+ for h in wars_array do
129
+ h.class.should == ProductWars::War
130
+ end
131
+ end
132
+
133
+ it "should contain properly formatted war hashes" do
134
+ wars_array = ProductWars.all_wars
135
+
136
+ for w in wars_array
137
+ for key in WAR_KEYS do
138
+ w.has_key?(key).should == true
139
+ w.keys.count.should == WAR_KEYS.count
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ # There are currently no exceptions this can raise
146
+ #context "unsuccessful request" do
147
+ # use_vcr_cassette
148
+
149
+ # it "should raise a NotFound error if the specified resource doesn't exist" do
150
+ # lambda{
151
+ # ProductWars.all_wars
152
+ # }.should raise_error(ProductWars::Errors::NotFound)
153
+ # end
154
+ #end
155
+ end
156
+
157
+ describe "::product_stats" do
158
+ context "successful request" do
159
+ use_vcr_cassette
160
+
161
+ it "should retrieve a ProductWars::Stats" do
162
+ response = ProductWars.product_stats(42067)
163
+ response.class.should == ProductWars::Stats
164
+ end
165
+
166
+ it "the reponse should contain the keys specified in the API docs" do
167
+ stats = ProductWars.product_stats(42067)
168
+
169
+ for key in STATS_KEYS do
170
+ stats.has_key?(key).should == true
171
+ stats.keys.count.should == STATS_KEYS.count
172
+ end
173
+ end
174
+ end
175
+
176
+ context "unsuccessful request" do
177
+ use_vcr_cassette
178
+
179
+ it "should raise a NotFound error if the specified resource doesn't exist" do
180
+ lambda{
181
+ ProductWars.product_stats('bad_id')
182
+ }.should raise_error(ProductWars::Errors::NotFound)
183
+ end
184
+ end
185
+ end
186
+
187
+ describe "::war" do
188
+ context "successful request" do
189
+ use_vcr_cassette
190
+
191
+ it "should retrieve a ProductWars::War" do
192
+ response = ProductWars.war(1)
193
+ response.class.should == ProductWars::War
194
+ end
195
+
196
+ it "the reponse should contain the keys specified in the API docs" do
197
+ war = ProductWars.war(1)
198
+
199
+ for key in WAR_KEYS do
200
+ war.has_key?(key).should == true
201
+ war.keys.count.should == WAR_KEYS.count
202
+ end
203
+ end
204
+ end
205
+
206
+ context "unsuccessful request" do
207
+ use_vcr_cassette
208
+
209
+ it "should raise a NotFound error if the specified resource doesn't exist" do
210
+ lambda{
211
+ ProductWars.war('bad_id')
212
+ }.should raise_error(ProductWars::Errors::NotFound)
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "::products_in_war" do
218
+ context "successful products index request" do
219
+ use_vcr_cassette
220
+
221
+ it "should retrieve an Array" do
222
+ products_array = ProductWars.products_in_war(1)
223
+ products_array.class.should == Array
224
+ end
225
+
226
+ it "should retrieve an Array containing ProductWars::Product objects" do
227
+ products_array = ProductWars.products_in_war(1)
228
+
229
+ for h in products_array do
230
+ h.class.should == ProductWars::Product
231
+ end
232
+ end
233
+
234
+ it "should contain properly formatted product hashes" do
235
+ products_array = ProductWars.products_in_war(1)
236
+
237
+ for p in products_array
238
+ for key in PRODUCT_KEYS do
239
+ p.has_key?(key).should == true
240
+ p.keys.count.should == PRODUCT_KEYS.count
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ context "unsuccessful request" do
247
+ use_vcr_cassette
248
+
249
+ it "should raise a NotFound error if the specified resource doesn't exist" do
250
+ lambda{
251
+ ProductWars.products_in_war('bad_id')
252
+ }.should raise_error(ProductWars::Errors::NotFound)
253
+ end
254
+ end
255
+ end
256
+
257
+ describe "::global_leaders" do
258
+ context "successful products index request" do
259
+ use_vcr_cassette
260
+
261
+ it "should retrieve an Array" do
262
+ products_array = ProductWars.global_leaders
263
+ products_array.class.should == Array
264
+ end
265
+
266
+ it "should retrieve an Array containing ProductWars::Product objects" do
267
+ products_array = ProductWars.global_leaders
268
+
269
+ for h in products_array do
270
+ h.class.should == ProductWars::Product
271
+ end
272
+ end
273
+
274
+ it "should contain properly formatted product hashes" do
275
+ products_array = ProductWars.global_leaders
276
+
277
+ for p in products_array
278
+ for key in PRODUCT_KEYS do
279
+ p.has_key?(key).should == true
280
+ p.keys.count.should == PRODUCT_KEYS.count
281
+ end
282
+ end
283
+ end
284
+ end
285
+
286
+ #There are currently no exceptions this will raise directly
287
+ #context "unsuccessful request" do
288
+ # use_vcr_cassette
289
+
290
+ # it "should raise a NotFound error if the specified resource doesn't exist" do
291
+ # lambda{
292
+ # ProductWars.global_leaders
293
+ # }.should raise_error(ProductWars::Errors::NotFound)
294
+ # end
295
+ #end
296
+ end
297
+
298
+ describe "::leaders_in_war" do
299
+ context "successful request" do
300
+ use_vcr_cassette
301
+
302
+ it "should retrieve an Array" do
303
+ products_array = ProductWars.leaders_in_war(1)
304
+ products_array.class.should == Array
305
+ end
306
+
307
+ it "should retrieve an Array containing ProductWars::Product objects" do
308
+ products_array = ProductWars.leaders_in_war(1)
309
+
310
+ for h in products_array do
311
+ h.class.should == ProductWars::Product
312
+ end
313
+ end
314
+
315
+ it "should contain properly formatted product hashes" do
316
+ products_array = ProductWars.leaders_in_war(1)
317
+
318
+ for p in products_array
319
+ for key in PRODUCT_KEYS do
320
+ p.has_key?(key).should == true
321
+ p.keys.count.should == PRODUCT_KEYS.count
322
+ end
323
+ end
324
+ end
325
+ end
326
+
327
+ context "unsuccessful request" do
328
+ use_vcr_cassette
329
+
330
+ it "should raise a NotFound error if the specified resource doesn't exist" do
331
+ lambda{
332
+ ProductWars.leaders_in_war('bad_id')
333
+ }.should raise_error(ProductWars::Errors::NotFound)
334
+ end
335
+ end
336
+ end
337
+ end
@@ -0,0 +1,12 @@
1
+ require 'vcr'
2
+ require 'ruby-debug'
3
+
4
+ VCR.config do |c|
5
+ c.cassette_library_dir = 'spec/cassettes'
6
+ c.stub_with :fakeweb
7
+ c.default_cassette_options = { :record => :once }
8
+ end
9
+
10
+ RSpec.configure do |c|
11
+ c.extend VCR::RSpec::Macros
12
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: productwars-api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Spencer Rogers
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-16 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 0
31
+ - 7
32
+ - 4
33
+ version: 0.7.4
34
+ name: httparty
35
+ version_requirements: *id001
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ name: hashie
51
+ version_requirements: *id002
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ name: shoulda
65
+ version_requirements: *id003
66
+ prerelease: false
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 1
77
+ - 0
78
+ - 0
79
+ version: 1.0.0
80
+ name: bundler
81
+ version_requirements: *id004
82
+ prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 7
91
+ segments:
92
+ - 1
93
+ - 5
94
+ - 2
95
+ version: 1.5.2
96
+ name: jeweler
97
+ version_requirements: *id005
98
+ prerelease: false
99
+ - !ruby/object:Gem::Dependency
100
+ type: :development
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ name: rcov
111
+ version_requirements: *id006
112
+ prerelease: false
113
+ - !ruby/object:Gem::Dependency
114
+ type: :development
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - "="
119
+ - !ruby/object:Gem::Version
120
+ hash: 11
121
+ segments:
122
+ - 1
123
+ - 7
124
+ - 0
125
+ version: 1.7.0
126
+ name: vcr
127
+ version_requirements: *id007
128
+ prerelease: false
129
+ - !ruby/object:Gem::Dependency
130
+ type: :development
131
+ requirement: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ name: fakeweb
141
+ version_requirements: *id008
142
+ prerelease: false
143
+ - !ruby/object:Gem::Dependency
144
+ type: :development
145
+ requirement: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - "="
149
+ - !ruby/object:Gem::Version
150
+ hash: 27
151
+ segments:
152
+ - 2
153
+ - 5
154
+ - 0
155
+ version: 2.5.0
156
+ name: rspec
157
+ version_requirements: *id009
158
+ prerelease: false
159
+ description: This gem provides object-like functionality for retrieving and manipulating data from the Product Wars API
160
+ email: spencer@designerpages.com
161
+ executables: []
162
+
163
+ extensions: []
164
+
165
+ extra_rdoc_files:
166
+ - LICENSE.txt
167
+ - README.rdoc
168
+ files:
169
+ - .document
170
+ - Gemfile
171
+ - Gemfile.lock
172
+ - LICENSE.txt
173
+ - README.rdoc
174
+ - Rakefile
175
+ - VERSION
176
+ - lib/productwars.rb
177
+ - lib/productwars/client.rb
178
+ - lib/productwars/errors.rb
179
+ - lib/productwars/product.rb
180
+ - lib/productwars/response.rb
181
+ - lib/productwars/stats.rb
182
+ - lib/productwars/war.rb
183
+ - productwars-api.gemspec
184
+ - spec/cassettes/ProductWars/_all_wars/successful_wars_index_request.yml
185
+ - spec/cassettes/ProductWars/_global_leaders/successful_products_index_request.yml
186
+ - spec/cassettes/ProductWars/_leaders_in_war/successful_request.yml
187
+ - spec/cassettes/ProductWars/_leaders_in_war/unsuccessful_request.yml
188
+ - spec/cassettes/ProductWars/_product/successful_request.yml
189
+ - spec/cassettes/ProductWars/_product/unsuccessful_request.yml
190
+ - spec/cassettes/ProductWars/_product_stats/successful_request.yml
191
+ - spec/cassettes/ProductWars/_product_stats/unsuccessful_request.yml
192
+ - spec/cassettes/ProductWars/_products_in_war/successful_products_index_request.yml
193
+ - spec/cassettes/ProductWars/_products_in_war/unsuccessful_request.yml
194
+ - spec/cassettes/ProductWars/_war/successful_request.yml
195
+ - spec/cassettes/ProductWars/_war/unsuccessful_request.yml
196
+ - spec/cassettes/ProductWars/_wars_containing_product/successful_request.yml
197
+ - spec/cassettes/ProductWars/_wars_containing_product/unsuccessful_request.yml
198
+ - spec/product_wars_spec.rb
199
+ - spec/spec_helper.rb
200
+ has_rdoc: true
201
+ homepage: http://github.com/spencer1248/product-wars-ruby-api-wrapper
202
+ licenses:
203
+ - MIT
204
+ post_install_message:
205
+ rdoc_options: []
206
+
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ none: false
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ hash: 3
215
+ segments:
216
+ - 0
217
+ version: "0"
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ hash: 3
224
+ segments:
225
+ - 0
226
+ version: "0"
227
+ requirements: []
228
+
229
+ rubyforge_project:
230
+ rubygems_version: 1.5.2
231
+ signing_key:
232
+ specification_version: 3
233
+ summary: API wrapper for productwars.com
234
+ test_files:
235
+ - spec/product_wars_spec.rb
236
+ - spec/spec_helper.rb