sucker 1.2.0 → 1.3.0.pre

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 (41) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +45 -20
  3. data/lib/sucker/parameters.rb +11 -7
  4. data/lib/sucker/parameters.rbc +723 -0
  5. data/lib/sucker/request.rb +52 -154
  6. data/lib/sucker/request.rbc +2719 -0
  7. data/lib/sucker/response.rb +14 -36
  8. data/lib/sucker/response.rbc +1307 -0
  9. data/lib/sucker/version.rb +3 -1
  10. data/lib/sucker/version.rbc +130 -0
  11. data/lib/sucker.rb +4 -2
  12. data/lib/sucker.rbc +286 -0
  13. data/spec/fixtures/cassette_library/0394751221.yml +26 -0
  14. data/spec/fixtures/cassette_library/0415246334.yml +26 -0
  15. data/spec/fixtures/cassette_library/0679753354.yml +26 -0
  16. data/spec/fixtures/cassette_library/0816614024-0007218095.yml +26 -0
  17. data/spec/fixtures/cassette_library/0816614024-0143105825.yml +26 -0
  18. data/spec/fixtures/cassette_library/0816614024.yml +26 -0
  19. data/spec/fixtures/cassette_library/482224816x.yml +26 -0
  20. data/spec/fixtures/cassette_library/816614024.yml +151 -0
  21. data/spec/fixtures/cassette_library/a2h6nh4sqyfz4m.yml +26 -0
  22. data/spec/fixtures/cassette_library/a2jyso6w6kep83.yml +26 -0
  23. data/spec/fixtures/cassette_library/author-lacan-or-deleuze-and-not-fiction.yml +26 -0
  24. data/spec/fixtures/cassette_library/b000aspues.yml +26 -0
  25. data/spec/fixtures/cassette_library/deleuze-binding-kindle.yml +26 -0
  26. data/spec/fixtures/cassette_library/deleuze.yml +26 -0
  27. data/spec/fixtures/cassette_library/george-orwell.yml +26 -0
  28. data/spec/fixtures/cassette_library/spec/sucker/request.yml +4 -4
  29. data/spec/fixtures/cassette_library/spec/sucker/response.yml +3 -3
  30. data/spec/spec_helper.rbc +230 -0
  31. data/spec/sucker/parameters_spec.rbc +1476 -0
  32. data/spec/sucker/request_spec.rb +34 -217
  33. data/spec/sucker/request_spec.rbc +2473 -0
  34. data/spec/sucker/response_spec.rb +46 -95
  35. data/spec/sucker/response_spec.rbc +2854 -0
  36. data/spec/sucker_spec.rbc +287 -0
  37. data/spec/support/amazon_credentials.rbc +154 -0
  38. data/spec/support/asins.rbc +335 -0
  39. data/spec/support/vcr.rbc +356 -0
  40. metadata +72 -96
  41. data/CHANGELOG.md +0 -47
@@ -1,274 +1,91 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Sucker
4
4
  describe Request do
5
- use_vcr_cassette "spec/sucker/request", :record => :new_episodes
5
+ use_vcr_cassette 'spec/sucker/request', :record => :new_episodes
6
6
 
7
7
  let(:worker) do
8
8
  Sucker.new(
9
9
  :locale => :us,
10
- :key => "key",
11
- :secret => "secret")
10
+ :key => 'key',
11
+ :secret => 'secret')
12
12
  end
13
13
 
14
- describe "#<<" do
15
- it "merges a hash into the existing parameters" do
16
- worker << { "foo" => "bar" }
17
- worker.parameters["foo"].should eql "bar"
14
+ describe '#<<' do
15
+ it 'merges a hash into the existing parameters' do
16
+ worker << { 'foo' => 'bar' }
17
+ worker.parameters['foo'].should eql 'bar'
18
18
  end
19
19
  end
20
20
 
