marketplace_web_service 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 239536b4a413a5bf73c8fecb3cf265ac4a03e09c
4
+ data.tar.gz: 341d51dd9692a8e41a0c1f8027939f1154e93d2f
5
+ SHA512:
6
+ metadata.gz: ce056d8688ea77df39c70fb6acfe1b5afd7912191a7c6688746e77cc93922aa3a516deb23a50798d7516e6d5950c91c35bd186c323ac6d2a0083829212f7185a
7
+ data.tar.gz: 84e9d838c921a3d7d8d7b6c76bd20a3065d3f482a65d5a8f53a4e669e6a274e05db215b9b10d53d12dcd79041276c280f65586736c8a0384ed69b17f77ef45f9
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rspec
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marketplace_web_service.gemspec
4
+ gemspec
5
+
6
+ gem "coveralls", require: false
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 DKC Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # MarketplaceWebService
2
+
3
+ [![Build Status](https://travis-ci.org/e-maido/marketplace_web_service.svg?branch=master)](https://travis-ci.org/e-maido/marketplace_web_service)
4
+ [![Coverage Status](https://img.shields.io/coveralls/e-maido/marketplace_web_service.svg)](https://coveralls.io/r/e-maido/marketplace_web_service)
5
+
6
+ TODO: Write a gem description
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'marketplace_web_service'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install marketplace_web_service
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/[my-github-username]/marketplace_web_service/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+
@@ -0,0 +1,36 @@
1
+ require "mws/query_string/uri_encoder"
2
+
3
+ module MWS
4
+ class QueryString < ::String
5
+ class RequestString < ::String
6
+ def initialize(method, host, path, params)
7
+ @method = method
8
+ @host = host
9
+ @path = path
10
+ @params = params
11
+
12
+ super(request_string)
13
+ end
14
+
15
+ private
16
+
17
+ def sorted_params
18
+ Hash[@params.sort_by{|param| param[0] }]
19
+ end
20
+
21
+ def encoded_params
22
+ encoder = MWS::QueryString::UriEncoder.new
23
+ Hash[sorted_params.map{|pair| pair.map{|elm| encoder.encode(elm.to_s) } } ]
24
+ end
25
+
26
+ def request_string
27
+ [
28
+ @method.to_s.upcase,
29
+ @host,
30
+ @path,
31
+ encoded_params.map{|pair| pair.join("=") }.join("&")
32
+ ].join("\n")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ require "openssl"
2
+ require "base64"
3
+
4
+ module MWS
5
+ class QueryString < ::String
6
+ class Signature < ::String
7
+ def initialize(text, key)
8
+ bytes = OpenSSL::HMAC.digest("SHA256", key, text)
9
+ signature = Base64.strict_encode64(bytes)
10
+
11
+ super(signature)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
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.each_char.map{|char| NO_ENCODE_CHARACTERS.match(char) ? 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
@@ -0,0 +1,50 @@
1
+ require "mws/query_string/request_string"
2
+ require "mws/query_string/signature"
3
+ require "mws/query_string/uri_encoder"
4
+
5
+ module MWS
6
+ class QueryString < ::String
7
+ DEFAULT_METHOD = "POST"
8
+ DEFAULT_PATH = "/"
9
+ DEFAULT_PARAMS = {
10
+ "SignatureMethod" => "HmacSHA256",
11
+ "SignatureVersion" => "2"
12
+ }
13
+
14
+ 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])
20
+
21
+ @params["Timestamp"] = timestamp_string
22
+ @params["Signature"] = signature_string # This substitution must be final substitution
23
+
24
+ super(query_string)
25
+ end
26
+
27
+ private
28
+
29
+ def query_string
30
+ encoder = MWS::QueryString::UriEncoder.new
31
+ sorted_params.each.map{|k, v| [k, encoder.encode(v)].join("=") }.join("&")
32
+ end
33
+
34
+ def timestamp_string
35
+ (@params["Timestamp"].is_a?(Time) ? @params["Timestamp"] : Time.now).iso8601
36
+ end
37
+
38
+ def signature_string
39
+ MWS::QueryString::Signature.new(request_string, @key)
40
+ end
41
+
42
+ 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 }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module MWS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mws.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mws/query_string"
2
+ require "mws/version"
3
+
4
+ module MWS
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mws/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marketplace_web_service"
8
+ spec.version = MWS::VERSION
9
+ spec.authors = ["OSA Shunsuke"]
10
+ spec.email = ["hhelibebcnofnenamg@gmail.com"]
11
+ spec.summary = %q{Simple wrapper gem for Amazon MWS(Marketplace Web Service) API.}
12
+ spec.description = %q{Simple wrapper gem for Amazon MWS(Marketplace Web Service) API.}
13
+ spec.homepage = "https://github.com/e-maido/marketplace_web_service"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::QueryString::RequestString do
4
+ let(:request_string){ MWS::QueryString::RequestString.new(method, host, path, params) }
5
+ let(:method){ "POST" }
6
+ let(:host){ "mws.amazonservice.com" }
7
+ let(:path){ "/" }
8
+ let(:params) {
9
+ {
10
+ "Timestamp" => "12:34:56",
11
+ "Attr2" => "Value2",
12
+ "Attr1" => "Value1",
13
+ "Attr3" => "Value3"
14
+ }
15
+ }
16
+
17
+ let(:valid_request_string){
18
+ request_string = <<-REQUEST_STRING
19
+ POST
20
+ mws.amazonservice.com
21
+ /
22
+ Attr1=Value1&Attr2=Value2&Attr3=Value3&Timestamp=12%3A34%3A56
23
+ REQUEST_STRING
24
+ request_string.chomp
25
+ }
26
+
27
+ describe "initialize" do
28
+ subject{ request_string }
29
+ it{ is_expected.to be_a String }
30
+ it("should be valid request string"){ is_expected.to eq(valid_request_string) }
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::QueryString::Signature do
4
+ let(:signature){ MWS::QueryString::Signature.new(text, key) }
5
+ let(:text){ "This text will be signed." }
6
+ let(:key){ "ThisIsSigningKey" }
7
+ let(:signed_string){ "6/r286zqzGe2NW6oVT9he24kp0GEdvhT/uDP43VNFzQ=" }
8
+
9
+ describe "initialize" do
10
+ subject{ signature }
11
+ it{ is_expected.to be_a String }
12
+ it("should be signed string"){ is_expected.to eq(signed_string) }
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::QueryString::UriEncoder do
4
+ describe "#encode" do
5
+ let(:encoder){ MWS::QueryString::UriEncoder.new }
6
+
7
+ mappings = {
8
+ "abcdefghijklmnopqrstuvwxyz" => "abcdefghijklmnopqrstuvwxyz",
9
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
10
+ "0123456789" => "0123456789",
11
+ "-_.~" => "-_.~",
12
+ " " => "%20",
13
+ "%" => "%25",
14
+ "+" => "%2B",
15
+ "/" => "%2F",
16
+ ":" => "%3A",
17
+ "=" => "%3D",
18
+ "2009-08-20T01:10:27.607Z" => "2009-08-20T01%3A10%3A27.607Z"
19
+ }
20
+
21
+ mappings.each do |before, after|
22
+ describe "\"#{before}\"" do
23
+ subject{ encoder.encode(before) }
24
+ it{ is_expected.to eq(after) }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::QueryString do
4
+ let(:query_string){ MWS::QueryString.new(valid_args) }
5
+ let(:valid_args){
6
+ {
7
+ key: "ThisIsSigningKey",
8
+ host: "mws.amazonservice.com",
9
+ params: {
10
+ "Action" => "SubmitFeed",
11
+ "Timestamp" => Time.new(2009, 8, 20, 1, 10, 27, 607)
12
+ }
13
+ }
14
+ }
15
+
16
+ describe "initialize" do
17
+ subject{ query_string }
18
+ it{ is_expected.to be_a String }
19
+ it("should be formated with query style"){ is_expected.to match /\A([^=&]+=[^=&]+)(&[^=&]+=[^=&]+)*\Z/ }
20
+ it("should be URI encoded"){ is_expected.not_to match /\A[A-Za-z0-9\-\_\.\~]*\Z/ }
21
+ 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}/ }
22
+ end
23
+ end
data/spec/mws_spec.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS do
4
+ end
@@ -0,0 +1,11 @@
1
+ # coding: utf-8
2
+
3
+ project_root = File.join(File.dirname(__FILE__), '..')
4
+ $: << project_root
5
+
6
+ Dir[File.join(File.dirname(__FILE__), "support", "*")].each {|f| require f }
7
+
8
+ require 'lib/mws'
9
+
10
+ require 'coveralls'
11
+ Coveralls.wear!
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marketplace_web_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - OSA Shunsuke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Simple wrapper gem for Amazon MWS(Marketplace Web Service) API.
70
+ email:
71
+ - hhelibebcnofnenamg@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Guardfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - lib/mws.rb
84
+ - lib/mws/query_string.rb
85
+ - lib/mws/query_string/request_string.rb
86
+ - lib/mws/query_string/signature.rb
87
+ - lib/mws/query_string/uri_encoder.rb
88
+ - lib/mws/version.rb
89
+ - marketplace_web_service.gemspec
90
+ - spec/mws/query_string/request_string_spec.rb
91
+ - spec/mws/query_string/signature_spec.rb
92
+ - spec/mws/query_string/uri_encoder_spec.rb
93
+ - spec/mws/query_string_spec.rb
94
+ - spec/mws_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/e-maido/marketplace_web_service
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Simple wrapper gem for Amazon MWS(Marketplace Web Service) API.
120
+ test_files:
121
+ - spec/mws/query_string/request_string_spec.rb
122
+ - spec/mws/query_string/signature_spec.rb
123
+ - spec/mws/query_string/uri_encoder_spec.rb
124
+ - spec/mws/query_string_spec.rb
125
+ - spec/mws_spec.rb
126
+ - spec/spec_helper.rb