marketplace_web_service 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f28041e47bf57d747d23b02e2896c255f1c32a90
4
- data.tar.gz: a61d946c4743938358d764bc7bcd81cfcf4d62bb
3
+ metadata.gz: 2f4ff93dac20f15865f105e22202cd5b246ae0d1
4
+ data.tar.gz: af2075a5e950eed79f9c9c4ffe3d99c018e02bcb
5
5
  SHA512:
6
- metadata.gz: 946259c65ec86b8c93731b07dc261f2e3e2db8d2dd406245d096b29fa4dbd5deac1b3b3778d763b67b6cd40ad1b880375a8e4f25f4850946d02c3eb101c203bb
7
- data.tar.gz: d3012bd41edb161417b6184deef31274becab95ba577abb4c70f630559168e4eec4c606ff5e7eba9ba990b8baba9723eca0e6db0cdb1b9414dc8a3403058ff2e
6
+ metadata.gz: f80a5ae26a99bdf8edc0c852dac8628c927ada747d401f33445e86088f50e320f354e1ffb8b059306c93e3187ebf798c07447ae69a92b8d7d032a0575ab7f3d9
7
+ data.tar.gz: e4652031bf15c83e5aee67ffe3687c991dff8bc6c94d5038822cea72e9c704a21386e0c28864f32df2c6dce86e17292a057d9b2b2540bd165941c013f7e8332c
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # MarketplaceWebService
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/marketplace_web_service.svg)](http://badge.fury.io/rb/marketplace_web_service)
3
4
  [![Build Status](https://travis-ci.org/e-maido/marketplace_web_service.svg?branch=master)](https://travis-ci.org/e-maido/marketplace_web_service)
4
5
  [![Coverage Status](https://img.shields.io/coveralls/e-maido/marketplace_web_service.svg)](https://coveralls.io/r/e-maido/marketplace_web_service)
5
6
 
@@ -3,11 +3,11 @@ require "mws/query_string/uri_encoder"
3
3
  module MWS
4
4
  class QueryString < ::String
5
5
  class RequestString < ::String
6
- def initialize(method, host, path, params)
7
- @method = method
8
- @host = host
9
- @path = path
10
- @params = params
6
+ def initialize(args)
7
+ @method = args[:method]
8
+ @endpoint = args[:endpoint]
9
+ @path = args[:path]
10
+ @params = args[:params]
11
11
 
12
12
  super(request_string)
13
13
  end
@@ -26,7 +26,7 @@ module MWS
26
26
  def request_string
27
27
  [
28
28
  @method.to_s.upcase,
29
- @host,
29
+ @endpoint,
30
30
  @path,
31
31
  encoded_params.map{|pair| pair.join("=") }.join("&")
32
32
  ].join("\n")
@@ -1,3 +1,4 @@
1
+ require "time"
1
2
  require "mws/query_string/request_string"
2
3
  require "mws/query_string/signature"
3
4
  require "mws/query_string/uri_encoder"
@@ -12,11 +13,11 @@ module MWS
12
13
  }
13
14
 
14
15
  def initialize(args)
15
- @key = args[:key]
16
- @method = args[:method] || DEFAULT_METHOD
17
- @host = args[:host]
18
- @path = args[:path] || DEFAULT_PATH
19
- @params = DEFAULT_PARAMS.merge(args[:params])
16
+ @key = args[:key]
17
+ @method = args[:method] || DEFAULT_METHOD
18
+ @endpoint = args[:endpoint]
19
+ @path = args[:path] || DEFAULT_PATH
20
+ @params = DEFAULT_PARAMS.merge(args[:params])
20
21
 
21
22
  @params["Timestamp"] = timestamp_string
22
23
  @params["Signature"] = signature_string # This substitution must be final substitution
@@ -31,8 +32,28 @@ module MWS
31
32
  sorted_params.each.map{|k, v| [k, encoder.encode(v)].join("=") }.join("&")
32
33
  end
33
34
 
35
+ def sorted_params
36
+ expanded_params.sort_by{|k, _v| k }
37
+ end
38
+
39
+ def expanded_params
40
+ params = {}
41
+ @params.each do |key, value|
42
+ if Array === value
43
+ value.each.with_index(1) do |v, idx|
44
+ element_name = key.match(/([A-Z][a-z]+)List/)[1]
45
+ new_key = [key, element_name, idx.to_s].join(".")
46
+ params[new_key] = v
47
+ end
48
+ else
49
+ params[key] = value
50
+ end
51
+ end
52
+ params
53
+ end
54
+
34
55
  def timestamp_string
35
- (@params["Timestamp"].is_a?(Time) ? @params["Timestamp"] : Time.now).iso8601
56
+ (@params["Timestamp"].is_a?(Time) ? @params["Timestamp"] : Time.now).getutc.iso8601
36
57
  end
37
58
 
38
59
  def signature_string
@@ -40,11 +61,7 @@ module MWS
40
61
  end
41
62
 
42
63
  def request_string
43
- MWS::QueryString::RequestString.new(@method, @host, @path, @params)
44
- end
45
-
46
- def sorted_params
47
- @params.sort_by{|k, _v| k }
64
+ MWS::QueryString::RequestString.new(method: @method, endpoint: @endpoint, path: @path, params: expanded_params)
48
65
  end
49
66
  end
50
67
  end
data/lib/mws/report.rb ADDED
@@ -0,0 +1,17 @@
1
+ module MWS
2
+ module Report
3
+ DEFAULT_VERSION = "2009-01-01"
4
+
5
+ def method_missing(method, args={})
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)}"})
9
+
10
+ req = MWS::Request.new(args)
11
+ res = req.execute
12
+ res.body
13
+ end
14
+
15
+ module_function :method_missing
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ require "base64"
2
+ require "digest/md5"
3
+ require "net/http"
4
+ require "net/https"
5
+
6
+ module MWS
7
+ class Request
8
+ DEFAULT_METHOD = :post
9
+
10
+ def initialize(args)
11
+ @method = args[:method] || DEFAULT_METHOD
12
+ @path = args[:path]
13
+ @endpoint = args[:endpoint]
14
+ @headers = args[:headers] || {}
15
+ @body = args[:body] || ""
16
+ end
17
+
18
+ def execute
19
+ client = Net::HTTP.new(@endpoint, 443)
20
+ client.use_ssl = true
21
+
22
+ client.start do |https|
23
+ case @method
24
+ when :post then return https.post(@path, @body, headers)
25
+ else raise ArgumentError, "#{@method} is unknown HTTP method"
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def headers
33
+ {
34
+ "Content-Type" => "text/xml",
35
+ "Content-MD5" => Base64.encode64(Digest::MD5.digest(@body)),
36
+ "User-Agent" => "MarketplaceWebService/#{MWS::VERSION} (Language=Ruby)",
37
+ "Host" => @endpoint
38
+ }.merge(@headers)
39
+ end
40
+ end
41
+ end
data/lib/mws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MWS
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/mws.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "mws/query_string"
2
+ require "mws/report"
3
+ require "mws/request"
2
4
  require "mws/version"
3
5
 
4
6
  module MWS
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe MWS::QueryString::RequestString do
4
- let(:request_string){ MWS::QueryString::RequestString.new(method, host, path, params) }
4
+ let(:request_string){ MWS::QueryString::RequestString.new(method: method, endpoint: endpoint, path: path, params: params) }
5
5
  let(:method){ "POST" }
6
- let(:host){ "mws.amazonservice.com" }
6
+ let(:endpoint){ "mws.amazonservices.com" }
7
7
  let(:path){ "/" }
8
8
  let(:params) {
9
9
  {
@@ -17,7 +17,7 @@ describe MWS::QueryString::RequestString do
17
17
  let(:valid_request_string){
18
18
  request_string = <<-REQUEST_STRING
19
19
  POST
20
- mws.amazonservice.com
20
+ mws.amazonservices.com
21
21
  /
22
22
  Attr1=Value1&Attr2=Value2&Attr3=Value3&Timestamp=12%3A34%3A56
23
23
  REQUEST_STRING
@@ -5,10 +5,12 @@ describe MWS::QueryString do
5
5
  let(:valid_args){
6
6
  {
7
7
  key: "ThisIsSigningKey",
8
- host: "mws.amazonservice.com",
8
+ endpoint: "mws.amazonservices.com",
9
9
  params: {
10
10
  "Action" => "SubmitFeed",
11
- "Timestamp" => Time.new(2009, 8, 20, 1, 10, 27, 607)
11
+ "Timestamp" => Time.new(2009, 8, 20, 1, 10, 27, 607),
12
+ "SomethingIdList" => [123, 456],
13
+ "SomethingTypeList" => ["ABC", "DEF"]
12
14
  }
13
15
  }
14
16
  }
@@ -19,5 +21,7 @@ describe MWS::QueryString do
19
21
  it("should be formated with query style"){ is_expected.to match /\A([^=&]+=[^=&]+)(&[^=&]+=[^=&]+)*\Z/ }
20
22
  it("should be URI encoded"){ is_expected.not_to match /\A[A-Za-z0-9\-\_\.\~]*\Z/ }
21
23
  it("should have timestamp in ISO8601 format"){ is_expected.to match /\d{4}-\d{2}-\d{2}T\d{2}%3A\d{2}%3A\d{2}/ }
24
+ it("should have expanded ids"){ is_expected.to match "SomethingIdList.Id.1=123" }
25
+ it("should have expanded types"){ is_expected.to match "SomethingTypeList.Type.2=DEF" }
22
26
  end
23
27
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::Report do
4
+ describe ".method_missing" do
5
+ describe ".get_report_list" do
6
+ let(:valid_args){
7
+ {
8
+ key: "ThisIsSigningKey",
9
+ endpoint: "mws.amazonservices.com",
10
+ params: {
11
+ "AWSAccessKeyId" => "AccessKeyIdString",
12
+ "SellerId" => "SellerIdString",
13
+ "ReportTypeList" => ["_GET_FLAT_FILE_ORDERS_DATA_"],
14
+ "Acknowledged" => false,
15
+ "MaxCount" => 100
16
+ }
17
+ }
18
+ }
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.get_report_list(valid_args) }
29
+ it { is_expected.to be_a String }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::Request do
4
+ let(:request){ MWS::Request.new(valid_args) }
5
+ let(:valid_args){
6
+ {
7
+ path: "/?Attr=Value",
8
+ endpoint: "mws.amazonservices.com",
9
+ headers: {},
10
+ body: ""
11
+ }
12
+ }
13
+
14
+ describe "initialize" do
15
+ subject{ request }
16
+ it{ is_expected.to be_a MWS::Request }
17
+ end
18
+
19
+ describe "#execute" do
20
+ context "POST" do
21
+ before do
22
+ http = Net::HTTP.new("")
23
+ expect(http).to receive(:use_ssl=).with(true)
24
+ expect(http).to receive(:start).and_yield(http)
25
+ expect(http).to receive(:post)
26
+ expect(Net::HTTP).to receive(:new).and_return(http)
27
+ end
28
+
29
+ it "should POST request" do
30
+ expect{ request.execute }.not_to raise_error
31
+ end
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marketplace_web_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-08-29 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,12 +86,16 @@ files:
86
86
  - lib/mws/query_string/request_string.rb
87
87
  - lib/mws/query_string/signature.rb
88
88
  - lib/mws/query_string/uri_encoder.rb
89
+ - lib/mws/report.rb
90
+ - lib/mws/request.rb
89
91
  - lib/mws/version.rb
90
92
  - marketplace_web_service.gemspec
91
93
  - spec/mws/query_string/request_string_spec.rb
92
94
  - spec/mws/query_string/signature_spec.rb
93
95
  - spec/mws/query_string/uri_encoder_spec.rb
94
96
  - spec/mws/query_string_spec.rb
97
+ - spec/mws/report_spec.rb
98
+ - spec/mws/request_spec.rb
95
99
  - spec/mws_spec.rb
96
100
  - spec/spec_helper.rb
97
101
  homepage: https://github.com/e-maido/marketplace_web_service
@@ -123,5 +127,7 @@ test_files:
123
127
  - spec/mws/query_string/signature_spec.rb
124
128
  - spec/mws/query_string/uri_encoder_spec.rb
125
129
  - spec/mws/query_string_spec.rb
130
+ - spec/mws/report_spec.rb
131
+ - spec/mws/request_spec.rb
126
132
  - spec/mws_spec.rb
127
133
  - spec/spec_helper.rb