right_aws_api 0.3.0 → 0.3.2

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: d8bba3831173844f44970e8ec7de2bdf8deaccfd
4
- data.tar.gz: 2d690e778c5465ba65af461b3f270a650f7c095b
3
+ metadata.gz: d6a1dd0e9ac24ff82bc67bd76900622da118f004
4
+ data.tar.gz: 40c41f86035559e2946f0f2975efc5b3ddbc02dc
5
5
  SHA512:
6
- metadata.gz: 05dcde93bbe91da2df664699908be7983409703bbf915b886c1767f565e6fccf05219d4d4f8579cb035737d00073050ac6c380e198dc6d6d443becb89113c723
7
- data.tar.gz: 274c90d8e49ae082c0e87e5116bb04b24c18bad63910a41f79e15360f88e4247ae5c0f5935f9688905fa7612df6440ba6b8cded63f2646acc56bbd3912bbffcd
6
+ metadata.gz: d084136e0e7f1f8b33ded2c0c91f828486f0a9ea67eaa77844bbbf08442488b5e1992cf29d3296a1ab5fd28421c551eead3191a792b9326cb18fe374ec170f5c
7
+ data.tar.gz: e424d46fff517efa40d79b848fc756fb9b1979f49fdf968f9875efa2ba9bbbd7606634fba2b627e2f1ff9f0da7593b89b2695e052869f854da83cd7d162b79e6
data/HISTORY CHANGED
@@ -1,5 +1,27 @@
1
- == current
1
+ == current (not released as a gem yet)
2
+ - Fixed:
3
+ - Route53
4
+ - All POST actions were broken because of the missing 'xmlns' attribute.
5
+ - Added new services:
6
+ - Product Advertising API
7
+ - Market Web Service API:
8
+ - Cart Information
9
+ - Customer Information
10
+ - Feeds
11
+ - Finances
12
+ - Fulfillment Inbound Shipment
13
+ - Fulfillment Inventory
14
+ - Fulfillment Outbound Shipment
15
+ - Orders
16
+ - Products
17
+ - Recommendations
18
+ - Reports
19
+ - Sellers
20
+ - Subscriptions
21
+ - Webstore
2
22
 
23
+ == 2015-06-02, v0.3.1
24
+ - AWS china support
3
25
  == 2015-03-12, v0.3.0
4
26
  - Fixed bugs in Route53:
5
27
  - new param added to ChangeResourceRecordSets: HostedZoneId -> TargetHostedZoneId
data/README.md CHANGED
@@ -21,6 +21,8 @@ http://rightscale.github.io/right_aws_api/frames.html#!file.README.html
21
21
 
22
22
  The gem supports the following AWS services out of the box:
23
23
 
24
+ Web Services:
25
+
24
26
  - {RightScale::CloudApi::AWS::AS::Manager Auto Scaling (AS)}
25
27
  - {RightScale::CloudApi::AWS::CF::Manager Cloud Front (CF)}
26
28
  - {RightScale::CloudApi::AWS::CFM::Manager Cloud Formation (CFM)}
@@ -39,6 +41,27 @@ The gem supports the following AWS services out of the box:
39
41
  - {RightScale::CloudApi::AWS::SNS::Manager Simple Notification Service (SNS)}
40
42
  - {RightScale::CloudApi::AWS::SQS::Manager Simple Queue Service (SQS)}
41
43
 
