marketplace_web_service 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mws.rb +3 -1
- data/lib/mws/api.rb +18 -0
- data/lib/mws/feed.rb +13 -0
- data/lib/mws/query_string.rb +2 -3
- data/lib/mws/query_string/percent_encoded_string.rb +12 -0
- data/lib/mws/query_string/request_string.rb +2 -3
- data/lib/mws/report.rb +5 -9
- data/lib/mws/version.rb +1 -1
- data/marketplace_web_service.gemspec +2 -0
- data/spec/mws/feed_spec.rb +32 -0
- data/spec/mws/query_string/{uri_encoder_spec.rb → percent_encoded_string_spec.rb} +8 -6
- metadata +23 -5
- data/lib/mws/query_string/uri_encoder.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b050d9e13f090866dccb8998f44218a5a8b26b6a
|
4
|
+
data.tar.gz: ffba83a4ef0b45e4b2cd6d3d2bb1f89df27fd545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b7861be76f73e0ba9e7da7b58033671387676492fbf422fa545ec452a37807ec0d1c4ee4b04a60c58f4f04e49ce08925ca4f1734f83108bc6bfe97289f78b3
|
7
|
+
data.tar.gz: 73963d4de204c40b57e1a3362a74efacfba120d448014e3e36c237b861d4204fc6dbd8a1526a1356a4ebebc1caba804c1c2c23e9a2d218a5197688027c5e34d4
|
data/lib/mws.rb
CHANGED
data/lib/mws/api.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "mws/query_string"
|
2
|
+
require "mws/request"
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module API
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def request(method, args, default_version)
|
9
|
+
action = method.to_s.split("_").map(&:capitalize).join
|
10
|
+
args[:params] = {"Action" => action, "Version" => default_version}.merge(args[:params])
|
11
|
+
args = args.merge({path: "/?#{MWS::QueryString.new(args)}"})
|
12
|
+
|
13
|
+
req = MWS::Request.new(args)
|
14
|
+
res = req.execute
|
15
|
+
res.body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/mws/feed.rb
ADDED
data/lib/mws/query_string.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "time"
|
2
|
+
require "mws/query_string/percent_encoded_string"
|
2
3
|
require "mws/query_string/request_string"
|
3
4
|
require "mws/query_string/signature"
|
4
|
-
require "mws/query_string/uri_encoder"
|
5
5
|
|
6
6
|
module MWS
|
7
7
|
class QueryString < ::String
|
@@ -28,8 +28,7 @@ module MWS
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def query_string
|
31
|
-
|
32
|
-
sorted_params.each.map{|k, v| [k, encoder.encode(v)].join("=") }.join("&")
|
31
|
+
sorted_params.each.map{|k, v| [k, PercentEncodedString.new(v)].join("=") }.join("&")
|
33
32
|
end
|
34
33
|
|
35
34
|
def sorted_params
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "uri_encoding"
|
2
|
+
|
3
|
+
module MWS
|
4
|
+
class QueryString < ::String
|
5
|
+
class PercentEncodedString < ::String
|
6
|
+
def initialize(string)
|
7
|
+
encoded_string = UriEncoding.encode(string, UriEncoding::UnreservedCharacters)
|
8
|
+
super(encoded_string)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "mws/query_string/
|
1
|
+
require "mws/query_string/percent_encoded_string"
|
2
2
|
|
3
3
|
module MWS
|
4
4
|
class QueryString < ::String
|
@@ -19,8 +19,7 @@ module MWS
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def encoded_params
|
22
|
-
|
23
|
-
Hash[sorted_params.map{|pair| pair.map{|elm| encoder.encode(elm.to_s) } } ]
|
22
|
+
Hash[sorted_params.map{|pair| pair.map{|elm| PercentEncodedString.new(elm.to_s) } } ]
|
24
23
|
end
|
25
24
|
|
26
25
|
def request_string
|
data/lib/mws/report.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
+
require "mws/api"
|
2
|
+
|
1
3
|
module MWS
|
2
4
|
module Report
|
3
5
|
DEFAULT_VERSION = "2009-01-01"
|
4
6
|
|
5
|
-
|
6
|
-
action = method.to_s.split("_").map(&:capitalize).join
|
7
|
-
args[:params] = {"Action" => action, "Version" => DEFAULT_VERSION}.merge(args[:params])
|
8
|
-
args = args.merge({path: "/?#{MWS::QueryString.new(args)}"})
|
7
|
+
module_function
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
res.body
|
9
|
+
def method_missing(method, args={})
|
10
|
+
MWS::API.request(method, args, DEFAULT_VERSION)
|
13
11
|
end
|
14
|
-
|
15
|
-
module_function :method_missing
|
16
12
|
end
|
17
13
|
end
|
data/lib/mws/version.rb
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "uri_encoding", ">= 0.0.2"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
spec.add_development_dependency "rspec"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MWS::Feed do
|
4
|
+
describe ".method_missing" do
|
5
|
+
describe ".submit_feed" do
|
6
|
+
let(:valid_args){
|
7
|
+
{
|
8
|
+
key: "ThisIsSigningKey",
|
9
|
+
endpoint: "mws.amazonservices.com",
|
10
|
+
params: {
|
11
|
+
"AWSAccessKeyId" => "AccessKeyIdString",
|
12
|
+
"SellerId" => "SellerIdString",
|
13
|
+
"FeedType" => "_POST_PRODUCT_PRICING_DATA_"
|
14
|
+
},
|
15
|
+
body: request_body
|
16
|
+
}
|
17
|
+
}
|
18
|
+
let(:request_body){ "" }
|
19
|
+
|
20
|
+
before do
|
21
|
+
response = double("request")
|
22
|
+
expect(response).to receive(:body).and_return("BodyString")
|
23
|
+
request = double("request")
|
24
|
+
expect(request).to receive(:execute).and_return(response)
|
25
|
+
expect(MWS::Request).to receive(:new).and_return(request)
|
26
|
+
end
|
27
|
+
|
28
|
+
subject { described_class.submit_feed(valid_args) }
|
29
|
+
it { is_expected.to be_a String }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe MWS::QueryString::UriEncoder do
|
4
|
-
describe "#encode" do
|
5
|
-
let(:encoder){ MWS::QueryString::UriEncoder.new }
|
1
|
+
require "spec_helper"
|
6
2
|
|
3
|
+
describe MWS::QueryString::PercentEncodedString do
|
4
|
+
describe "initialize" do
|
7
5
|
mappings = {
|
8
6
|
"abcdefghijklmnopqrstuvwxyz" => "abcdefghijklmnopqrstuvwxyz",
|
9
7
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
@@ -18,9 +16,13 @@ describe MWS::QueryString::UriEncoder do
|
|
18
16
|
"2009-08-20T01:10:27.607Z" => "2009-08-20T01%3A10%3A27.607Z"
|
19
17
|
}
|
20
18
|
|
19
|
+
subject{ described_class.new("") }
|
20
|
+
it{ is_expected.to be_an_instance_of(described_class) }
|
21
|
+
it{ is_expected.to be_a(String) }
|
22
|
+
|
21
23
|
mappings.each do |before, after|
|
22
24
|
describe "\"#{before}\"" do
|
23
|
-
subject{
|
25
|
+
subject{ described_class.new(before) }
|
24
26
|
it{ is_expected.to eq(after) }
|
25
27
|
end
|
26
28
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marketplace_web_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OSA Shunsuke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: uri_encoding
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,17 +96,20 @@ files:
|
|
82
96
|
- Rakefile
|
83
97
|
- lib/marketplace_web_service.rb
|
84
98
|
- lib/mws.rb
|
99
|
+
- lib/mws/api.rb
|
100
|
+
- lib/mws/feed.rb
|
85
101
|
- lib/mws/query_string.rb
|
102
|
+
- lib/mws/query_string/percent_encoded_string.rb
|
86
103
|
- lib/mws/query_string/request_string.rb
|
87
104
|
- lib/mws/query_string/signature.rb
|
88
|
-
- lib/mws/query_string/uri_encoder.rb
|
89
105
|
- lib/mws/report.rb
|
90
106
|
- lib/mws/request.rb
|
91
107
|
- lib/mws/version.rb
|
92
108
|
- marketplace_web_service.gemspec
|
109
|
+
- spec/mws/feed_spec.rb
|
110
|
+
- spec/mws/query_string/percent_encoded_string_spec.rb
|
93
111
|
- spec/mws/query_string/request_string_spec.rb
|
94
112
|
- spec/mws/query_string/signature_spec.rb
|
95
|
-
- spec/mws/query_string/uri_encoder_spec.rb
|
96
113
|
- spec/mws/query_string_spec.rb
|
97
114
|
- spec/mws/report_spec.rb
|
98
115
|
- spec/mws/request_spec.rb
|
@@ -123,9 +140,10 @@ signing_key:
|
|
123
140
|
specification_version: 4
|
124
141
|
summary: Simple wrapper gem for Amazon MWS(Marketplace Web Service) API.
|
125
142
|
test_files:
|
143
|
+
- spec/mws/feed_spec.rb
|
144
|
+
- spec/mws/query_string/percent_encoded_string_spec.rb
|
126
145
|
- spec/mws/query_string/request_string_spec.rb
|
127
146
|
- spec/mws/query_string/signature_spec.rb
|
128
|
-
- spec/mws/query_string/uri_encoder_spec.rb
|
129
147
|
- spec/mws/query_string_spec.rb
|
130
148
|
- spec/mws/report_spec.rb
|
131
149
|
- spec/mws/request_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module MWS
|
2
|
-
class QueryString < ::String
|
3
|
-
class UriEncoder
|
4
|
-
NO_ENCODE_CHARACTERS = /[A-Za-z0-9\-\_\.\~]/
|
5
|
-
|
6
|
-
def encode(string)
|
7
|
-
string.to_s.each_char.map{|char| char.match(NO_ENCODE_CHARACTERS) ? char : escape_char(char) }.join("")
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def escape_char(char)
|
13
|
-
char.each_byte.map{|byte| "%#{byte.to_s(16).upcase}" }.join("")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|