sucker 0.9.2 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.markdown +4 -20
  2. data/lib/sucker/request.rb +16 -9
  3. data/lib/sucker/response.rb +5 -4
  4. data/lib/sucker/version.rb +1 -1
  5. data/lib/sucker.rb +2 -4
  6. data/spec/fixtures/cassette_library/integration/errors.yml +27 -0
  7. data/spec/fixtures/cassette_library/integration/france.yml +27 -0
  8. data/spec/fixtures/cassette_library/integration/images.yml +27 -0
  9. data/spec/fixtures/cassette_library/integration/item_lookup/multiple.yml +27 -0
  10. data/spec/fixtures/cassette_library/integration/item_lookup/single.yml +27 -0
  11. data/spec/fixtures/cassette_library/integration/item_search.yml +27 -0
  12. data/spec/fixtures/cassette_library/integration/japan.yml +27 -0
  13. data/spec/fixtures/cassette_library/integration/related_items/child.yml +27 -0
  14. data/spec/fixtures/cassette_library/integration/related_items/parent.yml +27 -0
  15. data/spec/fixtures/cassette_library/integration/seller_listings_search.yml +27 -0
  16. data/spec/fixtures/cassette_library/integration/twenty_items.yml +27 -0
  17. data/spec/fixtures/cassette_library/unit/sucker/request.yml +32 -0
  18. data/spec/fixtures/cassette_library/unit/sucker/response.yml +27 -0
  19. data/spec/integration/errors_spec.rb +7 -8
  20. data/spec/integration/france_spec.rb +15 -33
  21. data/spec/integration/images_spec.rb +12 -12
  22. data/spec/integration/item_lookup_spec.rb +25 -22
  23. data/spec/integration/item_search_spec.rb +12 -8
  24. data/spec/integration/japan_spec.rb +12 -15
  25. data/spec/integration/related_items_spec.rb +21 -16
  26. data/spec/integration/seller_listing_search_spec.rb +10 -11
  27. data/spec/integration/twenty_items_in_one_request_spec.rb +20 -19
  28. data/spec/spec_helper.rb +1 -0
  29. data/spec/support/amazon.yml +2 -0
  30. data/spec/support/amazon_credentials.rb +1 -0
  31. data/spec/support/asins.rb +1 -0
  32. data/spec/support/vcr.rb +14 -0
  33. data/spec/unit/sucker/request_spec.rb +45 -33
  34. data/spec/unit/sucker/response_spec.rb +27 -24
  35. data/spec/unit/sucker_spec.rb +1 -0
  36. metadata +114 -38
  37. data/lib/sucker/stub.rb +0 -45
  38. data/spec/support/sucker.rb +0 -3
  39. data/spec/unit/sucker/stub_spec.rb +0 -68
@@ -1,9 +1,12 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe Request do
5
- before do
6
- @worker = Sucker.new(
6
+ use_vcr_cassette "unit/sucker/request", :record => :new_episodes
7
+
8
+ let(:worker) do
9
+ Sucker.new(
7
10
  :locale => "us",
8
11
  :key => "key",
9
12
  :secret => "secret")
@@ -13,113 +16,122 @@ module Sucker
13
16
  it "sets default parameters" do
14
17
  default_parameters = {
15
18
  "Service" => "AWSECommerceService",
16
- "Version" => Sucker::AMAZON_API_VERSION }
17
- @worker.parameters.should include default_parameters
19
+ "Version" => Sucker::CURRENT_AMAZON_API_VERSION }
20
+ worker.parameters.should include default_parameters
18
21
  end
19
22
  end
20
23
 
21
24
  context "#<<" do
22
25
  it "merges a hash into the parameters" do
23
- @worker << { "foo" => "bar" }
24
- @worker.parameters["foo"].should eql "bar"
26
+ worker << { "foo" => "bar" }
27
+ worker.parameters["foo"].should eql "bar"
28
+ end
29
+ end
30
+
31
+ context "api_version" do
32
+ it "has a default value" do
33
+ worker.api_version.should_not be_nil
34
+ end
35
+ end
36
+
37
+ context "#api_version=" do
38
+ it "sets the Amazon API version" do
39
+ worker.api_version = "foo"
40
+ worker.api_version.should eql "foo"
25
41
  end
26
42
  end
27
43
 
28
44
  context "#associate_tag=" do
29
45
  it "sets the associate tag in the parameters" do