44
+ Product Advertising API:
45
+
46
+ - {RightScale::CloudApi::ECS::PA::Manager Product Advertising API (PA)}
47
+
48
+ Market Web Services:
49
+
50
+ - {RightScale::CloudApi::MWS::CartInformation::Manager Cart Information}
51
+ - {RightScale::CloudApi::MWS::CustomerInformation::Manager Customer Information}
52
+ - {RightScale::CloudApi::MWS::Feeds::Manager Feeds}
53
+ - {RightScale::CloudApi::MWS::Finances::Manager Finances}
54
+ - {RightScale::CloudApi::MWS::FulfillmentInboundShipment::Manager Fulfillment Inbound Shipment}
55
+ - {RightScale::CloudApi::MWS::FulfillmentInventory::Manager Fulfillment Inventory}
56
+ - {RightScale::CloudApi::MWS::FulfillmentOutboundShipment::Manager Fulfillment Outbound Shipment}
57
+ - {RightScale::CloudApi::MWS::Orders::Manager Orders}
58
+ - {RightScale::CloudApi::MWS::Products::Manager Products}
59
+ - {RightScale::CloudApi::MWS::Recommendations::Manager Recommendations}
60
+ - {RightScale::CloudApi::MWS::Reports::Manager Reports}
61
+ - {RightScale::CloudApi::MWS::Sellers::Manager Sellers}
62
+ - {RightScale::CloudApi::MWS::Subscriptions::Manager Subscriptions}
63
+ - {RightScale::CloudApi::MWS::Webstore::Manager Webstore}
64
+
42
65
  And it is easy to add support for other. You will need to refer to
