sucker 0.2.1 → 0.2.2
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.
- data/lib/sucker/request.rb +6 -12
- data/lib/sucker.rb +1 -2
- data/spec/integration/japan_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/sucker/request_spec.rb +9 -21
- metadata +5 -3
data/lib/sucker/request.rb
CHANGED
@@ -10,6 +10,7 @@ module Sucker
|
|
10
10
|
:ca => 'ecs.amazonaws.ca',
|
11
11
|
:fr => 'ecs.amazonaws.fr',
|
12
12
|
:jp => 'ecs.amazonaws.jp' }
|
13
|
+
PATH = "/onca/xml"
|
13
14
|
|
14
15
|
# The Amazon locale to query
|
15
16
|
attr_accessor :locale
|
@@ -69,25 +70,18 @@ module Sucker
|
|
69
70
|
join("&")
|
70
71
|
end
|
71
72
|
|
72
|
-
def digest
|
73
|
-
OpenSSL::Digest::Digest.new("sha256")
|
74
|
-
end
|
75
|
-
|
76
73
|
def host
|
77
74
|
HOSTS[locale.to_sym]
|
78
75
|
end
|
79
76
|
|
80
|
-
def path
|
81
|
-
"/onca/xml"
|
82
|
-
end
|
83
|
-
|
84
77
|
# Returns a signed and timestamped query string
|
85
|
-
def
|
78
|
+
def build_signed_query
|
86
79
|
timestamp_parameters
|
87
80
|
|
88
81
|
query = build_query
|
89
82
|
|
90
|
-
|
83
|
+
digest = OpenSSL::Digest::Digest.new("sha256")
|
84
|
+
string = ["GET", host, PATH, query].join("\n")
|
91
85
|
hmac = OpenSSL::HMAC.digest(digest, secret, string)
|
92
86
|
|
93
87
|
query + "&Signature=" + CGI.escape([hmac].pack("m").chomp)
|
@@ -96,8 +90,8 @@ module Sucker
|
|
96
90
|
def uri
|
97
91
|
URI::HTTP.build(
|
98
92
|
:host => host,
|
99
|
-
:path =>
|
100
|
-
:query =>
|
93
|
+
:path => PATH,
|
94
|
+
:query => build_signed_query)
|
101
95
|
end
|
102
96
|
|
103
97
|
def timestamp_parameters
|
data/lib/sucker.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Sucker
|
4
|
+
describe "Japan" do
|
5
|
+
before do
|
6
|
+
@worker = Sucker.new(
|
7
|
+
:locale => "jp",
|
8
|
+
:key => amazon["key"],
|
9
|
+
:secret => amazon["secret"])
|
10
|
+
|
11
|
+
@worker << {
|
12
|
+
"Operation" => "ItemLookup",
|
13
|
+
"IdType" => "ASIN" }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "single item" do
|
17
|
+
before do
|
18
|
+
@worker << { "ItemId" => "0816614024" }
|
19
|
+
@item = @worker.get["ItemLookupResponse"]["Items"]["Item"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an item" do
|
23
|
+
@item.should be_an_instance_of Hash
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -54,6 +54,13 @@ module Sucker
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
context "#key=" do
|
58
|
+
it "sets the Amazon AWS access key in the parameters" do
|
59
|
+
@worker.key = "key"
|
60
|
+
@worker.parameters["AWSAccessKeyId"].should eql "key"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
57
64
|
context "private methods" do
|
58
65
|
context "#build_query" do
|
59
66
|
it "canonicalizes parameters" do
|
@@ -74,19 +81,6 @@ module Sucker
|
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
77
|
-
context "#digest" do
|
78
|
-
it "returns a digest object" do
|
79
|
-
@worker.send(:digest).should be_an_instance_of OpenSSL::Digest::Digest
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "#key=" do
|
84
|
-
it "sets the Amazon AWS access key in the parameters" do
|
85
|
-
@worker.key = "key"
|
86
|
-
@worker.parameters["AWSAccessKeyId"].should eql "key"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
84
|
context "#host" do
|
91
85
|
it "returns a host" do
|
92
86
|
@worker.locale = "us"
|
@@ -94,17 +88,11 @@ module Sucker
|
|
94
88
|
end
|
95
89
|
end
|
96
90
|
|
97
|
-
context "#
|
98
|
-
it "returns a path" do
|
99
|
-
@worker.send(:path).should eql "/onca/xml"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "#sign_query" do
|
91
|
+
context "#build_signed_query" do
|
104
92
|
it "returns a signed query string" do
|
105
93
|
@worker.secret = "secret"
|
106
94
|
@worker.locale = "us"
|
107
|
-
query = @worker.send :
|
95
|
+
query = @worker.send :build_signed_query
|
108
96
|
query.should match /&Signature=.*/
|
109
97
|
end
|
110
98
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hakan Ensari
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/sucker/request.rb
|
68
68
|
- README.md
|
69
69
|
- spec/integration/item_lookup_spec.rb
|
70
|
+
- spec/integration/japan_spec.rb
|
70
71
|
- spec/integration/seller_listing_search_spec.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
- spec/support/amazon_credentials.rb
|
@@ -109,6 +110,7 @@ specification_version: 3
|
|
109
110
|
summary: A thin Ruby wrapper to the Amazon Product Advertising API
|
110
111
|
test_files:
|
111
112
|
- spec/integration/item_lookup_spec.rb
|
113
|
+
- spec/integration/japan_spec.rb
|
112
114
|
- spec/integration/seller_listing_search_spec.rb
|
113
115
|
- spec/spec_helper.rb
|
114
116
|
- spec/support/amazon_credentials.rb
|