30
- @worker.associate_tag = "foo"
31
- @worker.parameters["AssociateTag"].should eql "foo"
46
+ worker.associate_tag = "foo"
47
+ worker.parameters["AssociateTag"].should eql "foo"
32
48
  end
33
49
  end
34
50
 
35
51
  context "#curl" do
36
52
  it "returns a cURL object" do
37
- @worker.curl.should be_an_instance_of Curl::Easy
53
+ worker.curl.should be_an_instance_of Curl::Easy
38
54
  end
39
55
 
40
56
  it "configures the cURL object" do
41
- @worker.curl.interface.should be_nil
57
+ worker.curl.interface.should be_nil
42
58
 
43
- @worker.curl do |curl|
59
+ worker.curl do |curl|
44
60
  curl.interface = "eth1"
45
61
  end
46
62
 
47
- @worker.curl.interface.should eql "eth1"
63
+ worker.curl.interface.should eql "eth1"
48
64
  end
49
65
  end
50
66
 
51
67
  context "#get" do
52
- before do
53
- Sucker.stub(@worker)
54
- end
55
-
56
68
  it "returns a Response object" do
57
- @worker.get.class.ancestors.should include Sucker::Response
69
+ worker.get.class.ancestors.should include Sucker::Response
58
70
  end
59
71
  end
60
72
 
61
73
  context "#key=" do
62
74
  it "sets the Amazon AWS access key in the parameters" do
63
- @worker.key = "foo"
64
- @worker.parameters["AWSAccessKeyId"].should eql "foo"
75
+ worker.key = "foo"
76
+ worker.parameters["AWSAccessKeyId"].should eql "foo"
65
77
  end
66
78
  end
67
79
 
68
80
  context "private methods" do
69
81
  context "#build_query" do
70
82
  it "canonicalizes parameters" do
71
- query = @worker.send(:build_query)
83
+ query = worker.send(:build_query)
72
84
  query.should match /Service=([^&]+)&Timestamp=([^&]+)&Version=([^&]+)/
73
85
  end
74
86
 
75
87
  it "sorts parameters" do
76
- @worker.parameters["AAA"] = "foo"
77
- query = @worker.send(:build_query)
88
+ worker.parameters["AAA"] = "foo"
89
+ query = worker.send(:build_query)
78
90
  query.should match /^AAA=foo/
79
91
  end
80
92
 
81
93
  it "converts a parameter whose value is an array to a string" do
82
- @worker.parameters["Foo"] = ["bar", "baz"]
83
- query = @worker.send(:build_query)
94
+ worker.parameters["Foo"] = ["bar", "baz"]
95
+ query = worker.send(:build_query)
84
96
  query.should match /Foo=bar%2Cbaz/
85
97
  end
86
98
 
87
99
  it "handles integer parameter values" do
88
- @worker.parameters["Foo"] = 1
89
- query = @worker.send(:build_query)
100
+ worker.parameters["Foo"] = 1
101
+ query = worker.send(:build_query)
90
102
  query.should match /Foo=1/
91
103
  end
92
104
 
93
105
  it "handles floating-point parameter values" do
94
- @worker.parameters["Foo"] = 1.0
95
- query = @worker.send(:build_query)
106
+ worker.parameters["Foo"] = 1.0
107
+ query = worker.send(:build_query)
96
108
  query.should match /Foo=1/
97
109
  end
98
110
  end
99
111
 
100
112
  context "#host" do
101
113
  it "returns a host" do
102
- @worker.locale = "fr"
103
- @worker.send(:host).should eql "ecs.amazonaws.fr"
114
+ worker.locale = "fr"
115
+ worker.send(:host).should eql "ecs.amazonaws.fr"
104
116
  end
105
117
  end
106
118
 
107
119
  context "#build_signed_query" do
108
120
  it "returns a signed query string" do
109
- query = @worker.send :build_signed_query
121
+ query = worker.send :build_signed_query
110
122
  query.should match /&Signature=.*/
111
123
  end
112
124
  end
113
125
 
114
126
  context "#timestamp" do
115
127
  it "returns a timestamp" do
116
- @worker.send(:timestamp)["Timestamp"].should match /^\d+-\d+-\d+T\d+:\d+:\d+Z$/
128
+ worker.send(:timestamp)["Timestamp"].should match /^\d+-\d+-\d+T\d+:\d+:\d+Z$/
117
129
  end
118
130
  end
119
131
 
120
132
  context "#uri" do
121
133
  it "returns the URI with which to query Amazon" do
