aws-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.yardopts +6 -0
  2. data/LICENSE.txt +171 -0
  3. data/NOTICE.txt +2 -0
  4. data/README.rdoc +189 -0
  5. data/lib/aws-sdk.rb +14 -0
  6. data/lib/aws.rb +63 -0
  7. data/lib/aws/api_config.rb +45 -0
  8. data/lib/aws/api_config/.document +0 -0
  9. data/lib/aws/api_config/EC2-2011-02-28.yml +2314 -0
  10. data/lib/aws/api_config/SNS-2010-03-31.yml +171 -0
  11. data/lib/aws/api_config/SQS-2009-02-01.yml +161 -0
  12. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +278 -0
  13. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +147 -0
  14. data/lib/aws/api_config_transform.rb +32 -0
  15. data/lib/aws/async_handle.rb +90 -0
  16. data/lib/aws/authorize_v2.rb +37 -0
  17. data/lib/aws/authorize_v3.rb +37 -0
  18. data/lib/aws/base_client.rb +524 -0
  19. data/lib/aws/cacheable.rb +92 -0
  20. data/lib/aws/common.rb +228 -0
  21. data/lib/aws/configurable.rb +36 -0
  22. data/lib/aws/configuration.rb +272 -0
  23. data/lib/aws/configured_client_methods.rb +81 -0
  24. data/lib/aws/configured_grammars.rb +65 -0
  25. data/lib/aws/configured_option_grammars.rb +46 -0
  26. data/lib/aws/configured_xml_grammars.rb +47 -0
  27. data/lib/aws/default_signer.rb +38 -0
  28. data/lib/aws/ec2.rb +321 -0
  29. data/lib/aws/ec2/attachment.rb +149 -0
  30. data/lib/aws/ec2/attachment_collection.rb +57 -0
  31. data/lib/aws/ec2/availability_zone.rb +80 -0
  32. data/lib/aws/ec2/availability_zone_collection.rb +47 -0
  33. data/lib/aws/ec2/block_device_mappings.rb +53 -0
  34. data/lib/aws/ec2/client.rb +54 -0
  35. data/lib/aws/ec2/client/xml.rb +127 -0
  36. data/lib/aws/ec2/collection.rb +39 -0
  37. data/lib/aws/ec2/config_transform.rb +63 -0
  38. data/lib/aws/ec2/elastic_ip.rb +107 -0
  39. data/lib/aws/ec2/elastic_ip_collection.rb +85 -0
  40. data/lib/aws/ec2/errors.rb +29 -0
  41. data/lib/aws/ec2/filtered_collection.rb +65 -0
  42. data/lib/aws/ec2/has_permissions.rb +46 -0
  43. data/lib/aws/ec2/image.rb +245 -0
  44. data/lib/aws/ec2/image_collection.rb +235 -0
  45. data/lib/aws/ec2/instance.rb +515 -0
  46. data/lib/aws/ec2/instance_collection.rb +276 -0
  47. data/lib/aws/ec2/key_pair.rb +86 -0
  48. data/lib/aws/ec2/key_pair_collection.rb +102 -0
  49. data/lib/aws/ec2/permission_collection.rb +177 -0
  50. data/lib/aws/ec2/region.rb +81 -0
  51. data/lib/aws/ec2/region_collection.rb +55 -0
  52. data/lib/aws/ec2/request.rb +27 -0
  53. data/lib/aws/ec2/reserved_instances.rb +50 -0
  54. data/lib/aws/ec2/reserved_instances_collection.rb +44 -0
  55. data/lib/aws/ec2/reserved_instances_offering.rb +55 -0
  56. data/lib/aws/ec2/reserved_instances_offering_collection.rb +43 -0
  57. data/lib/aws/ec2/resource.rb +340 -0
  58. data/lib/aws/ec2/resource_tag_collection.rb +218 -0
  59. data/lib/aws/ec2/security_group.rb +246 -0
  60. data/lib/aws/ec2/security_group/ip_permission.rb +70 -0
  61. data/lib/aws/ec2/security_group/ip_permission_collection.rb +59 -0
  62. data/lib/aws/ec2/security_group_collection.rb +132 -0
  63. data/lib/aws/ec2/snapshot.rb +138 -0
  64. data/lib/aws/ec2/snapshot_collection.rb +90 -0
  65. data/lib/aws/ec2/tag.rb +88 -0
  66. data/lib/aws/ec2/tag_collection.rb +114 -0
  67. data/lib/aws/ec2/tagged_collection.rb +48 -0
  68. data/lib/aws/ec2/tagged_item.rb +87 -0
  69. data/lib/aws/ec2/volume.rb +190 -0
  70. data/lib/aws/ec2/volume_collection.rb +95 -0
  71. data/lib/aws/errors.rb +129 -0
  72. data/lib/aws/http/builtin_handler.rb +69 -0
  73. data/lib/aws/http/curb_handler.rb +123 -0
  74. data/lib/aws/http/handler.rb +77 -0
  75. data/lib/aws/http/httparty_handler.rb +61 -0
  76. data/lib/aws/http/request.rb +136 -0
  77. data/lib/aws/http/request_param.rb +63 -0
  78. data/lib/aws/http/response.rb +75 -0
  79. data/lib/aws/ignore_result_element.rb +38 -0
  80. data/lib/aws/indifferent_hash.rb +86 -0
  81. data/lib/aws/inflection.rb +46 -0
  82. data/lib/aws/lazy_error_classes.rb +64 -0
  83. data/lib/aws/meta_utils.rb +43 -0
  84. data/lib/aws/model.rb +57 -0
  85. data/lib/aws/naming.rb +32 -0
  86. data/lib/aws/option_grammar.rb +544 -0
  87. data/lib/aws/policy.rb +912 -0
  88. data/lib/aws/rails.rb +209 -0
  89. data/lib/aws/record.rb +79 -0
  90. data/lib/aws/record/attribute.rb +94 -0
  91. data/lib/aws/record/attribute_macros.rb +288 -0
  92. data/lib/aws/record/attributes/boolean.rb +49 -0
  93. data/lib/aws/record/attributes/datetime.rb +86 -0
  94. data/lib/aws/record/attributes/float.rb +48 -0
  95. data/lib/aws/record/attributes/integer.rb +68 -0
  96. data/lib/aws/record/attributes/sortable_float.rb +60 -0
  97. data/lib/aws/record/attributes/sortable_integer.rb +95 -0
  98. data/lib/aws/record/attributes/string.rb +69 -0
  99. data/lib/aws/record/base.rb +728 -0
  100. data/lib/aws/record/conversion.rb +38 -0
  101. data/lib/aws/record/dirty_tracking.rb +286 -0
  102. data/lib/aws/record/errors.rb +153 -0
  103. data/lib/aws/record/exceptions.rb +48 -0
  104. data/lib/aws/record/finder_methods.rb +262 -0
  105. data/lib/aws/record/naming.rb +31 -0
  106. data/lib/aws/record/scope.rb +157 -0
  107. data/lib/aws/record/validations.rb +653 -0
  108. data/lib/aws/record/validator.rb +237 -0
  109. data/lib/aws/record/validators/acceptance.rb +51 -0
  110. data/lib/aws/record/validators/block.rb +38 -0
  111. data/lib/aws/record/validators/confirmation.rb +43 -0
  112. data/lib/aws/record/validators/count.rb +108 -0
  113. data/lib/aws/record/validators/exclusion.rb +43 -0
  114. data/lib/aws/record/validators/format.rb +57 -0
  115. data/lib/aws/record/validators/inclusion.rb +56 -0
  116. data/lib/aws/record/validators/length.rb +107 -0
  117. data/lib/aws/record/validators/numericality.rb +138 -0
  118. data/lib/aws/record/validators/presence.rb +45 -0
  119. data/lib/aws/resource_cache.rb +39 -0
  120. data/lib/aws/response.rb +113 -0
  121. data/lib/aws/response_cache.rb +50 -0
  122. data/lib/aws/s3.rb +109 -0
  123. data/lib/aws/s3/access_control_list.rb +252 -0
  124. data/lib/aws/s3/acl_object.rb +266 -0
  125. data/lib/aws/s3/bucket.rb +320 -0
  126. data/lib/aws/s3/bucket_collection.rb +122 -0
  127. data/lib/aws/s3/bucket_version_collection.rb +85 -0
  128. data/lib/aws/s3/client.rb +999 -0
  129. data/lib/aws/s3/client/xml.rb +190 -0
  130. data/lib/aws/s3/data_options.rb +99 -0
  131. data/lib/aws/s3/errors.rb +43 -0
  132. data/lib/aws/s3/multipart_upload.rb +318 -0
  133. data/lib/aws/s3/multipart_upload_collection.rb +78 -0
  134. data/lib/aws/s3/object_collection.rb +159 -0
  135. data/lib/aws/s3/object_metadata.rb +67 -0
  136. data/lib/aws/s3/object_upload_collection.rb +83 -0
  137. data/lib/aws/s3/object_version.rb +141 -0
  138. data/lib/aws/s3/object_version_collection.rb +78 -0
  139. data/lib/aws/s3/paginated_collection.rb +94 -0
  140. data/lib/aws/s3/policy.rb +76 -0
  141. data/lib/aws/s3/prefix_and_delimiter_collection.rb +56 -0
  142. data/lib/aws/s3/prefixed_collection.rb +84 -0
  143. data/lib/aws/s3/presigned_post.rb +504 -0
  144. data/lib/aws/s3/request.rb +198 -0
  145. data/lib/aws/s3/s3_object.rb +794 -0
  146. data/lib/aws/s3/tree.rb +116 -0
  147. data/lib/aws/s3/tree/branch_node.rb +71 -0
  148. data/lib/aws/s3/tree/child_collection.rb +108 -0
  149. data/lib/aws/s3/tree/leaf_node.rb +99 -0
  150. data/lib/aws/s3/tree/node.rb +22 -0
  151. data/lib/aws/s3/tree/parent.rb +90 -0
  152. data/lib/aws/s3/uploaded_part.rb +82 -0
  153. data/lib/aws/s3/uploaded_part_collection.rb +86 -0
  154. data/lib/aws/service_interface.rb +60 -0
  155. data/lib/aws/simple_db.rb +202 -0
  156. data/lib/aws/simple_db/attribute.rb +159 -0
  157. data/lib/aws/simple_db/attribute_collection.rb +227 -0
  158. data/lib/aws/simple_db/client.rb +52 -0
  159. data/lib/aws/simple_db/client/options.rb +34 -0
  160. data/lib/aws/simple_db/client/xml.rb +68 -0
  161. data/lib/aws/simple_db/consistent_read_option.rb +42 -0
  162. data/lib/aws/simple_db/delete_attributes.rb +64 -0
  163. data/lib/aws/simple_db/domain.rb +118 -0
  164. data/lib/aws/simple_db/domain_collection.rb +116 -0
  165. data/lib/aws/simple_db/domain_metadata.rb +112 -0
  166. data/lib/aws/simple_db/errors.rb +46 -0
  167. data/lib/aws/simple_db/expect_condition_option.rb +45 -0
  168. data/lib/aws/simple_db/item.rb +84 -0
  169. data/lib/aws/simple_db/item_collection.rb +594 -0
  170. data/lib/aws/simple_db/item_data.rb +70 -0
  171. data/lib/aws/simple_db/put_attributes.rb +62 -0
  172. data/lib/aws/simple_db/request.rb +27 -0
  173. data/lib/aws/simple_email_service.rb +373 -0
  174. data/lib/aws/simple_email_service/client.rb +39 -0
  175. data/lib/aws/simple_email_service/client/options.rb +24 -0
  176. data/lib/aws/simple_email_service/client/xml.rb +38 -0
  177. data/lib/aws/simple_email_service/email_address_collection.rb +66 -0
  178. data/lib/aws/simple_email_service/errors.rb +29 -0
  179. data/lib/aws/simple_email_service/quotas.rb +64 -0
  180. data/lib/aws/simple_email_service/request.rb +27 -0
  181. data/lib/aws/sns.rb +69 -0
  182. data/lib/aws/sns/client.rb +37 -0
  183. data/lib/aws/sns/client/options.rb +24 -0
  184. data/lib/aws/sns/client/xml.rb +38 -0
  185. data/lib/aws/sns/errors.rb +29 -0
  186. data/lib/aws/sns/policy.rb +49 -0
  187. data/lib/aws/sns/request.rb +27 -0
  188. data/lib/aws/sns/subscription.rb +100 -0
  189. data/lib/aws/sns/subscription_collection.rb +84 -0
  190. data/lib/aws/sns/topic.rb +384 -0
  191. data/lib/aws/sns/topic_collection.rb +70 -0
  192. data/lib/aws/sns/topic_subscription_collection.rb +58 -0
  193. data/lib/aws/sqs.rb +70 -0
  194. data/lib/aws/sqs/client.rb +38 -0
  195. data/lib/aws/sqs/client/xml.rb +36 -0
  196. data/lib/aws/sqs/errors.rb +33 -0
  197. data/lib/aws/sqs/policy.rb +50 -0
  198. data/lib/aws/sqs/queue.rb +507 -0
  199. data/lib/aws/sqs/queue_collection.rb +105 -0
  200. data/lib/aws/sqs/received_message.rb +184 -0
  201. data/lib/aws/sqs/received_sns_message.rb +112 -0
  202. data/lib/aws/sqs/request.rb +44 -0
  203. data/lib/aws/xml_grammar.rb +923 -0
  204. data/rails/init.rb +15 -0
  205. metadata +298 -0