43
66
  the AWS docs (http://aws.amazon.com/documentation/) for all the API params and usage explanations.
44
67
 
@@ -159,6 +182,52 @@ call and you know what params it accepts - just call the method with those param
159
182
  sqs.DeleteQueue('myCoolQueue')
160
183
  ```
161
184
 
185
+ ### Amazon Product Advertising API (PA)
186
+
187
+ ```ruby
188
+
189
+ require "right_aws_api"
190
+
191
+ key = ENV['AWS_ACCESS_KEY_ID']
192
+ secret = ENV['AWS_SECRET_ACCESS_KEY']
193
+ endpoint = 'https://webservices.amazon.com'
194
+ paa = RightScale::CloudApi::ECS::PA::Manager.new(key, secret, endpoint)
195
+
196
+ paa.ItemLookup(
197
+ 'AssociateTag' => 'weird-tag',
198
+ 'IdType' => 'ASIN',
199
+ 'ItemId' => 'B00TRAO8HK',
200
+ 'ResponseGroup' => 'OfferSummary'
201
+ )
202
+ ```
203
+
204
+ ### Amazon Market Web Services API (MWS)
205
+
206
+ ```ruby
207
+
208
+ key = ENV['AWS_ACCESS_KEY_ID']
209
+ secret = ENV['AWS_SECRET_ACCESS_KEY']
210
+ endpoint = 'https://mws.amazonservices.com'
211
+
212
+ # Webstore
213
+ ws = RightScale::CloudApi::MWS::Webstore::Manager.new(key, secret, endpoint)
214
+ ws.GetServiceStatus
215
+
216
+ # Reports
217
+ rd = RightScale::CloudApi::MWS::Reports::Manager.new(key, secret, endpoint)
218
+ rd.GetReportList(
219
+ 'SellerId' => 'foo',
220
+ 'MarketplaceId' => 'bar',
221
+ )
222
+
223
+ # Recommendations
224
+ rd = RightScale::CloudApi::MWS::Recommendations::Manager.new(key, secret, endpoint)
225
+ rd.ListRecommendations(
226
+ 'SellerId' => 'foo',
227
+ 'MarketplaceId' => 'bar',
228
+ )
229
+ ```
230
+
162
231
  ### Options
163
232
 
164
233
  There is a way to provide extra options when you instantiate a new manager:
@@ -204,10 +204,10 @@ module RightScale
204
204
  when host[ /^route53\.amazonaws\.com$/i ] then ['route53', 'us-east-1']
205
205
  when host[ /^(.*\.)?s3\.amazonaws\.com$/i ] then ['s3', 'us-east-1']
206
206
  when host[ /^(.*\.)?s3-external-1\.amazonaws\.com$/i ] then ['s3', 'us-east-1']
207
- when host[ /s3-website-([^.]+)\.amazonaws\.com$/i ] then ['s3', $1]
208
- when host[ /^(.*\.)?s3-([^.]+).amazonaws\.com$/i ] then ['s3', $2]
209
- when host[ /^(.*\.)?s3\.([^.]+)\.amazonaws\.com$/i ] then ['s3', $2]
210
- else host[ /^([^.]+)\.([^.]+)\.amazonaws\.com$/i ] && [$1, $2]
207
+ when host[ /s3-website(-|\.)([^.]+)\.amazonaws\.com(\.cn)?$/i ] then ['s3', $2]
208
+ when host[ /^(.*\.)?s3-([^.]+).amazonaws\.com(\.cn)?$/i ] then ['s3', $2]
209
+ when host[ /^(.*\.)?s3\.([^.]+)\.amazonaws\.com(\.cn)?$/i ] then ['s3', $2]
210
+ else host[ /^([^.]+)\.([^.]+)\.amazonaws\.com(\.cn)?$/i ] && [$1, $2]
211
211
  end
212
212
  fail(ArgumentError, "Cannot extract service name from %s host" % host.inspect) if !result || result[0].to_s.empty?
213
213
  fail(ArgumentError, "Cannot extract region name from %s host" % host.inspect) if result[1].to_s.empty?
@@ -32,9 +32,6 @@ module RightScale
32
32
  class Error < CloudApi::Error
33
33
  end
34
34
 
35
- # Use POST verb if GET's path is getting too big.
36
- MAX_GET_REQUEST_PATH_LENGTH = 2000
37
-
38
35
  # Authenticates an AWS request
39
36
  #
40
37
  # @return [void]
@@ -48,6 +48,7 @@ module RightScale
48
48
  base.query_api_pattern 'CreateHostedZone', :post, 'hostedzone',
49
49
  :body => {
50
50
  'CreateHostedZoneRequest' => {
51
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
51
52
  'Name' => :Name,
52
53
  'CallerReference' => :CallerReference,
53
54
  'HostedZoneConfig{!remove-if-blank}' => {
@@ -78,6 +79,7 @@ module RightScale
78
79
  base.query_api_pattern 'UpdateHostedZoneComment', :post, 'hostedzone/{:HostedZoneId}',
79
80
  :body => {
80
81
  'UpdateHostedZoneCommentRequest' => {
82
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
81
83
  'Comment' => :Comment
82
84
  }
83
85
  }
@@ -85,6 +87,7 @@ module RightScale
85
87
  base.query_api_pattern 'AssociateVPCWithHostedZone', :post, 'hostedzone/{:HostedZoneId}/associatevpc',
86
88
  :body => {
87
89
  'AssociateVPCWithHostedZoneRequest' => {
90
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
88
91
  'VPC{!remove-if-blank}' => {
89
92
  'VPCId' => :VPCId,
90
93
  'VPCRegion' => :VPCRegion
@@ -99,6 +102,7 @@ module RightScale
99
102
  base.query_api_pattern 'DisassociateVPCFromHostedZone', :post, 'hostedzone/{:HostedZoneId}/disassociatevpc',
100
103
  :body => {
101
104
  'DisassociateVPCFromHostedZoneRequest' => {
105
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
102
106
  'VPC{!remove-if-blank}' => {
103
107
  'VPCId' => :VPCId,
104
108
  'VPCRegion' => :VPCRegion
@@ -127,6 +131,7 @@ module RightScale
127
131
  base.query_api_pattern 'ChangeResourceRecordSets', :post, 'hostedzone/{:HostedZoneId}/rrset',
128
132
  :body => {
129
133
  'ChangeResourceRecordSetsRequest' => {
134
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
130
135
  'ChangeBatch' => {
131
136
  'Comment' => :Comment,
132
137
  'Changes' => {
@@ -184,6 +189,7 @@ module RightScale
184
189
  base.query_api_pattern 'CreateReusableDelegationSet', :post, 'delegationset',
185
190
  :body => {
186
191
  'CreateReusableDelegationSetRequest' => {
192
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
187
193
  'CallerReference' => :CallerReference,
188
194
  'HostedZoneId' => :HostedZoneId
189
195
  }
@@ -202,6 +208,7 @@ module RightScale
202
208
  base.query_api_pattern 'CreateHealthCheck', :post, 'healthcheck',
203
209
  :body => {
204
210
  'CreateHealthCheckRequest' => {
211
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
205
212
  'CallerReference' => :CallerReference,
206
213
  'HealthCheckConfig' => {
207
214
  'IPAddress' => :IPAddress,
@@ -227,6 +234,7 @@ module RightScale
227
234
  base.query_api_pattern 'UpdateHealthCheck', :post, 'healthcheck/{:HealthCheckId}',
228
235
  :body => {
229
236
  'CreateHealthCheckRequest' => {
237
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
230
238
  'HealthCheckVersion' => :HealthCheckVersion,
231
239
  'IPAddress' => :IPAddress,
232
240
  'Port' => :Port,
@@ -267,6 +275,7 @@ module RightScale
267
275
  base.query_api_pattern 'ChangeTagsForResource', :post, 'tags/{:ResourceType}/{:ResourceId}',
268
276
  :body => {
269
277
  'ChangeTagsForResourceRequest' => {
278
+ '@xmlns' => 'https://route53.amazonaws.com/doc/2013-04-01/',
270
279
  'RemoveTagKeys' => :RemoveTagKeys,
271
280
  'AddTags{!remove-if-blank}' => {
272
281
  'Tag' => :Tag
@@ -0,0 +1,138 @@
1
+ #--
2
+ # Copyright (c) 2015 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require "cloud/ecs/pa/routines/request_signer"
25
+ require "cloud/ecs/pa/parsers/response_error"
26
+
27
+ module RightScale
28
+ module CloudApi
29
+
30
+ # ECS (ECommerceService) namespace
31
+ module ECS
32
+
33
+ module PA
34
+
35
+ # Product Advertising API (PA) compatible manager (thread safe).
36
+ #
37
+ # @example
38
+ # require "right_aws_api"
39
+ #
40
+ # # Create a manager to access Product Advertising API.
41
+ # paa = RightScale::CloudApi::ECS::PA::Manager.new(key, secret, 'https://webservices.amazon.com')
42
+ #
43
+ # paa.ThisCallMustBeSupportedByPA('Param.1' => 'A', 'Param.2' => 'B') #=> Hash
44
+ #
45
+ # @example
46
+ # paa.ItemSearch(
47
+ # 'AssociateTag' => 'weird-tag',
48
+ # 'BrowseNode' => 2625374011,
49
+ # 'MaximumPrice' => 2000,
50
+ # 'MinimumPrice' => 2000,
51
+ # 'ResponseGroup' => 'SalesRank',
52
+ # 'SearchIndex' => 'DVD',
53
+ # 'Sort' => 'salesrank',
54
+ # ) #=>
55
+ # {"ItemSearchResponse"=>
56
+ # {"@xmlns"=>"http://webservices.amazon.com/AWSECommerceService/2013-08-01",
57
+ # "OperationRequest"=>
58
+ # {"HTTPHeaders"=>{"Header"=>{"@Name"=>"UserAgent", "@Value"=>"Ruby"}},
59
+ # "RequestId"=>"a21817e1-f828-4a80-8b6a-c27e320b92e2",
60
+ # "Arguments"=>
61
+ # {"Argument"=> ..... }}}
62
+ #
63
+ # @example
64
+ # paa.ItemLookup(
65
+ # 'AssociateTag' => 'weird-tag',
66
+ # 'IdType' => 'ASIN',
67
+ # 'ItemId' => 'B00TRAO8HK',
68
+ # 'ResponseGroup' => 'OfferSummary',
69
+ # ) #=>
70
+ # {"ItemLookupResponse"=>
71
+ # {"@xmlns"=>"http://webservices.amazon.com/AWSECommerceService/2013-08-01",
72
+ # "OperationRequest"=>
73
+ # {"HTTPHeaders"=>{"Header"=>{"@Name"=>"UserAgent", "@Value"=>"Ruby"}},
74
+ # "RequestId"=>"1c199f5d-3794-40b3-9fc4-33316010d130",
75
+ # "Arguments"=> { ... },
76
+ # "Items"=>
77
+ # {"Request"=> { ... },
78
+ # "Item"=>
79
+ # {"ASIN"=>"B00TRAO8HK",
80
+ # "OfferSummary"=>
81
+ # {"LowestNewPrice"=>
82
+ # {"Amount"=>"2000",
83
+ # "CurrencyCode"=>"USD",
84
+ # "FormattedPrice"=>"$20.00"},
85
+ # "LowestUsedPrice"=>
86
+ # {"Amount"=>"2654",
87
+ # "CurrencyCode"=>"USD",
88
+ # "FormattedPrice"=>"$26.54"},
89
+ # "TotalNew"=>"23",
90
+ # "TotalUsed"=>"2",
91
+ # "TotalCollectible"=>"0",
92
+ # "TotalRefurbished"=>"0"}}}}}
93
+ #
94
+ # If there is a new API version available just pass it to the manager!
95
+ #
96
+ # @example
97
+ # paa = RightScale::CloudApi::ECS::PA::Manager.new(key, secret, 'https://webservices.amazon.com', :api_version => "2021-12-31")
98
+ #
99
+ # @see ApiManager
100
+ # @see http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html
101
+ #
102
+ class Manager < CloudApi::Manager
103
+ end
104
+
105
+ # Thread un-safe parent class for almost all the AWS services.
106
+ class ApiManager < AWS::ApiManager
107
+
108
+ DEFAULT_API_VERSION = '2013-08-01'
109
+
110
+ set_routine RetryManager
111
+ set_routine RequestInitializer
112
+ set_routine ECS::PA::RequestSigner
113
+ set_routine RequestGenerator
114
+ set_routine RequestAnalyzer
115
+ set_routine ConnectionProxy
116
+ set_routine ResponseAnalyzer
117
+ set_routine CacheValidator
118
+ set_routine ResponseParser
119
+ set_routine ResultWrapper
120
+
121
+ set :response_error_parser => Parser::ECS::ResponseError
122
+
123
+ def api(action, params={}, &block)
124
+ params['Operation'] ||= action.to_s._snake_case._camelize
125
+ opts = {}
126
+ verb = params.delete(:verb) || :post
127
+ opts[:body] = params.delete(:body)
128
+ opts[:headers] = params.delete(:headers) || {}
129
+ opts[:options] = params.delete(:options) || {}
130
+ opts[:params] = parametrize(params)
131
+ process_api_request(verb, 'onca/xml', opts, &block)
132
+ end
133
+
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,85 @@
1
+ #--
2
+ # Copyright (c) 2015 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module RightScale
25
+ module CloudApi
26
+ # Parsers namespace
27
+ module Parser
28
+ # AWS parsers namespace
29
+ module ECS
30
+
31
+ # AWS response error parser, case 1
32
+ #
33
+ class ResponseError
34
+
35
+ # Parse HTTP error message from a response body
36
+ #
37
+ # @param [RightScale::CloudApi::HTTPResponse] response
38
+ # @param [Hash] options
39
+ # @option options [Class] :xml_parser
40
+ #
41
+ # @return [String]
42
+ #
43
+ # @example
44
+ # # For the call below:
45
+ # ec2.DescribeInstances('InstanceId' => 'hohoho')
46
+ # # Generates an XML error:
47
+ # <?xml version="1.0"?>
48
+ # <ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/">
49
+ # <Error>
50
+ # <Code>
51
+ # AWS.InvalidAccount
52
+ # </Code>
53
+ # <Message>
54
+ # Your AccessKey Id is not registered for Product Advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html
55
+ # </Message>
56
+ # </Error>
57
+ # <RequestId>
58
+ # 57510d4f-72ad-4c15-985c-1dc330e5f3d4
59
+ # </RequestId>
60
+ # </ItemLookupErrorResponse>
61
+ # # And the method parse all above into:
62
+ # 400: Your AccessKey Id is not registered for Product Advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html (RequestID: 57510d4f-72ad-4c15-985c-1dc330e5f3d4)
63
+ #
64
+ def self.parse(response, options={})
65
+ result = "#{response.code}: "
66
+ body = response.body.to_s
67
+ if response['content-type'].to_s[/xml/] || body[/\A<\?xml /]
68
+ hash = Utils::get_xml_parser_class(options[:xml_parser]).parse(body)
69
+ top_key = hash.keys.first
70
+ error = hash[top_key] && hash[top_key]["Error"]
71
+ if error
72
+ result << ('%s: %s' % [error['Code'], error['Message']])
73
+ result << (' (RequestID: %s)' % hash[top_key]['RequestId'])
74
+ end
75
+ else
76
+ result << body unless body._blank?
77
+ end
78
+ result
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end