122
- @worker.send(:uri).should be_an_instance_of URI::HTTP
134
+ worker.send(:uri).should be_an_instance_of URI::HTTP
123
135
  end
124
136
  end
125
137
  end
@@ -3,8 +3,11 @@ require "spec_helper"
3
3
 
4
4
  module Sucker
5
5
  describe Response do
6
- before do
7
- @asins = ["0816614024", "0143105825"]
6
+ use_vcr_cassette "unit/sucker/response", :record => :new_episodes
7
+
8
+ let(:asins) { ["0816614024", "0143105825"] }
9
+
10
+ let(:response) do
8
11
  worker = Sucker.new(
9
12
  :locale => "us",
10
13
  :key => amazon["key"],
@@ -13,76 +16,76 @@ module Sucker
13
16
  "Operation" => "ItemLookup",
14
17
  "IdType" => "ASIN",
15
18
  "ResponseGroup" => ["ItemAttributes", "OfferFull"],
16
- "ItemId" => @asins }
17
- @response = worker.get
19
+ "ItemId" => asins }
20
+ worker.get
18
21
  end
19
22
 
20
23
  context ".new" do
21
24
  it "sets the response body" do
22
- @response.body.should be_an_instance_of String
25
+ response.body.should be_an_instance_of String
23
26
  end
24
27
 
25
28
  it "sets the response code" do
26
- @response.code.should == 200
29
+ response.code.should == 200
27
30
  end
28
31
 
29
32
  it "sets the response time" do
30
- @response.time.should be_an_instance_of Float
33
+ response.time.should be_an_instance_of Float
31
34
  end
32
35
  end
33
36
 
34
37
  context "#xml" do
35
38
  it "returns a Nokogiri document" do
36
- @response.xml.should be_an_instance_of Nokogiri::XML::Document
39
+ response.xml.should be_an_instance_of Nokogiri::XML::Document
37
40
  end
38
41
  end
39
42
 
40
43
  context "#node" do
41
44
  it "returns a collection of hashified nodes" do
42
- response = @response.node("ItemAttributes")
43
- response.map { |book| book["ISBN"] }.should eql @asins
45
+ node = response.node("ItemAttributes")
46
+ node.map { |book| book["ISBN"] }.should eql asins
44
47
  end
45
48
 
46
49
  it "returns an empty array if there are no matches" do
47
- response = @response.node("Foo")
48
- response.should eql []
50
+ node = response.node("Foo")
51
+ node.should eql []
49
52
  end
50
53
  end
51
54
 
52
55
  context "#to_hash" do
53
56
  it "returns a hash" do
54
- @response.to_hash.should be_an_instance_of Hash
57
+ response.to_hash.should be_an_instance_of Hash
55
58
  end
56
59
 
57
60
  it "converts a content hash to string" do
58
- @response.body = "<book><title>A Thousand Plateaus</title></book>"
59
- @response.to_hash["book"]["title"].should be_an_instance_of String
61
+ response.body = "<book><title>A Thousand Plateaus</title></book>"
62
+ response.to_hash["book"]["title"].should be_an_instance_of String
60
63
  end
61
64
 
62
65
  it "renders French" do
63
- @response.body = "<Title>L'archéologie du savoir</Title>"
64
- @response.to_hash["Title"].should eql "L'archéologie du savoir"
66
+ response.body = "<Title>L'archéologie du savoir</Title>"
67
+ response.to_hash["Title"].should eql "L'archéologie du savoir"
65
68
  end
66
69
 
67
70
  it "renders German" do
68
- @response.body = "<Title>Kafka: Für eine kleine Literatur</Title>"
69
- @response.to_hash["Title"].should eql "Kafka: Für eine kleine Literatur"
71
+ response.body = "<Title>Kafka: Für eine kleine Literatur</Title>"
72
+ response.to_hash["Title"].should eql "Kafka: Für eine kleine Literatur"
70
73
  end
71
74
 
72
75
  it "renders Japanese" do
