right_aws_api 0.1.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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +2 -0
  3. data/LICENSE +19 -0
  4. data/README.md +164 -0
  5. data/Rakefile +38 -0
  6. data/lib/cloud/aws/as/manager.rb +118 -0
  7. data/lib/cloud/aws/base/helpers/utils.rb +328 -0
  8. data/lib/cloud/aws/base/manager.rb +186 -0
  9. data/lib/cloud/aws/base/parsers/response_error.rb +117 -0
  10. data/lib/cloud/aws/base/routines/request_signer.rb +80 -0
  11. data/lib/cloud/aws/cf/manager.rb +171 -0
  12. data/lib/cloud/aws/cf/routines/request_signer.rb +70 -0
  13. data/lib/cloud/aws/cf/wrappers/default.rb +213 -0
  14. data/lib/cloud/aws/cfm/manager.rb +90 -0
  15. data/lib/cloud/aws/cw/manager.rb +113 -0
  16. data/lib/cloud/aws/eb/manager.rb +87 -0
  17. data/lib/cloud/aws/ec/manager.rb +91 -0
  18. data/lib/cloud/aws/ec2/manager.rb +222 -0
  19. data/lib/cloud/aws/elb/manager.rb +120 -0
  20. data/lib/cloud/aws/emr/manager.rb +86 -0
  21. data/lib/cloud/aws/iam/manager.rb +100 -0
  22. data/lib/cloud/aws/rds/manager.rb +110 -0
  23. data/lib/cloud/aws/route53/manager.rb +177 -0
  24. data/lib/cloud/aws/route53/routines/request_signer.rb +70 -0
  25. data/lib/cloud/aws/route53/wrappers/default.rb +132 -0
  26. data/lib/cloud/aws/s3/manager.rb +373 -0
  27. data/lib/cloud/aws/s3/parsers/response_error.rb +76 -0
  28. data/lib/cloud/aws/s3/routines/request_signer.rb +243 -0
  29. data/lib/cloud/aws/s3/wrappers/default.rb +315 -0
  30. data/lib/cloud/aws/sdb/manager.rb +150 -0
  31. data/lib/cloud/aws/sns/manager.rb +96 -0
  32. data/lib/cloud/aws/sqs/manager.rb +335 -0
  33. data/lib/right_aws_api.rb +45 -0
  34. data/lib/right_aws_api_version.rb +40 -0
  35. data/right_aws_api.gemspec +55 -0
  36. data/spec/describe_calls.rb +92 -0
  37. metadata +118 -0