@@ -0,0 +1,69 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'net/http'
15
+ require 'net/https'
16
+
17
+ module AWS
18
+ module Http
19
+
20
+ # @private
21
+ class BuiltinHandler
22
+
23
+ def handle(request, response)
24
+
25
+ http = Net::HTTP.new(request.host, request.use_ssl? ? 443 : 80)
26
+
27
+ # http://www.ruby-lang.org/en/news/2007/10/04/net-https-vulnerability/
28
+ if request.use_ssl?
29
+ http.use_ssl = true
30
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
31
+ store = OpenSSL::X509::Store.new
32
+ store.set_default_paths
33
+ http.cert_store = store
34
+ end
35
+
36
+ http.start do
37
+
38
+ # Net::HTTP adds this header for us when the body is
39
+ # provided, but it messes up signing
40
+ headers = { 'content-type' => '' }
41
+
42
+ # Net::HTTP calls strip on each header value, this causes errors
43
+ # when the values are numbers (like Content-Length)
44
+ request.headers.each_pair do |key,value|
45
+ headers[key] = value.to_s
46
+ end
47
+
48
+ http_request_class = case request.http_method
49
+ when 'HEAD' then Net::HTTP::Head
50
+ when 'GET' then Net::HTTP::Get
51
+ when 'PUT' then Net::HTTP::Put
52
+ when 'POST' then Net::HTTP::Post
53
+ when 'DELETE' then Net::HTTP::Delete
54
+ else raise "unsupported http request method: #{request.http_method}"
55
+ end
56
+
57
+ http_request = http_request_class.new(request.uri, headers)
58
+ http.request(http_request, request.body) do |http_response|
59
+ response.body = http_response.body
60
+ response.status = http_response.code.to_i
61
+ response.headers = http_response.to_hash
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,123 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'thread'
15
+
16
+ module AWS
17
+ module Http
18
+
19
+ # @private
20
+ class CurbHandler
21
+
22
+ def initialize
23
+ @q = []
24
+ @sem = Mutex.new
25
+ @multi = Curl::Multi.new
26
+
27
+ start_processor
28
+ end
29
+
30
+ def handle request, response
31
+ raise "unsupport http reqest method: #{request.http_method}" unless
32
+ ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'].include? request.http_method
33
+ @sem.synchronize do
34
+ @q << [request, response, Thread.current]
35
+ @processor.wakeup
36
+ end
37
+ Thread.stop
38
+ nil
39
+ end
40
+
41
+ # fills the Curl::Multi handle with the given array of queue
42
+ # items, calling make_easy_handle on each one first
43
+ private
44
+ def fill_multi(items)
45
+ items.each do |item|
46
+ c = make_easy_handle(*item)
47
+ @multi.add(c)
48
+ end
49
+ end
50
+
51
+ # starts a background thread that waits for new items and
52
+ # sends them through the Curl::Multi handle
53
+ private
54
+ def start_processor
55
+ @processor = Thread.new do
56
+ loop do
57
+ items = nil
58
+ @sem.synchronize do
59
+ items = @q.slice!(0..-1)
60
+ end
61
+ unless items.empty?
62
+ fill_multi(items)
63
+ @multi.perform do
64
+ # curl is idle, so process more items if we can get them
65
+ # without blocking
66
+ if !@q.empty? && @sem.try_lock
67
+ begin
68
+ fill_multi(@q.slice!(0..-1))
69
+ ensure
70
+ @sem.unlock
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ # wait for a new item to show up before continuing
77
+ Thread.stop if @q.empty?
78
+ end
79
+ end
80
+ end
81
+
82
+ private
83
+ def make_easy_handle request, response, thread = nil
84
+
85
+ url = request.use_ssl? ?
86
+ "https://#{request.host}:443#{request.uri}" :
87
+ "http://#{request.host}#{request.uri}"
88
+ puts url
89
+
90
+ curl = Curl::Easy.new(url)
91
+ curl.headers = request.headers
92
+
93
+ curl.on_header {|header_data|
94
+ name, value = header_data.strip.split(/:\s+/, 2)
95
+ response.headers[name] = value
96
+ header_data.length
97
+ }
98
+
99
+ case request.http_method
100
+ when 'GET'
101
+ # ....
102
+ when 'HEAD'
103
+ curl.head = true
104
+ when 'PUT'
105
+ curl.put_data = request.body
106
+ when 'POST'
107
+ curl.post_body = request.body
108
+ when 'DELETE'
109
+ curl.delete = true
110
+ end
111
+
112
+ curl.on_complete do
113
+ response.body = curl.body_str
114
+ response.status = curl.response_code
115
+ thread.run if thread
116
+ end
117
+
118
+ curl
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,77 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'aws/meta_utils'
15
+
16
+ module AWS
17
+ module Http
18
+
19
+ # @private
20
+ class Handler
21
+
22
+ attr_reader :base
23
+
24
+ def initialize(base, &block)
25
+ @base = base
26
+ if base.respond_to?(:handle)
27
+
28
+ unless block.arity == 2
29
+ raise ArgumentError, 'passed block must accept 2 arguments'
30
+ end
31
+ MetaUtils.extend_method(self, :handle, &block)
32
+
33
+ elsif base.respond_to?(:handle_async)
34
+
35
+ unless block.arity == 3
36
+ raise ArgumentError, 'passed block must accept 3 arguments'
37
+ end
38
+
39
+ MetaUtils.extend_method(self, :handle_async) do |req, resp, handle|
40
+ @base.handle_async(req, resp, handle)
41
+ end
42
+ MetaUtils.extend(self) do
43
+ define_method(:handle) do |req, resp|
44
+ raise "attempted to call #handle on an async handler"
45
+ end
46
+ define_method(:handle_async, &block)
47
+ end
48
+
49
+ else
50
+ raise ArgumentError, 'base must respond to #handle or #handle_async'
51
+ end
52
+ end
53
+
54
+ def handle(request, http_response)
55
+ @base.handle(request, http_response)
56
+ end
57
+
58
+ def handle_async(request, http_response, handle)
59
+ Thread.new do
60
+ begin
61
+ self.handle(request, http_response)
62
+ rescue => e
63
+ handle.signal_failure
64
+ else
65
+ handle.signal_success
66
+ end
67
+ end
68
+ end
69
+
70
+ def sleep_with_callback seconds, &block
71
+ Kernel.sleep(seconds)
72
+ yield
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'httparty'
15
+
16
+ module AWS
17
+ module Http
18
+
19
+ # @private
20
+ class HTTPartyHandler
21
+
22
+ include HTTParty
23
+
24
+ class NoOpParser < HTTParty::Parser
25
+ SupportedFormats = {}
26
+ end
27
+
28
+ def handle(request, response)
29
+
30
+ url = request.use_ssl? ?
31
+ "https://#{request.host}:443#{request.uri}" :
32
+ "http://#{request.host}#{request.uri}"
33
+
34
+ # get, post, put, delete, head
35
+ method = request.http_method.downcase
36
+
37
+ # Net::HTTP adds this header for us when the body is
38
+ # provided, but it messes up signing
39
+ headers = { 'content-type' => '' }
40
+
41
+ # headers must have string values (net http calls .strip on them)
42
+ request.headers.each_pair do |key,value|
43
+ headers[key] = value.to_s
44
+ end
45
+
46
+ begin
47
+ http_response = self.class.send(method, url,
48
+ :headers => headers,
49
+ :body => request.body,
50
+ :parser => NoOpParser)
51
+ rescue Timeout::Error => e
52
+ response.timeout = true
53
+ else
54
+ response.body = http_response.body
55
+ response.status = http_response.code.to_i
56
+ response.headers = http_response.to_hash
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,136 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'stringio'
15
+ require 'aws/http/request_param'
16
+
17
+ module AWS
18
+ module Http
19
+
20
+ # Base class for all service reqeusts.
21
+ # @private
22
+ class Request
23
+
24
+ # Returns a new empty http request object.
25
+ def initialize
26
+ @host = nil
27
+ @http_method = 'POST'
28
+ @path = '/'
29
+ @headers = CaseInsensitiveHash.new
30
+ @params = []
31
+ @use_ssl = true
32
+ end
33
+
34
+ # @return [String] hostname of the request
35
+ attr_accessor :host
36
+
37
+ # @return [CaseInsensitiveHash] request headers
38
+ attr_reader :headers
39
+
40
+ # @return [Array] An array of request params, each param responds to
41
+ # #name and #value.
42
+ attr_reader :params
43
+
44
+ # @return [String] GET, PUT POST, HEAD or DELETE, defaults to POST
45
+ attr_accessor :http_method
46
+
47
+ # @return [String] path of the request URI, defaults to /
48
+ attr_reader :path
49
+
50
+ # @return [String] the AWS access key ID used to authorize the
51
+ # request
52
+ attr_accessor :access_key_id
53
+
54
+ # @param [Boolean] ssl If the request should be sent over ssl or not.
55
+ def use_ssl= use_ssl
56
+ @use_ssl = use_ssl
57
+ end
58
+
59
+ # @return [Boolean] If this request should be sent over ssl or not.
60
+ def use_ssl?
61
+ @use_ssl
62
+ end
63
+
64
+ # Adds a request param.
65
+ #
66
+ # @overload add_param(param_name, param_value = nil)
67
+ # Add a param (name/value)
68
+ # @param [String] param_name
69
+ # @param [String] param_value Leave blank for sub resources
70
+ #
71
+ # @overload add_param(param_obj)
72
+ # Add a param (object)
73
+ # @param [Param] param_obj
74
+ #
75
+ def add_param name_or_param, value = nil
76
+ if name_or_param.kind_of?(Param)
77
+ @params << name_or_param
78
+ else
79
+ @params << Param.new(name_or_param, value)
80
+ end
81
+ end
82
+
83
+ # @private
84
+ def get_param param_name
85
+ @params.detect{|p| p.name == param_name } ||
86
+ raise("undefined param #{param_name}")
87
+ end
88
+
89
+ # @return [String] the request uri
90
+ def uri
91
+ querystring ? "#{path}?#{querystring}" : path
92
+ end
93
+
94
+ # @return [String] Returns the request params url encoded, or nil if
95
+ # this request has no params.
96
+ def url_encoded_params
97
+ if @params.empty?
98
+ nil
99
+ else
100
+ @params.sort.collect{|p| p.encoded }.join('&')
101
+ end
102
+ end
103
+
104
+ # @return [String, nil] Returns the requesty querystring.
105
+ def querystring
106
+ nil
107
+ end
108
+
109
+ # @return [String, nil] Returns the request body.
110
+ def body
111
+ url_encoded_params
112
+ end
113
+
114
+ # @private
115
+ class CaseInsensitiveHash < Hash
116
+
117
+ def []= key, value
118
+ super(key.to_s.downcase, value)
119
+ end
120
+
121
+ def [] key
122
+ super(key.to_s.downcase)
123
+ end
124
+
125
+ def has_key?(key)
126
+ super(key.to_s.downcase)
127
+ end
128
+ alias_method :key?, :has_key?
129
+ alias_method :include?, :has_key?
130
+ alias_method :member?, :has_key?
131
+
132
+ end
133
+
134
+ end
135
+ end
136
+ end