73
- @response.body = "<Title>スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則</Title>"
74
- @response.to_hash["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
76
+ response.body = "<Title>スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則</Title>"
77
+ response.to_hash["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
75
78
  end
76
79
  end
77
80
 
78
81
  context "#valid?" do
79
82
  it "returns true if the HTTP status is OK" do
80
- @response.should be_valid
83
+ response.should be_valid
81
84
  end
82
85
 
83
86
  it "returns false if the HTTP status is not OK" do
84
- @response.code = 403
85
- @response.should_not be_valid
87
+ response.code = 403
88
+ response.should_not be_valid
86
89
  end
87
90
  end
88
91
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  describe Sucker do
metadata CHANGED
@@ -1,12 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 62196353
5
+ prerelease: true
5
6
  segments:
7
+ - 1
8
+ - 0
6
9
  - 0
7
- - 9
8
- - 2
9
- version: 0.9.2
10
+ - beta
11
+ - 1
12
+ version: 1.0.0.beta.1
10
13
  platform: ruby
11
14
  authors:
12
15
  - Hakan Ensari
@@ -15,123 +18,170 @@ autorequire:
15
18
  bindir: bin
16
19
  cert_chain: []
17
20
 
18
- date: 2010-10-06 00:00:00 +01:00
21
+ date: 2010-10-14 00:00:00 +01:00
19
22
  default_executable:
20
23
  dependencies:
21
24
  - !ruby/object:Gem::Dependency
22
25
  name: activesupport
26
+ prerelease: false
23
27
  requirement: &id001 !ruby/object:Gem::Requirement
24
28
  none: false
25
29
  requirements:
26
30
  - - ">="
27
31
  - !ruby/object:Gem::Version
32
+ hash: 7
28
33
  segments:
29
34
  - 2
30
35
  - 3
31
36
  - 2
32
37
  version: 2.3.2
33
38
  type: :runtime
34
- prerelease: false
35
39
  version_requirements: *id001
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: nokogiri
42
+ prerelease: false
38
43
  requirement: &id002 !ruby/object:Gem::Requirement
39
44
  none: false
40
45
  requirements:
41
46
  - - ~>
42
47
  - !ruby/object:Gem::Version
48
+ hash: 7
43
49
  segments:
44
50
  - 1
45
51
  - 4
46
52
  - 0
47
53
  version: 1.4.0
48
54
  type: :runtime
49
- prerelease: false
50
55
  version_requirements: *id002
51
56
  - !ruby/object:Gem::Dependency
52
57
  name: curb
58
+ prerelease: false
53
59
  requirement: &id003 !ruby/object:Gem::Requirement
54
60
  none: false
55
61
  requirements:
56
62
  - - ~>
57
63
  - !ruby/object:Gem::Version
64
+ hash: 3
58
65
  segments:
59
66
  - 0
60
67
  - 7
61
68
  - 0
62
69
  version: 0.7.0
63
70
  type: :runtime
64
- prerelease: false
65
71
  version_requirements: *id003
66
72
  - !ruby/object:Gem::Dependency
67
73
  name: rake
74
+ prerelease: false
68
75
  requirement: &id004 !ruby/object:Gem::Requirement
69
76
  none: false
70
77
  requirements:
71
- - - ">="
78
+ - - ~>
72
79
  - !ruby/object:Gem::Version
80
+ hash: 49
73
81
  segments:
74
82
  - 0
75
- version: "0"
83
+ - 8
84
+ - 7
85
+ version: 0.8.7
76
86
  type: :development
77
- prerelease: false
78
87
  version_requirements: *id004
79
88
  - !ruby/object:Gem::Dependency
80
89
  name: rdiscount
90
+ prerelease: false
81
91
  requirement: &id005 !ruby/object:Gem::Requirement
82
92
  none: false
83
93
  requirements:
84
- - - ">="
94
+ - - ~>
85
95
  - !ruby/object:Gem::Version
96
+ hash: 5
86
97
  segments:
87
- - 0
88
- version: "0"
98
+ - 1
99
+ - 6
100
+ - 5
101
+ version: 1.6.5
89
102
  type: :development
90
- prerelease: false
91
103
  version_requirements: *id005
92
104
  - !ruby/object:Gem::Dependency
93
105
  name: rspec
106
+ prerelease: false
94
107
  requirement: &id006 !ruby/object:Gem::Requirement
95
108
  none: false
96
109
  requirements:
97
- - - "="
110
+ - - ~>
98
111
  - !ruby/object:Gem::Version
112
+ hash: 15
99
113
  segments:
100
114
  - 2
101
115
  - 0
102
116
  - 0
103
- - rc
104
- version: 2.0.0.rc
117
+ version: 2.0.0
105
118
  type: :development
106
- prerelease: false
107
119
  version_requirements: *id006
108
120
  - !ruby/object:Gem::Dependency
109
121
  name: throttler
122
+ prerelease: false
110
123
  requirement: &id007 !ruby/object:Gem::Requirement
111
124
  none: false
112
125
  requirements:
113
- - - ">="
126
+ - - ~>
114
127
  - !ruby/object:Gem::Version
128
+ hash: 21
115
129
  segments:
116
130
  - 0
117
- version: "0"
131
+ - 2
132
+ - 1
133
+ version: 0.2.1
118
134
  type: :development
119
- prerelease: false
120
135
  version_requirements: *id007
121
136
  - !ruby/object:Gem::Dependency
122
137
  name: sdoc-helpers
138
+ prerelease: false
123
139
  requirement: &id008 !ruby/object:Gem::Requirement
124
140
  none: false
125
141
  requirements:
126
- - - ">="
142
+ - - ~>
127
143
  - !ruby/object:Gem::Version
144
+ hash: 19
128
145
  segments:
129
146
  - 0
130
- version: "0"
147
+ - 1
148
+ - 4
149
+ version: 0.1.4
131
150
  type: :development
132
- prerelease: false
133
151
  version_requirements: *id008
134
- description: A Ruby wrapper to the Amazon Product Advertising API
152
+ - !ruby/object:Gem::Dependency
153
+ name: vcr
154
+ prerelease: false
155
+ requirement: &id009 !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ hash: 31
161
+ segments:
162
+ - 1
163
+ - 2
164
+ - 0
165
+ version: 1.2.0
166
+ type: :development
167
+ version_requirements: *id009
168
+ - !ruby/object:Gem::Dependency
169
+ name: webmock
170
+ prerelease: false
171
+ requirement: &id010 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ~>
175
+ - !ruby/object:Gem::Version
176
+ hash: 7
177
+ segments:
178
+ - 1
179
+ - 4
180
+ - 0
181
+ version: 1.4.0
182
+ type: :development
183
+ version_requirements: *id010
184
+ description: A minimal Ruby wrapper to the Amazon Product Advertising API
135
185
  email:
136
186
  - code@papercavalier.com
137
187
  executables: []
@@ -143,12 +193,24 @@ extra_rdoc_files: []
143
193
  files:
144
194
  - lib/sucker/request.rb
145
195
  - lib/sucker/response.rb
146
- - lib/sucker/stub.rb
147
196
  - lib/sucker/version.rb
148
197
  - lib/sucker.rb
149
198
  - LICENSE
150
199
  - README.markdown
151
200
  - spec/fixtures/asins.txt
201
+ - spec/fixtures/cassette_library/integration/errors.yml
202
+ - spec/fixtures/cassette_library/integration/france.yml
203
+ - spec/fixtures/cassette_library/integration/images.yml
204
+ - spec/fixtures/cassette_library/integration/item_lookup/multiple.yml
205
+ - spec/fixtures/cassette_library/integration/item_lookup/single.yml
206
+ - spec/fixtures/cassette_library/integration/item_search.yml
207
+ - spec/fixtures/cassette_library/integration/japan.yml
208
+ - spec/fixtures/cassette_library/integration/related_items/child.yml
209
+ - spec/fixtures/cassette_library/integration/related_items/parent.yml
210
+ - spec/fixtures/cassette_library/integration/seller_listings_search.yml
211
+ - spec/fixtures/cassette_library/integration/twenty_items.yml
212
+ - spec/fixtures/cassette_library/unit/sucker/request.yml
213
+ - spec/fixtures/cassette_library/unit/sucker/response.yml
152
214
  - spec/integration/errors_spec.rb
153
215
  - spec/integration/france_spec.rb
154
216
  - spec/integration/images_spec.rb
@@ -159,21 +221,21 @@ files:
159
221
  - spec/integration/seller_listing_search_spec.rb
160
222
  - spec/integration/twenty_items_in_one_request_spec.rb
161
223
  - spec/spec_helper.rb
224
+ - spec/support/amazon.yml
162
225
  - spec/support/amazon.yml.example
163
226
  - spec/support/amazon_credentials.rb
164
227
  - spec/support/asins.rb
165
- - spec/support/sucker.rb
228
+ - spec/support/vcr.rb
166
229
  - spec/unit/sucker/request_spec.rb
167
230
  - spec/unit/sucker/response_spec.rb
168
- - spec/unit/sucker/stub_spec.rb
169
231
  - spec/unit/sucker_spec.rb
170
232
  has_rdoc: true
171
233
  homepage: http://gloss.papercavalier.com/sucker
172
234
  licenses: []
173
235
 
174
236
  post_install_message:
175
- rdoc_options:
176
- - --charset=UTF-8
237
+ rdoc_options: []
238
+
177
239
  require_paths:
178
240
  - lib
179
241
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -181,29 +243,43 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
243
  requirements:
182
244
  - - ">="
183
245
  - !ruby/object:Gem::Version
184
- hash: -55576138892431507
246
+ hash: 3
185
247
  segments:
186
248
  - 0
187
249
  version: "0"
188
250
  required_rubygems_version: !ruby/object:Gem::Requirement
189
251
  none: false
190
252
  requirements:
191
- - - ">="
253
+ - - ">"
192
254
  - !ruby/object:Gem::Version
255
+ hash: 25
193
256
  segments:
194
257
  - 1
195
258
  - 3
196
- - 7
197
- version: 1.3.7
259
+ - 1
260
+ version: 1.3.1
198
261
  requirements: []
199
262
 
200
- rubyforge_project:
263
+ rubyforge_project: sucker
201
264
  rubygems_version: 1.3.7
202
265
  signing_key:
203
266
  specification_version: 3
204
267
  summary: A Ruby wrapper to the Amazon Product Advertising API
205
268
  test_files:
206
269
  - spec/fixtures/asins.txt
270
+ - spec/fixtures/cassette_library/integration/errors.yml
271
+ - spec/fixtures/cassette_library/integration/france.yml
272
+ - spec/fixtures/cassette_library/integration/images.yml
273
+ - spec/fixtures/cassette_library/integration/item_lookup/multiple.yml
274
+ - spec/fixtures/cassette_library/integration/item_lookup/single.yml
275
+ - spec/fixtures/cassette_library/integration/item_search.yml
276
+ - spec/fixtures/cassette_library/integration/japan.yml
277
+ - spec/fixtures/cassette_library/integration/related_items/child.yml
278
+ - spec/fixtures/cassette_library/integration/related_items/parent.yml
279
+ - spec/fixtures/cassette_library/integration/seller_listings_search.yml
280
+ - spec/fixtures/cassette_library/integration/twenty_items.yml
281
+ - spec/fixtures/cassette_library/unit/sucker/request.yml
282
+ - spec/fixtures/cassette_library/unit/sucker/response.yml
207
283
  - spec/integration/errors_spec.rb
208
284
  - spec/integration/france_spec.rb
209
285
  - spec/integration/images_spec.rb
@@ -214,11 +290,11 @@ test_files:
214
290
  - spec/integration/seller_listing_search_spec.rb
215
291
  - spec/integration/twenty_items_in_one_request_spec.rb
216
292
  - spec/spec_helper.rb
293
+ - spec/support/amazon.yml
217
294
  - spec/support/amazon.yml.example
218
295
  - spec/support/amazon_credentials.rb
219
296
  - spec/support/asins.rb
220
- - spec/support/sucker.rb
297
+ - spec/support/vcr.rb
221
298
  - spec/unit/sucker/request_spec.rb
222
299
  - spec/unit/sucker/response_spec.rb
223
- - spec/unit/sucker/stub_spec.rb
224
300
  - spec/unit/sucker_spec.rb
data/lib/sucker/stub.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
- module Sucker
3
-
4
- # Stubs Sucker::Response to run specs offline.
5
- class MockResponse < Response
6
- def initialize(mock_response_body)
7
- self.body = mock_response_body
8
- self.code = 200
9
- self.time = 0.1
10
- end
11
- end
12
-
13
- class << self
14
- attr_accessor :fixtures_path
15
-
16
- # Records a request on first run and fakes subsequently
17
- def stub(request)
18
- request.instance_eval do
19
- self.class.send :define_method, :fixture do
20
- values = parameters.
21
- reject { |k, v| %w{AWSAccessKeyId Service}.include? k }.
22
- values.
23
- flatten.
24
- join
25
- filename = Digest::MD5.hexdigest(host + values)
26
- "#{Sucker.fixtures_path}/#{filename}.xml"
27
- end
28
-
29
- self.class.send :define_method, :get do
30
- if File.exists?(fixture)
31
- MockResponse.new(File.new(fixture, "r").read)
32
- else
33
- curl.url = uri.to_s
34
- curl.perform
35
- response = Response.new(curl)
36
-
37
- File.open(fixture, "w") { |f| f.write response.body }
38
-
39
- response
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,3 +0,0 @@
1
- require "sucker/stub"
2
-
3
- Sucker.fixtures_path = File.dirname(__FILE__) + "/../fixtures"