@@ -0,0 +1,150 @@
1
+ #--
2
+ # Copyright (c) 2013 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/aws/base/manager"
25
+
26
+ module RightScale
27
+ module CloudApi
28
+ module AWS
29
+
30
+ # Simple DB namespace
31
+ #
32
+ # @api public
33
+ #
34
+ module SDB
35
+
36
+ # Amazon Simple DB (SDB) compatible manager (thread safe).
37
+ #
38
+ # @example
39
+ # require "right_aws_api"
40
+ #
41
+ # # Create a manager to access SDB.
42
+ # sdb = RightScale::CloudApi::AWS::SDB::Manager::new(key, secret, 'https://sdb.amazonaws.com' )
43
+ #
44
+ # sdb.ListDomains #=>
45
+ # {"ListDomainsResponse"=>
46
+ # {"ListDomainsResult"=>
47
+ # {"DomainName"=>
48
+ # ["kd_tests",
49
+ # "kdclient"]},
50
+ # "ResponseMetadata"=>
51
+ # {"RequestId"=>"d430ab64-18ff-b529-fc0c-0cae65d68203",
52
+ # "BoxUsage"=>"0.0000071759"},
53
+ # "@xmlns"=>"http://sdb.amazonaws.com/doc/2009-04-15/"}}
54
+ #
55
+ # @example
56
+ # sdb.PutAttributes('DomainName' => 'kdclient',
57
+ # 'ItemName' => 'Employee',
58
+ # 'Attribute' => [ { 'Name' => 'name', 'Value' => 'John' },
59
+ # { 'Name' => 'age', 'Value' => '33' },
60
+ # { 'Name' => 'sex', 'Value' => 'male } ]) #=>
61
+ # {"PutAttributesResponse"=>
62
+ # {"ResponseMetadata"=>
63
+ # {"RequestId"=>"210d06ce-8b15-0035-1084-baec98874f75",
64
+ # "BoxUsage"=>"0.0000219961"},
65
+ # "@xmlns"=>"http://sdb.amazonaws.com/doc/2009-04-15/"}}
66
+ #
67
+ #
68
+ # @example
69
+ # # BatchPutAttributes
70
+ # sdb.BatchPutAttributes( "DomainName" => "kdclient",
71
+ # "Item.1.ItemName" => "konstantin",
72
+ # "Item.1.Attribute.1.Name" => "sex",
73
+ # "Item.1.Attribute.1.Value" => "male",
74
+ # "Item.1.Attribute.2.Name" => "weight",
75
+ # "Item.1.Attribute.2.Value" => "170",
76
+ # "Item.1.Attribute.3.Name" => "age",
77
+ # "Item.1.Attribute.3.Value" => "38",
78
+ # "Item.2.ItemName" => "alex",
79
+ # "Item.2.Attribute.1.Name" => "sex",
80
+ # "Item.2.Attribute.1.Value" => "male",
81
+ # "Item.2.Attribute.2.Name" => "weight",
82
+ # "Item.2.Attribute.2.Value" => "188",
83
+ # "Item.2.Attribute.3.Name" => "age",
84
+ # "Item.2.Attribute.3.Value" => "42",
85
+ # "Item.3.ItemName" => "diana",
86
+ # "Item.3.Attribute.1.Name" => "sex",
87
+ # "Item.3.Attribute.1.Value" => "female",
88
+ # "Item.3.Attribute.2.Name" => "weight",
89
+ # "Item.3.Attribute.2.Value" => "120",
90
+ # "Item.3.Attribute.3.Name" => "age",
91
+ # "Item.3.Attribute.3.Value" => "25" )
92
+ #
93
+ # # ... the same as the call above (see {RightScale::CloudApi::Utils::AWS::parametrize} method usage)
94
+ # sdb.BatchPutAttributes( 'DomainName' => 'kdclient',
95
+ # 'Item' => [ { 'ItemName' => 'konstantin',
96
+ # 'Attribute' => [ { 'Name' => 'sex', 'Value' => 'male' },
97
+ # { 'Name' => 'weight', 'Value' => '170'},
98
+ # { 'Name' => 'age', 'Value' => '38'} ] },
99
+ # { 'ItemName' => 'alex',
100
+ # 'Attribute' => [ { 'Name' => 'sex', 'Value' => 'male' },
101
+ # { 'Name' => 'weight', 'Value' => '188'},
102
+ # { 'Name' => 'age', 'Value' => '42'} ] },
103
+ # { 'ItemName' => 'diana',
104
+ # 'Attribute' => [ { 'Name' => 'sex', 'Value' => 'female' },
105
+ # { 'Name' => 'weight', 'Value' => '120'},
106
+ # { 'Name' => 'age', 'Value' => '25'} ] } ] ) #=>
107
+ # {"BatchPutAttributesResponse"=>
108
+ # {"ResponseMetadata"=>
109
+ # {"RequestId"=>"4b0d9997-0a51-2c4f-3424-da04225d6ef9",
110
+ # "BoxUsage"=>"0.0000461918"},
111
+ # "@xmlns"=>"http://sdb.amazonaws.com/doc/2009-04-15/"}}
112
+ #
113
+ # sdb.Select('SelectExpression' => "select name from kdclient where sex = 'female'")
114
+ #
115
+ # @see ApiManager
116
+ # @see http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/SDB_API_Operations.html
117
+ #
118
+ class Manager < AWS::Manager
119
+ end
120
+
121
+
122
+ # Amazon SimpleDB (SDB) compatible manager (thread unsafe).
123
+ #
124
+ # @see Manager
125
+ #
126
+ class ApiManager < AWS::ApiManager
127
+
128
+ # Default API version for SimpleDB service.
129
+ # To override the API version use :api_version key when instantiating a manager.
130
+ #
131
+ DEFAULT_API_VERSION = '2009-04-15'
132
+
133
+ error_pattern :abort_on_timeout, :path => /Action=(Create|Put|BatchPut)/
134
+ error_pattern :retry, :response => /InternalError|Unavailable/i
135
+ error_pattern :disconnect_and_abort, :code => /5..|403|408/
136
+ error_pattern :disconnect_and_abort, :code => /4../, :if => Proc.new{ |opts| rand(100) < 10 }
137
+
138
+ set :response_error_parser => Parser::AWS::ResponseErrorV2
139
+
140
+ cache_pattern :verb => /get|post/,
141
+ :path => /Action=List/,
142
+ :if => Proc::new{ |o| (o[:params].keys - COMMON_QUERY_PARAMS)._blank? },
143
+ :key => Proc::new{ |o| o[:params]['Action'] },
144
+ :sign => Proc::new{ |o| o[:response].body.to_s.sub(%r{<RequestId>.+?</RequestId>}i,'') }
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,96 @@
1
+ #--
2
+ # Copyright (c) 2013 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/aws/base/manager"
25
+
26
+ module RightScale
27
+ module CloudApi
28
+ module AWS
29
+
30
+ # Simple Notification Service namespace
31
+ #
32
+ # @api public
33
+ #
34
+ module SNS
35
+
36
+ # Amazon Simple Notification Service (SNS) compatible clouds manager (thread safe).
37
+ #
38
+ # @example
39
+ # require "right_aws_api"
40
+ #
41
+ # sns = RightScale::CloudApi::AWS::SNS::Manager.new(
42
+ # ENV['AWS_ACCESS_KEY_ID'],
43
+ # ENV['AWS_SECRET_ACCESS_KEY'],
44
+ # 'https://sns.us-east-1.amazonaws.com')
45
+ #
46
+ # @example
47
+ # sns.CreateTopic('Name' => 'myNewTopic') #=>
48
+ # {"CreateTopicResponse"=>
49
+ # {"@xmlns"=>"http://sns.amazonaws.com/doc/2010-03-31/",
50
+ # "CreateTopicResult"=>
51
+ # {"TopicArn"=>"arn:aws:sns:us-east-1:826693181925:myNewTopic"},
52
+ # "ResponseMetadata"=>{"RequestId"=>"ba2c7170-8d8f-11e1-99c8-cd4871234eac"}}}
53
+ #
54
+ # @example
55
+ # sns.ListSubscriptions #=>
56
+ # {"ListSubscriptionsResponse"=>
57
+ # {"@xmlns"=>"http://sns.amazonaws.com/doc/2010-03-31/",
58
+ # "ListSubscriptionsResult"=>{"Subscriptions"=>nil},
59
+ # "ResponseMetadata"=>{"RequestId"=>"8d53941d-8d8f-11e1-a165-a1021f73c0e5"}}}
60
+ #
61
+ # @see ApiManager
62
+ # @see http://docs.amazonwebservices.com/sns/latest/api/API_Operations.html
63
+ #
64
+ class Manager < AWS::Manager
65
+ end
66
+
67
+
68
+ # Amazon Simple Notification Service (SNS) compatible clouds manager (thread unsafe).
69
+ #
70
+ # @see Manager
71
+ #
72
+ class ApiManager < AWS::ApiManager
73
+
74
+ # Default API version for SNS service.
75
+ # To override the API version use :api_version key when instantiating a manager.
76
+ #
77
+ DEFAULT_API_VERSION = '2010-03-31'
78
+
79
+ error_pattern :abort_on_timeout, :path => /Action=(Create)/
80
+ error_pattern :retry, :response => /InternalError|Unavailable/i
81
+ error_pattern :disconnect_and_abort, :code => /5..|403|408/
82
+ error_pattern :disconnect_and_abort, :code => /4../, :if => Proc.new{ |opts| rand(100) < 10 }
83
+
84
+ set :response_error_parser => Parser::AWS::ResponseErrorV2
85
+
86
+ cache_pattern :verb => /get|post/,
87
+ :path => /Action=List/,
88
+ :if => Proc::new{ |o| (o[:params].keys - COMMON_QUERY_PARAMS)._blank? },
89
+ :key => Proc::new{ |o| o[:params]['Action'] },
90
+ :sign => Proc::new{ |o| o[:response].body.to_s.sub(%r{<RequestId>.+?</RequestId>}i,'') }
91
+ end
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,335 @@
1
+ #--
2
+ # Copyright (c) 2013 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/aws/base/helpers/utils"
25
+ require "cloud/aws/base/routines/request_signer"
26
+ require "cloud/aws/base/parsers/response_error"
27
+
28
+ module RightScale
29
+ module CloudApi
30
+ module AWS
31
+
32
+ # Simple Queue Service namespace
33
+ #
34
+ # @api public
35
+ #
36
+ module SQS
37
+
38
+ # Amazon Simple Queue Service (SQS) compatible manager (thread safe).
39
+ #
40
+ # @example
41
+ # require "right_aws_api"
42
+ #
43
+ # # Create a manager
44
+ # sqs = RightScale::CloudApi::AWS::SQS::Manager.new(
45
+ # ENV['AWS_ACCESS_KEY_ID'],
46
+ # ENV['AWS_SECRET_ACCESS_KEY'],
47
+ # ENV['AWS_ACCOUNT_NUMBER'],
48
+ # 'https://sqs.us-east-1.amazonaws.com')
49
+ #
50
+ # # List all queues
51
+ # sqs.ListQueues #=>
52
+ # {"ListQueuesResponse"=>
53
+ # {"ResponseMetadata"=>{"RequestId"=>"9db0c9d7-35cf-4477-bc13-bbeacaf16d9b"},
54
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/",
55
+ # "ListQueuesResult"=>
56
+ # {"QueueUrl"=>
57
+ # ["https://sqs.us-east-1.amazonaws.com/826693181925/Abracadabra",
58
+ # "https://sqs.us-east-1.amazonaws.com/826693181925/JM-Output"] }}}
59
+ #
60
+ # @example
61
+ # # Create new queue (Amazon way)...
62
+ # sqs.CreateQueue( 'QueueName' => 'myCoolQueue',
63
+ # 'Attribute.1.Name' => 'VisibilityTimeout',
64
+ # 'Attribute.1.Value' => '40',
65
+ # 'Attribute.2.Name' => 'MaximumMessageSize',
66
+ # 'Attribute.2.Value' => '2048' )
67
+ #
68
+ # # ... or using CloudApi way:
69
+ # sqs.CreateQueue( 'QueueName' => 'myCoolQueue',
70
+ # 'Attribute' => [
71
+ # { 'Name' => 'VisibilityTimeout', 'Value' => 40 },
72
+ # { 'Name' => 'MaximumMessageSize', 'Value' => 2048 } ])
73
+ # {"CreateQueueResponse"=>
74
+ # {"CreateQueueResult"=>
75
+ # {"QueueUrl"=>
76
+ # "https://sqs.us-east-1.amazonaws.com/826693181925/myCoolQueue1"},
77
+ # "ResponseMetadata"=>{"RequestId"=>"bf32f187-00e2-4327-8207-9aa6f786c654"},
78
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
79
+ #
80
+ # When Amazon API expects Queue to be a part of a path then put the name as first parameter:
81
+ #
82
+ # @example
83
+ # # sqs.GetQueueAttributes('myCoolQueue', 'AttributeName' => ['VisibilityTimeout', 'MaximumMessageSize', 'ApproximateNumberOfMessages']) #=>
84
+ # {"GetQueueAttributesResponse"=>
85
+ # {"@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/",
86
+ # "GetQueueAttributesResult"=>
87
+ # {"Attribute"=>
88
+ # [{"Name"=>"VisibilityTimeout", "Value"=>"40"},
89
+ # {"Name"=>"MaximumMessageSize", "Value"=>"2048"},
90
+ # {"Name"=>"ApproximateNumberOfMessages", "Value"=>"0"}]},
91
+ # "ResponseMetadata"=>{"RequestId"=>"f70ca08f-97d6-4787-856d-e447529c6a26"}}}
92
+ #
93
+ # @example
94
+ # # Send message (do not forget to escape it)
95
+ # message = 'A big brown dog jumped over the fox'
96
+ # sqs.SendMessage('myCoolQueue1', 'MessageBody' => URI::escape(message)) #=>
97
+ # {"SendMessageResponse"=>
98
+ # {"ResponseMetadata"=>{"RequestId"=>"df903a9d-8409-421d-9ca4-2ccdaf3a38b3"},
99
+ # "SendMessageResult"=>
100
+ # {"MessageId"=>"462df5b0-a7f9-40af-8951-b47ec664cfd9",
101
+ # "MD5OfMessageBody"=>"cf16267845abfaaa6297db494b2c90e8"},
102
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
103
+ #
104
+ # @example
105
+ # # Receive message (then unescape it when needed)
106
+ # sqs.ReceiveMessage('myCoolQueue') #=>
107
+ # {"ReceiveMessageResponse"=>
108
+ # {"ReceiveMessageResult"=>
109
+ # {"Message"=>
110
+ # {"ReceiptHandle"=>
111
+ # "Prl0vft3nRgHmktg983Id8/3NhzTWnxZAtOv0Jr3qdfKsqBR68Pl4basOMqgGO3jF2yeAcI4nKhmtDuS7jqOpBE7mbdwfiUFDn55yssPQWcaxxjGVWeu+p45YGxn2aqU6fh4OnTDebUWsBLCPSc9uf+cRuJOwodzeVVT1XUKYxlnwvZJa2qD17wfitoJp5F/lFy4yU0GaDP4VF5icb/AfzxYuO7kg0p9Cswf0pPkWYgV+BOe9Ri0GELw4YkTLMInHk93NtdcWtgM51zbmwDDhOQDIQdfkcKw1z9OdHsr1+4=",
112
+ # "Body"=>"A%20big%20brown%20dog%20jumped%20over%20the%20fox",
113
+ # "MD5OfBody"=>"a1bb5681fa24d4f437eeba5a1dd305c1",
114
+ # "MessageId"=>"71ba4c68-54c9-4ae2-a272-626a6905593b"}},
115
+ # "ResponseMetadata"=>{"RequestId"=>"c77ab769-ff74-4fdb-ab86-fb9219ab3e0c"},
116
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
117
+ #
118
+ # @example
119
+ # # Send message batch (Amazon way) ...
120
+ # sqs.SendMessageBatch('myCoolQueue',
121
+ # 'SendMessageBatchRequestEntry.1.Id' => 1,
122
+ # 'SendMessageBatchRequestEntry.1.DelaySeconds' => 300,
123
+ # 'SendMessageBatchRequestEntry.1.MessageBody' => CGI::escape('Hahaha!'),
124
+ # 'SendMessageBatchRequestEntry.2.Id' => 2,
125
+ # 'SendMessageBatchRequestEntry.2.DelaySeconds' => 310,
126
+ # 'SendMessageBatchRequestEntry.2.MessageBody' => CGI::escape('Hahaha!!'),
127
+ # 'SendMessageBatchRequestEntry.3.Id' => 3,
128
+ # 'SendMessageBatchRequestEntry.3.DelaySeconds' => 320,
129
+ # 'SendMessageBatchRequestEntry.3.MessageBody' => CGI::escape('Hahaha!!!'),
130
+ # 'SendMessageBatchRequestEntry.4.Id' => 4,
131
+ # 'SendMessageBatchRequestEntry.4.DelaySeconds' => 330,
132
+ # 'SendMessageBatchRequestEntry.4.MessageBody' => CGI::escape('Hahaha!!!!') )
133
+ #
134
+ # # ... or using CloudApi way:
135
+ # sqs.SendMessageBatch('myCoolQueue',
136
+ # 'SendMessageBatchRequestEntry' => [
137
+ # { 'Id' => 1, 'DelaySeconds' => 300, 'MessageBody' => CGI::escape('Hahaha!') },
138
+ # { 'Id' => 2, 'DelaySeconds' => 310, 'MessageBody' => CGI::escape('Hahaha!!') },
139
+ # { 'Id' => 3, 'DelaySeconds' => 320, 'MessageBody' => CGI::escape('Hahaha!!!') },
140
+ # { 'Id' => 4, 'DelaySeconds' => 330, 'MessageBody' => CGI::escape('Hahaha!!!!') } ] ) #=>
141
+ # {"SendMessageBatchResponse"=>
142
+ # {"SendMessageBatchResult"=>
143
+ # {"SendMessageBatchResultEntry"=>
144
+ # [{"MessageId"=>"8bc2891f-e2d6-4b92-9138-6fa7d2552e2d",
145
+ # "Id"=>"1",
146
+ # "MD5OfMessageBody"=>"c5bfc3f4240d74756238a1e390cc1391"},
147
+ # {"MessageId"=>"bc52eaf2-9f57-48c2-aa2d-7c3507bc306e",
148
+ # "Id"=>"2",
149
+ # "MD5OfMessageBody"=>"659355aa82149d1334942b5879da028e"},
150
+ # {"MessageId"=>"a7a14acd-b722-4146-be55-34167bb9dac8",
151
+ # "Id"=>"3",
152
+ # "MD5OfMessageBody"=>"faf2f2992906f2daf49f35c302dc3454"},
153
+ # {"MessageId"=>"cd443cd2-68a1-4456-b593-a964f336f12e",
154
+ # "Id"=>"4",
155
+ # "MD5OfMessageBody"=>"4033563a06b308f7366ca3d6bc7e3151"}]},
156
+ # "ResponseMetadata"=>{"RequestId"=>"7237d096-677d-4bc6-be44-7a1a313d18d6"},
157
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
158
+ #
159
+ # @example
160
+ # # Get queue attributes:
161
+ # sqs.GetQueueAttributes('myCoolQueue', 'AttributeName' => 'All') #=>
162
+ # {"GetQueueAttributesResponse"=>
163
+ # {"GetQueueAttributesResult"=>
164
+ # {"Attribute"=>
165
+ # [{"Name"=>"VisibilityTimeout", "Value"=>"40"},
166
+ # {"Name"=>"ApproximateNumberOfMessages", "Value"=>"7"},
167
+ # {"Name"=>"ApproximateNumberOfMessagesNotVisible", "Value"=>"0"},
168
+ # {"Name"=>"ApproximateNumberOfMessagesDelayed", "Value"=>"0"},
169
+ # {"Name"=>"CreatedTimestamp", "Value"=>"1322001625"},
170
+ # {"Name"=>"LastModifiedTimestamp", "Value"=>"1322001625"},
171
+ # {"Name"=>"QueueArn", "Value"=>"arn:aws:sqs:us-east-1:826693181925:myCoolQueue"},
172
+ # {"Name"=>"MaximumMessageSize", "Value"=>"2048"},
173
+ # {"Name"=>"MessageRetentionPeriod", "Value"=>"345600"},
174
+ # {"Name"=>"DelaySeconds", "Value"=>"0"}]},
175
+ # "ResponseMetadata"=>{"RequestId"=>"85b2d5f4-b63e-44bc-845c-14e4ae16cb9e"},
176
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
177
+ #
178
+ # @example
179
+ # # Delete queue:
180
+ # sqs.DeleteQueue('myCoolQueue1') #=>
181
+ # {"DeleteQueueResponse"=>
182
+ # {"ResponseMetadata"=>{"RequestId"=>"01de6439-6817-4308-8645-2a9430316e8a"},
183
+ # "@xmlns"=>"http://queue.amazonaws.com/doc/2011-10-01/"}}
184
+ #
185
+ # @see ApiManager
186
+ # @see http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference
187
+ #
188
+ class Manager < CloudApi::Manager
189
+ end
190
+
191
+
192
+ # Amazon Simple Queue Service (SQS) compatible manager (thread unsafe).
193
+ #
194
+ # @see Manager
195
+ #
196
+ class ApiManager < CloudApi::ApiManager
197
+
198
+ # SQS Error
199
+ class Error < CloudApi::Error
200
+ end
201
+
202
+ # Default API version for SQS service.
203
+ # To override the API version use :api_version key when instantiating a manager.
204
+ #
205
+ DEFAULT_API_VERSION = '2011-10-01'
206
+
207
+ set_routine CloudApi::RetryManager
208
+ set_routine CloudApi::RequestInitializer
209
+ set_routine AWS::RequestSigner
210
+ set_routine CloudApi::RequestGenerator
211
+ set_routine CloudApi::RequestAnalyzer
212
+ set_routine CloudApi::ConnectionProxy
213
+ set_routine CloudApi::ResponseAnalyzer
214
+ set_routine CloudApi::ResponseParser
215
+ set_routine CloudApi::ResultWrapper
216
+
217
+ error_pattern :abort_on_timeout, :path => /Action=Create/
218
+ error_pattern :retry, :response => /InternalError|Unavailable|ServiceUnavailable/i
219
+ error_pattern :disconnect_and_abort, :code => /5..|403|408/
220
+ error_pattern :disconnect_and_abort, :code => /4../, :if => Proc.new{ |opts| rand(100) < 10 }
221
+
222
+ set :response_error_parser => Parser::AWS::ResponseErrorV2
223
+
224
+
225
+ # Constructor
226
+ #
227
+ # @param [String] aws_access_key_id
228
+ # @param [String] aws_secret_access_key
229
+ # @param [String] aws_account_number
230
+ # @param [String] endpoint
231
+ # @param [Hash] options
232
+ #
233
+ # @see Manager
234
+ #
235
+ # @example
236
+ # # see Manager class
237
+ #
238
+ def initialize(aws_access_key_id, aws_secret_access_key, aws_account_number, endpoint, options={})
239
+ credentials = { :aws_account_number => aws_account_number,
240
+ :aws_access_key_id => aws_access_key_id,
241
+ :aws_secret_access_key => aws_secret_access_key }
242
+ super(credentials, endpoint, options)
243
+ end
244
+
245
+ # Makes an API call to AWS::Ec2 compatible cloud
246
+ #
247
+ # @param [String] action The action as Amazon names it in its docs.
248
+ #
249
+ # @return [Object]
250
+ #
251
+ # @example
252
+ # # Where opts may have next keys: :options, :headers, :body
253
+ # api(action, queue_name, opts={})
254
+ # api(action, opts={})
255
+ #
256
+ # @example
257
+ # sqs.api('ListQueues')
258
+ #
259
+ # @example
260
+ # sqs.api('SetQueueAttributes', 'myCoolQueue1', {'Attribute.?.Name' => 'Attribute.?.Value'}#
261
+ #
262
+ def api(action, *args)
263
+ queue_name = args.shift if args.first.is_a?(String)
264
+ opts = args.shift || {}
265
+ # Uri Parameters
266
+ opts['Action'] ||= action.to_s._snake_case._camelize
267
+ options = {}
268
+ options[:body] = opts.delete(:body)
269
+ options[:headers] = opts.delete(:headers) || {}
270
+ options[:options] = opts.delete(:options) || {}
271
+ options[:params] = parametrize(opts)
272
+ # Options and Per Queue URI
273
+ path = queue_name._blank? ? '' : "#{@credentials[:aws_account_number]}/#{queue_name}"
274
+ process_api_request(:get, path, options)
275
+ end
276
+
277
+
278
+ # Parametrize data to the format that Amazon EC2 and compatible services accept
279
+ #
280
+ # See {RightScale::CloudApi::Utils::AWS.parametrize} for more examples.
281
+ #
282
+ # @return [Hash] A hash of data in the format Amazon want to get.
283
+ #
284
+ # @example
285
+ # parametrize( 'ParamA' => 'a',
286
+ # 'ParamB' => ['b', 'c'],
287
+ # 'ParamC.?.Something' => ['d', 'e'],
288
+ # 'Filter' => [ { 'Key' => 'A', 'Value' => ['aa','ab']},
289
+ # { 'Key' => 'B', 'Value' => ['ba','bb']}] ) #=>
290
+ # {
291
+ # "Filter.1.Key" => "A",
292
+ # "Filter.1.Value.1" => "aa",
293
+ # "Filter.1.Value.2" => "ab",
294
+ # "Filter.2.Key" => "B",
295
+ # "Filter.2.Value.1" => "ba",
296
+ # "Filter.2.Value.2" => "bb",
297
+ # "ParamA" => "a",
298
+ # "ParamB.1" => "b",
299
+ # "ParamB.2" => "c",
300
+ # "ParamC.1.Something" => "d",
301
+ # "ParamC.2.Something" => "e"
302
+ # }
303
+ #
304
+ def parametrize(*args) # :nodoc:
305
+ Utils::AWS.parametrize(*args)
306
+ end
307
+
308
+
309
+ # @api public
310
+ alias_method :p9e, :parametrize
311
+
312
+
313
+ # Adds an ability to call SQS API methods by their names
314
+ #
315
+ # @return [Object]
316
+ #
317
+ # @example
318
+ # sqs.ListQueues
319
+ #
320
+ # @example
321
+ # sqs.SetQueueAttributes('myCoolQueue1', {'Attribute.?.Name' => 'Attribute.?.Value'})
322
+ #
323
+ def method_missing(method_name, *args, &block)
324
+ if method_name.to_s[/\A[A-Z]/]
325
+ api(method_name, *args, &block)
326
+ else
327
+ super
328
+ end
329
+ end
330
+
331
+ end
332
+ end
333
+ end
334
+ end
335
+ end