sucker 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/sucker/request.rb +0 -7
- data/spec/spec_helper.rb +4 -1
- data/spec/unit/sucker/request_spec.rb +35 -77
- metadata +3 -3
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Sucker
|
2
2
|
======
|
3
3
|
|
4
|
-
|
4
|
+
Sucker is a thin Ruby wrapper to the Amazon Product Advertising API. It runs on Curb and Crack.
|
5
5
|
|
6
|
-
Sucker
|
6
|
+
![Sucker](http://upload.wikimedia.org/wikipedia/en/7/71/Vacuum_cleaner_1910.JPG)
|
7
7
|
|
8
8
|
Examples
|
9
9
|
--------
|
data/lib/sucker/request.rb
CHANGED
@@ -46,8 +46,6 @@ module Sucker
|
|
46
46
|
# Makes a request to Amazon and returns the response as a hash
|
47
47
|
# Todo: Handle errors
|
48
48
|
def get
|
49
|
-
raise ArgumentError, 'Set key, secret, and valid locale' if !valid?
|
50
|
-
|
51
49
|
curl.url = uri.to_s
|
52
50
|
curl.perform
|
53
51
|
|
@@ -105,10 +103,5 @@ module Sucker
|
|
105
103
|
def timestamp_parameters
|
106
104
|
self.parameters["Timestamp"] = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
107
105
|
end
|
108
|
-
|
109
|
-
# Returns true if request has key, secret, and a valid locale set
|
110
|
-
def valid?
|
111
|
-
!!locale && !!HOSTS[locale.to_sym] && !!secret && !!parameters["AWSAccessKeyId"]
|
112
|
-
end
|
113
106
|
end
|
114
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,63 +6,55 @@ module Sucker
|
|
6
6
|
@worker = Sucker.new
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@worker.parameters.should eql default_parameters
|
16
|
-
end
|
9
|
+
context ".new" do
|
10
|
+
it "sets default parameters" do
|
11
|
+
default_parameters = {
|
12
|
+
"Service" => "AWSECommerceService",
|
13
|
+
"Version" => Sucker::AMAZON_API_VERSION }
|
14
|
+
@worker.parameters.should eql default_parameters
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
18
|
+
context "#<<" do
|
19
|
+
it "merges a hash into the parameters" do
|
20
|
+
@worker << { "foo" => "bar" }
|
21
|
+
@worker.parameters["foo"].should eql "bar"
|
24
22
|
end
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
it "configures the cURL object" do
|
32
|
-
@worker.curl.interface.should be_nil
|
25
|
+
context "#curl" do
|
26
|
+
it "returns a cURL object" do
|
27
|
+
@worker.curl.should be_an_instance_of Curl::Easy
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
30
|
+
it "configures the cURL object" do
|
31
|
+
@worker.curl.interface.should be_nil
|
37
32
|
|
38
|
-
|
33
|
+
@worker.curl do |curl|
|
34
|
+
curl.interface = "eth1"
|
39
35
|
end
|
40
|
-
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@worker.key = "key"
|
46
|
-
@worker.secret = "secret"
|
37
|
+
@worker.curl.interface.should eql "eth1"
|
38
|
+
end
|
39
|
+
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
41
|
+
context "#get" do
|
42
|
+
before do
|
43
|
+
@worker.locale = "us"
|
44
|
+
@worker.secret = "secret"
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
# Stub curl
|
47
|
+
curl = @worker.curl
|
48
|
+
curl.stub(:get).and_return(nil)
|
49
|
+
curl.stub!(:body_str).and_return(fixture("single_item_lookup.us"))
|
50
|
+
end
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
lambda{ @worker.get }.should raise_error ArgumentError
|
61
|
-
end
|
52
|
+
it "returns a hash" do
|
53
|
+
@worker.get.should be_an_instance_of Hash
|
62
54
|
end
|
63
55
|
end
|
64
56
|
|
65
|
-
context "private" do
|
57
|
+
context "private methods" do
|
66
58
|
context "#build_query" do
|
67
59
|
it "canonicalizes parameters" do
|
68
60
|
query = @worker.send(:build_query)
|
@@ -132,40 +124,6 @@ module Sucker
|
|
132
124
|
@worker.send(:uri).should be_an_instance_of URI::HTTP
|
133
125
|
end
|
134
126
|
end
|
135
|
-
|
136
|
-
context "valid?" do
|
137
|
-
it "returns true if key, secret, and a valid locale are set" do
|
138
|
-
@worker.key = "key"
|
139
|
-
@worker.locale = "us"
|
140
|
-
@worker.secret = "secret"
|
141
|
-
@worker.send(:valid?).should be_true
|
142
|
-
end
|
143
|
-
|
144
|
-
it "returns false if key is not set" do
|
145
|
-
@worker.locale = "us"
|
146
|
-
@worker.secret = "secret"
|
147
|
-
@worker.send(:valid?).should be_false
|
148
|
-
end
|
149
|
-
|
150
|
-
it "returns false if secret is not set" do
|
151
|
-
@worker.locale = "us"
|
152
|
-
@worker.key = "key"
|
153
|
-
@worker.send(:valid?).should be_false
|
154
|
-
end
|
155
|
-
|
156
|
-
it "returns false if locale is not set" do
|
157
|
-
@worker.key = "key"
|
158
|
-
@worker.secret = "secret"
|
159
|
-
@worker.send(:valid?).should be_false
|
160
|
-
end
|
161
|
-
|
162
|
-
it "returns false if locale is not valid" do
|
163
|
-
@worker.key = "key"
|
164
|
-
@worker.locale = "US"
|
165
|
-
@worker.secret = "secret"
|
166
|
-
@worker.send(:valid?).should be_false
|
167
|
-
end
|
168
|
-
end
|
169
127
|
end
|
170
128
|
end
|
171
129
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sucker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hakan Ensari
|