amazon_pa_api 0.3.0 → 1.0.0
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 +4 -4
- data/README.md +16 -35
- data/amazon_pa_api.gemspec +4 -0
- data/lib/amazon_pa_api.rb +6 -4
- data/lib/amazon_pa_api/operations/operation.rb +15 -15
- data/lib/amazon_pa_api/request.rb +3 -0
- data/lib/amazon_pa_api/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8dc19602365606f6d507c26873e6f9375114ddc
|
4
|
+
data.tar.gz: 7af1dcf5608210b20cfc0d9d7e02b34eb21e8110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 737b189beab8733db057ad1844dcde4548e4b6198232fac92739ebc8d214d9aca49b494a7f4307b5bc6647de570e3896827eacc4ec59fa13b7fe5f6e20d5371d
|
7
|
+
data.tar.gz: fc4245d404246d1a7618c9f46864f48acac8b41473fbc5132a6816daa4c6816d3fb45b8b6f4d0717f0504f7179e40b3a2488d512d07764062b12e8f440718acc
|
data/README.md
CHANGED
@@ -29,27 +29,31 @@ Or install it yourself as:
|
|
29
29
|
You can use easily Amazon Product Advertising API calls, like this:
|
30
30
|
|
31
31
|
```
|
32
|
+
AmazonPaApi::ItemLookup.access_key_id = "Your Amazon AWS access key id"
|
33
|
+
AmazonPaApi::ItemLookup.secret_access_key = "Your Amazon AWS secret access key"
|
34
|
+
AmazonPaApi::ItemLookup.associate_tag = "Your Amazon AWS associate tag"
|
35
|
+
|
32
36
|
item_lookup = AmazonPaApi::ItemLookup.new('B0026IAWMU')
|
33
|
-
item_lookup.access_key_id = "Your Amazon AWS access key id" # required
|
34
|
-
item_lookup.secret_access_key = "Your Amazon AWS secret key" # required
|
35
|
-
item_lookup.associate_tag = "Your Amazon associate tag" # required
|
36
|
-
|
37
37
|
puts item_lookup.get.body # => XML
|
38
|
+
|
39
|
+
# credentials are handled as class variables
|
40
|
+
item_search = AmazonPaApi::ItemSearch.new('Attack on Titan', 'Books')
|
41
|
+
puts item_search.get.body # => XML
|
38
42
|
```
|
39
43
|
|
40
44
|
Or you can set Amazon credentials as hash, like this:
|
41
45
|
|
42
46
|
```
|
43
|
-
credentials = { access_key_id: "Your Amazon AWS access key id",
|
44
|
-
secret_access_key: "Your Amazon AWS secret key",
|
45
|
-
associate_tag: "Your Amazon associate tag"
|
46
|
-
}
|
47
47
|
item_search = AmazonPaApi::ItemSearch.new('Attack on Titan', 'Books')
|
48
|
-
item_search.credentials =
|
48
|
+
item_search.credentials = { access_key_id: "Your Amazon AWS access key id",
|
49
|
+
secret_access_key: "Your Amazon AWS secret key",
|
50
|
+
associate_tag: "Your Amazon associate tag"
|
51
|
+
} # required
|
52
|
+
|
49
53
|
puts item_search.get.body # => XML
|
50
|
-
|
54
|
+
|
55
|
+
# credentials are handled as class variables
|
51
56
|
item_lookup = AmazonPaApi::ItemLookup.new('B0026IAWMU')
|
52
|
-
item_lookup.credentials = credentials
|
53
57
|
puts item_lookup.get.body # => XML
|
54
58
|
```
|
55
59
|
|
@@ -62,7 +66,6 @@ If you want to choice Amazon ECommerce end point:
|
|
62
66
|
|
63
67
|
# or like this:
|
64
68
|
item_lookup = AmazonPaApi::ItemLookup.new('B0026IAWMU')
|
65
|
-
item_lookup.credentials = credentials
|
66
69
|
puts item_lookup.get.body # => XML
|
67
70
|
|
68
71
|
item_lookup.region = :uk
|
@@ -83,13 +86,7 @@ You can use Amazon Product Advertising API operation's request parameters as ins
|
|
83
86
|
### ItemLookup
|
84
87
|
|
85
88
|
```
|
86
|
-
credentials = { access_key_id: "Your Amazon AWS access key id",
|
87
|
-
secret_access_key: "Your Amazon AWS secret key",
|
88
|
-
associate_tag: "Your Amazon associate tag"
|
89
|
-
}
|
90
|
-
|
91
89
|
item_lookup = AmazonPaApi::ItemLookup.new('B0026IAWMU')
|
92
|
-
item_lookup.credentials = credentials
|
93
90
|
puts item_lookup.get.body # => XML
|
94
91
|
|
95
92
|
```
|
@@ -97,37 +94,21 @@ You can use Amazon Product Advertising API operation's request parameters as ins
|
|
97
94
|
### ItemSearch
|
98
95
|
|
99
96
|
```
|
100
|
-
credentials = { access_key_id: "Your Amazon AWS access key id",
|
101
|
-
secret_access_key: "Your Amazon AWS secret key",
|
102
|
-
associate_tag: "Your Amazon associate tag"
|
103
|
-
}
|
104
97
|
item_search = AmazonPaApi::ItemSearch.new('Attack on Titan', 'Books')
|
105
|
-
item_search.credentials = credentials
|
106
98
|
puts item_search.get.body # => XML
|
107
99
|
```
|
108
100
|
|
109
101
|
### SimilarityLookup
|
110
102
|
|
111
103
|
```
|
112
|
-
credentials = { access_key_id: "Your Amazon AWS access key id",
|
113
|
-
secret_access_key: "Your Amazon AWS secret key",
|
114
|
-
associate_tag: "Your Amazon associate tag"
|
115
|
-
}
|
116
104
|
similarity_lookup = AmazonPaApi::SimilarityLookup.new('B0026IAWNU')
|
117
|
-
similarity_lookup.credentials = credentials
|
118
105
|
puts similarity_lookup.get.body # => XML
|
119
106
|
```
|
120
107
|
|
121
108
|
### BrowseNodeLookup
|
122
109
|
|
123
110
|
```
|
124
|
-
credentials = { access_key_id: "Your Amazon AWS access key id",
|
125
|
-
secret_access_key: "Your Amazon AWS secret key",
|
126
|
-
associate_tag: "Your Amazon associate tag"
|
127
|
-
}
|
128
|
-
|
129
111
|
browse_node_lookup = AmazonPaApi::BrowseNodeLookup(71443051)
|
130
|
-
browse_node_lookup.credentials = credentials
|
131
112
|
puts browse_node_lookup.get.body # => XML
|
132
113
|
```
|
133
114
|
|
@@ -139,7 +120,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
139
120
|
|
140
121
|
## Contributing
|
141
122
|
|
142
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sakura-computer/amazon_pa_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
143
124
|
|
144
125
|
|
145
126
|
## License
|
data/amazon_pa_api.gemspec
CHANGED
@@ -19,7 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = ">= 2.0.0"
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "accessor_extender", "~> 1.0"
|
25
29
|
end
|
data/lib/amazon_pa_api.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
require "accessor_extender"
|
2
|
+
require "net/http"
|
3
|
+
require "cgi"
|
4
|
+
require "openssl"
|
5
|
+
require "base64"
|
6
|
+
|
1
7
|
require "amazon_pa_api/version"
|
2
8
|
require "amazon_pa_api/extensions"
|
3
9
|
require "amazon_pa_api/operations/item_lookup"
|
@@ -5,7 +11,3 @@ require "amazon_pa_api/operations/item_search"
|
|
5
11
|
require "amazon_pa_api/operations/similarity_lookup"
|
6
12
|
require "amazon_pa_api/operations/browse_node_lookup"
|
7
13
|
|
8
|
-
require "net/http"
|
9
|
-
require "cgi"
|
10
|
-
require "openssl"
|
11
|
-
require "base64"
|
@@ -8,7 +8,7 @@ module AmazonPaApi
|
|
8
8
|
|
9
9
|
# PA api requires thease credentials.
|
10
10
|
# String - You must to set thease before performing operations.
|
11
|
-
|
11
|
+
cattr_accessor :access_key_id, :secret_access_key, :associate_tag
|
12
12
|
|
13
13
|
# Subclass set this variables at initialize.
|
14
14
|
# String - The name of operation you want to perform.
|
@@ -19,7 +19,7 @@ module AmazonPaApi
|
|
19
19
|
# default is jp.
|
20
20
|
attr_accessor :region
|
21
21
|
|
22
|
-
# You can get PA api response via
|
22
|
+
# You can get PA api response via these.
|
23
23
|
attr_reader :header, :body
|
24
24
|
|
25
25
|
API_VERSION = "2010-09-01".freeze
|
@@ -51,11 +51,11 @@ module AmazonPaApi
|
|
51
51
|
secret_access_key: '',
|
52
52
|
associate_tag:''
|
53
53
|
)
|
54
|
-
self.access_key_id = access_key_id
|
55
|
-
self.secret_access_key = secret_access_key
|
56
|
-
self.associate_tag = associate_tag
|
54
|
+
self.class.access_key_id = access_key_id
|
55
|
+
self.class.secret_access_key = secret_access_key
|
56
|
+
self.class.associate_tag = associate_tag
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
protected
|
60
60
|
|
61
61
|
# It set instance variable from defined request parameters in subclass.
|
@@ -72,18 +72,18 @@ module AmazonPaApi
|
|
72
72
|
parameters ={
|
73
73
|
"Service" => "AWSECommerceService",
|
74
74
|
"Timestamp" => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
75
|
-
"AWSAccessKeyId" =>
|
76
|
-
"AssociateTag" =>
|
75
|
+
"AWSAccessKeyId" => Operation.access_key_id.to_s,
|
76
|
+
"AssociateTag" => Operation.associate_tag.to_s,
|
77
77
|
"Operation" => self.operation,
|
78
78
|
"Version" => API_VERSION,
|
79
|
-
}.merge!(params)
|
79
|
+
}.merge!(params)
|
80
80
|
end
|
81
81
|
|
82
|
-
# It sort and set all query parameters as
|
82
|
+
# It sort and set all query parameters as string.
|
83
83
|
def request_params_string
|
84
84
|
request_params.sort.inject('') do |params_string, (k,v)|
|
85
85
|
params_string += '&' unless params_string.size == 0
|
86
|
-
params_string += "#{k.to_s}=#{CGI.escape(v.to_s)}"
|
86
|
+
params_string += "#{k.to_s}=#{CGI.escape(v.to_s).gsub('+', '%20')}"
|
87
87
|
params_string
|
88
88
|
end
|
89
89
|
end
|
@@ -94,7 +94,7 @@ module AmazonPaApi
|
|
94
94
|
# URI - To Amazon AWS ECommerce Service.
|
95
95
|
def add_signature(unsigned_uri)
|
96
96
|
signature = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"),
|
97
|
-
|
97
|
+
Operation.secret_access_key.to_s,
|
98
98
|
"GET\n#{unsigned_uri.host}\n#{unsigned_uri.path}\n#{unsigned_uri.query}"
|
99
99
|
)
|
100
100
|
signature = [signature].pack("m").chomp
|
@@ -105,9 +105,9 @@ module AmazonPaApi
|
|
105
105
|
|
106
106
|
# it add signature and requests Amazon via http.
|
107
107
|
def request
|
108
|
-
if self.access_key_id.nil? ||
|
109
|
-
self.secret_access_key.nil? ||
|
110
|
-
self.associate_tag.nil?
|
108
|
+
if self.class.access_key_id.nil? ||
|
109
|
+
self.class.secret_access_key.nil? ||
|
110
|
+
self.class.associate_tag.nil?
|
111
111
|
raise "PA api requires AWS credentials. Please set access_key_id, secret_access_key and associate_tag, try again."
|
112
112
|
end
|
113
113
|
raise "Invalid region. region: #{self.region}" unless END_POINTS.include?(self.region)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon_pa_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sakura-computer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: accessor_extender
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
55
69
|
description: The purpose of this gem is to make use of Amazon Product Advertising
|
56
70
|
API and pull easily Amazon products information.
|
57
71
|
email:
|
@@ -92,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
106
|
requirements:
|
93
107
|
- - '>='
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
109
|
+
version: 2.0.0
|
96
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
111
|
requirements:
|
98
112
|
- - '>='
|