21
- describe "#version=" do
22
- it "sets the Amazon API version" do
23
- worker.version = "foo"
24
- worker.parameters["Version"].should eql "foo"
25
- end
26
- end
27
-
28
- describe "#associate_tag" do
29
- it "returns the associate tag for the current locale" do
30
- worker.instance_variable_set(:@associate_tags, { :us => 'foo-bar'})
31
-
32
- worker.associate_tag.should eql 'foo-bar'
33
- end
34
-
35
- it "returns blank if no associate tag is set for the current locale" do
36
- worker.associate_tag.should be_blank
37
- end
38
- end
39
-
40
- describe "#associate_tag=" do
41
- it "sets the associate tag for the current locale" do
42
- worker.associate_tag = "foo-bar"
43
- associate_tags = worker.instance_variable_get(:@associate_tags)
44
-
45
- associate_tags.keys.size.should eql 1
46
- associate_tags[:us].should eql 'foo-bar'
47
- worker.associate_tag.should eql 'foo-bar'
48
- end
49
- end
50
-
51
- describe "#associate_tags=" do
52
- it "sets associate tags for the locales" do
53
- tags = {
54
- :us => 'foo',
55
- :uk => 'bar',
56
- :de => 'baz',
57
- :ca => 'foo',
58
- :fr => 'bar',
59
- :jp => 'baz' }
60
- worker.associate_tags = tags
61
-
62
- worker.instance_variable_get(:@associate_tags).should eql tags
63
- end
64
- end
65
-
66
- describe "#curl_opts" do
67
- it "returns options for curl" do
68
- worker.curl_opts.should be_an_instance_of Hash
69
- end
70
-
71
- context "when given a block" do
72
-
73
- it "yields options for curl" do
74
- worker.curl_opts { |c| c.interface = "eth1" }
75
-
76
- worker.curl_opts[:interface].should eql "eth1"
77
- end
78
- end
79
- end
80
-
81
- describe "#get" do
82
- context "when no argument is passed" do
83
- it "returns a response" do
21
+ describe '#get' do
22
+ context 'when no argument is passed' do
23
+ it 'returns a response' do
84
24
  worker.get.class.ancestors.should include Response
85
25
  end
86
-
87
- it "sets options on curl" do
88
- easy = mock
89
- easy.should_receive(:interface=).once.with("eth1")
90
- Curl::Easy.stub!(:perform).and_yield(easy)
91
- Response.should_receive(:new).once
92
-
93
- worker.curl_opts { |c| c.interface = 'eth1' }
94
- worker.get
95
- end
96
- end
97
-
98
- context "when one argument is passed" do
99
- context "when the argument is is `:all`" do
100
- it "queries all locales" do
101
- locales = worker.send(:locales)
102
- worker.should_receive(:get_multi).with(locales)
103
- worker.get(:all)
104
- end
105
- end
106
-
107
- context "when the argument is not `:all`" do
108
- it "sets current locale to to the argument" do
109
- worker.should_receive(:locale=).with(:uk)
110
- worker.get(:uk)
111
- end
112
-
113
- it "calls itself with no argument" do
114
- worker.class.send :alias_method, :get_original, :get
115
- worker.should_receive(:get).with(no_args())
116
- worker.get_original(:uk)
117
- end
118
- end
119
- end
120
-
121
- context "when multiple arguments are passed" do
122
- it "queries multiple locales" do
123
- worker.should_receive(:get_multi).with([:us, :uk])
124
- worker.get(:us, :uk)
125
- end
126
26
  end
127
27
  end
128
28
 
129
- describe "#key" do
130
- it "returns the Amazon AWS access key for the current locale" do
131
- worker.instance_variable_set(:@keys, { :us => 'foo' })
132
-
133
- worker.key.should eql 'foo'
134
- end
135
-
136
- it "raises an argument error if key is missing" do
137
- worker.instance_variable_get(:@keys)[:us] = nil
138
- expect do
139
- worker.key
140
- end.to raise_error 'AWS access key missing'
29
+ describe '#version=' do
30
+ it 'sets the Amazon API version' do
31
+ worker.version = 'foo'
32
+ worker.parameters['Version'].should eql 'foo'
141
33
  end
142
34
  end
143
35
 
144
- describe "#key=" do
145
- it "sets a global Amazon AWS access key" do
146
- worker.key = "foo"
147
- keys = worker.instance_variable_get(:@keys)
148
-
149
- keys.size.should eql Request::HOSTS.size
150
- keys.values.uniq.should eql ["foo"]
151
- end
152
- end
153
-
154
- describe "#keys=" do
155
- it "sets distinct Amazon AWS access keys for the locales" do
156
- keys = {
157
- :us => 'foo',
158
- :uk => 'bar',
159
- :de => 'baz',
160
- :ca => 'foo',
161
- :fr => 'bar',
162
- :jp => 'baz' }
163
- worker.keys = keys
164
-
165
- worker.instance_variable_get(:@keys).should eql keys
166
- end
167
- end
168
-
169
- describe "#locale" do
170
- it "returns the current locale" do
171
- worker.locale.should eql :us
172
- end
173
-
174
- it "raises an argument error if locale is not set" do
175
- worker.instance_variable_set(:@locale, nil)
176
- expect do
177
- worker.locale
178
- end.to raise_error 'Locale not set'
179
- end
180
- end
181
-
182
- describe "#locale=" do
183
- it "sets the current locale" do
184
- worker.locale= :uk
185
- worker.locale.should eql :uk
186
- end
187
-
188
- it "raises an argument error if locale is invalid" do
189
- expect do
190
- worker.locale= :br
191
- end.to raise_error 'Invalid locale'
192
- end
193
- end
194
-
195
- # private
196
-
197
- describe "#build_query" do
36
+ describe '#build_query' do
198
37
  let(:query) do
199
38
  worker.send(:build_query)
200
39
  end
201
40
 
202
- it "canonicalizes query" do
203
- query.should match /Service=([^&]+)&Timestamp=([^&]+)&Version=([^&]+)/
41
+ it 'canonicalizes query' do
42
+ query.should match /AWSAccessKeyId=key&AssociateTag=&Service=([^&]+)&Timestamp=([^&]+)&Version=([^&]+)/
204
43
  end
205
44
 
206
- it "includes a timestamp" do
45
+ it 'includes a timestamp' do
207
46
  query.should include 'Timestamp'
208
47
  end
209
48
 
210
- it "sorts query" do
211
- worker.parameters["A"] = "foo"
49
+ it 'sorts query' do
50
+ worker.parameters['A'] = 'foo'
212
51
  query.should match /^A=foo/
213
52
  end
214
53
  end
215
54
 
216
- describe "#build_signed_query" do
55
+ describe '#build_signed_query' do
217
56
  let(:query) { worker.send(:build_signed_query) }
218
57
 
219
- it "includes the key for the current locale" do
58
+ it 'includes the key for the current locale' do
220
59
  worker.key = 'foo'
221
60
  query.should include 'AWSAccessKeyId=foo'
222
61
  end
223
62
 
224
- it "includes the associate tag for the current locale" do
63
+ it 'includes the associate tag for the current locale' do
225
64
  worker.associate_tag = 'foo'
226
65
  query.should include 'AssociateTag=foo'
227
66
  end
228
67
 
229
- it "returns a signed query string" do
68
+ it 'returns a signed query string' do
230
69
  query = worker.send :build_signed_query
231
70
  query.should include 'Signature='
232
71
  end
233
72
  end
234
73
 
235
- describe "#escape" do
236
- it "URL-encodes a string" do
237
- worker.send(:escape, 'foo,bar').should eql "foo%2Cbar"
238
- end
239
- end
240
-
241
- describe "#get_multi" do
242
- it "returns an array of responses" do
243
- responses = worker.send(:get_multi, [:us, :uk])
244
-
245
- responses.should be_an_instance_of Array
246
- responses.each { |resp| resp.should be_an_instance_of Response }
247
- end
248
-
249
- context "when given a block" do
250
- it "yields responses" do
251
- locales = worker.send(:locales)
252
- count = 0
253
- worker.send(:get_multi, locales) do |resp|
254
- resp.should be_an_instance_of Response
255
- count += 1
256
- end
257
-
258
- count.should eql locales.size
259
- end
74
+ describe '#escape' do
75
+ it 'URL-encodes a string' do
76
+ worker.send(:escape, 'foo,bar').should eql 'foo%2Cbar'
260
77
  end
261
78
  end
262
79
 
263
- describe "#host" do
264
- it "returns a host" do
265
- worker.locale = "fr"
266
- worker.send(:host).should eql "ecs.amazonaws.fr"
80
+ describe '#host' do
81
+ it 'returns a host' do
82
+ worker.locale = :fr
83
+ worker.send(:host).should eql 'ecs.amazonaws.fr'
267
84
  end
268
85
  end
269
86
 
270
- describe "#uri" do
271
- it "returns the URI with which to query Amazon" do
87
+ describe '#uri' do
88
+ it 'returns the URI with which to query Amazon' do
272
89
  worker.send(:uri).should be_an_instance_of URI::HTTP
273
90
  end
274
91
  end