aws-sdk 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.
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,70 @@
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
+ module AWS
15
+ class SimpleDB
16
+
17
+ # Holds the data for a SimpleDB item. While {Item} only proxies
18
+ # requests to return data, this class actually stores data
19
+ # returned by a query. For example, you can use this to get the
20
+ # list of items whose titles are palindromes using only a single
21
+ # request to SimpleDB (not counting pagination):
22
+ #
23
+ # items.enum_for(:select).
24
+ # select { |data| data.title == data.title.to_s.reverse }.
25
+ # map { |data| data.item }
26
+ #
27
+ # The {ItemCollection#select} call yields instances of ItemData,
28
+ # and the +map+ call in the example above gets the list of
29
+ # corresponding {Item} instances.
30
+ class ItemData
31
+
32
+ # @private
33
+ def initialize(opts = {})
34
+ @name = opts[:name]
35
+ @attributes = opts[:attributes]
36
+ @domain = opts[:domain]
37
+
38
+ if obj = opts[:response_object]
39
+ @name ||= obj.name if obj.respond_to?(:name)
40
+ if obj.respond_to?(:attributes)
41
+ @attributes ||= obj.attributes.inject({}) do |m, att|
42
+ m[att.name] ||= []
43
+ m[att.name] << att.value
44
+ m
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # @return [String] The item name.
51
+ attr_reader :name
52
+
53
+ # @return [Hash] A hash of attribute names to arrays of values.
54
+ attr_reader :attributes
55
+
56
+ # @return [Domain] The domain from which the item data was retrieved.
57
+ attr_reader :domain
58
+
59
+ # Returns the {Item} corresponding to this ItemData; you can
60
+ # use this to perform further operations on the item, or to
61
+ # fetch its most recent data.
62
+ # @return [Item] The item this data belongs to.
63
+ def item
64
+ domain[name]
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,62 @@
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/simple_db/expect_condition_option'
15
+
16
+ module AWS
17
+ class SimpleDB
18
+
19
+ # @private
20
+ module PutAttributes
21
+
22
+ include ExpectConditionOption
23
+
24
+ # Given a single hash of attribute names to values, returns a list
25
+ # of hashes suitable for the put_attributes :attributes option.
26
+ # @private
27
+ protected
28
+ def attribute_hashes attributes, replace
29
+ attribute_hashes = []
30
+ attributes.each_pair do |attribute_name,values|
31
+ [values].flatten.each do |value|
32
+ attribute_hashes << {
33
+ :name => attribute_name.to_s,
34
+ :value => value.to_s,
35
+ :replace => replace,
36
+ } unless [:if, :unless].include?(attribute_name)
37
+ end
38
+ end
39
+ attribute_hashes
40
+ end
41
+
42
+ # @private
43
+ protected
44
+ def do_put attribute_hashes, expect_opts = {}
45
+ return nil if attribute_hashes.empty?
46
+
47
+ opts = {
48
+ :domain_name => item.domain.name,
49
+ :item_name => item.name,
50
+ :attributes => attribute_hashes,
51
+ :expected => expect_condition_opts(expect_opts)
52
+ }
53
+ opts.delete(:expected) if opts[:expected].empty?
54
+
55
+ client.put_attributes(opts)
56
+ nil
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,27 @@
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/http/request'
15
+ require 'aws/authorize_v2'
16
+
17
+ module AWS
18
+ class SimpleDB
19
+
20
+ # @private
21
+ class Request < AWS::Http::Request
22
+
23
+ include AuthorizeV2
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,373 @@
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/common'
15
+ require 'aws/service_interface'
16
+ require 'aws/simple_email_service/client'
17
+ require 'aws/simple_email_service/email_address_collection'
18
+ require 'aws/simple_email_service/quotas'
19
+
20
+ module AWS
21
+
22
+ # This class is the starting point for working with Amazon
23
+ # SimpleEmailService (SES).
24
+ #
25
+ # To use Amazon SimpleEmailService you must first
26
+ # {sign up here}[http://aws.amazon.com/ses/]
27
+ #
28
+ # For more information about Amazon SimpleEmailService:
29
+ #
30
+ # * {Amazon SimpleEmailService}[http://aws.amazon.com/ses/]
31
+ # * {Amazon SimpleEmailService Documentation}[http://aws.amazon.com/documentation/ses/]
32
+ #
33
+ # = Credentials
34
+ #
35
+ # You can setup default credentials for all AWS services via
36
+ # AWS.config:
37
+ #
38
+ # AWS.config(
39
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
40
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
41
+ #
42
+ # Or you can set them directly on the SimpleEmailService interface:
43
+ #
44
+ # ses = AWS::SimpleEmailService.new(
45
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
46
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
47
+ #
48
+ # = Rails
49
+ #
50
+ # If you want to use Amazon SimpleEmailService to send email from your
51
+ # Rails application you just need to do 2 things:
52
+ #
53
+ # 1. Configure your AWS credentials with {AWS.config}
54
+ # 2. Set SES as the delivery method:
55
+ #
56
+ # config.action_mailer.delivery_method = :amazon_ses
57
+ #
58
+ # This has only been tested with Rails 2.3 and Rails 3.0.
59
+ #
60
+ # = Email Addresses
61
+ #
62
+ # Until you have {requested production access}[http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/InitialSetup.Customer.html]
63
+ # you will only be able to send emails to and from verified email addresses.
64
+ # To verify an email address:
65
+ #
66
+ # ses.email_addresses.verify('youremailaddress@domain.com')
67
+ #
68
+ # AWS will send an email to the given email address. Follow the link in the
69
+ # email to verify the address.
70
+ #
71
+ # To explore the email addresses you have authorized:
72
+ #
73
+ # ses.email_addresses.each do |address|
74
+ # puts address
75
+ # end
76
+ #
77
+ # See {EmailAddressCollection} for more information on working with SES email
78
+ # addresses.
79
+ #
80
+ # = Sending Email
81
+ #
82
+ # To send a basic email you can use {#send_email}.
83
+ #
84
+ # ses.send_email(
85
+ # :subject => 'A Sample Email',
86
+ # :from => 'sender@domain.com',
87
+ # :to => 'receipient@domain.com',
88
+ # :body_text => 'Sample email text.',
89
+ # :body_html => '<h1>Sample Email</h1>')
90
+ #
91
+ # If you need to send email with attachments or have other special needs
92
+ # that send_email does not support you can use {#send_raw_email}.
93
+ #
94
+ # ses.send_raw_email(<<EMAIL)
95
+ # Subject: A Sample Email
96
+ # From: sender@domain.com
97
+ # To: receipient@domain.com
98
+ #
99
+ # Sample email text.
100
+ # EMAIL
101
+ #
102
+ # If you prefer, you can also set the sender and recipient in ruby
103
+ # when sending raw emails:
104
+ #
105
+ # ses.send_raw_email(<<EMAIL, :to => 'to@foo.com', :from => 'from@foo.com')
106
+ # Subject: A Sample Email
107
+ #
108
+ # Sample email text.
109
+ # EMAIL
110
+ #
111
+ # = Quotas
112
+ #
113
+ # Based on several factors, Amazon SES determines how much email you can
114
+ # send and how quickly you can send it. These sending limits are defined
115
+ # as follows:
116
+ #
117
+ # * +:max_send_rate+ — Maximum number of emails you can send per second.
118
+ # * +:max_24_hour_send+ - Maximum number of emails you can send in a
119
+ # 24-hour period.
120
+ #
121
+ # To get your current quotas (and how many emails you have sent in the last
122
+ # 24 hours):
123
+ #
124
+ # ses.quotas
125
+ # # => {:max_24_hour_send=>200, :max_send_rate=>1.0, :sent_last_24_hours=>22}
126
+ #
127
+ # = Statistics
128
+ #
129
+ # You can get statistics about individual emails:
130
+ #
131
+ # ses.statistics.each do |stats|
132
+ # puts "Sent: #{stats[:sent]}"
133
+ # puts "Delivery Attempts: #{stats[:delivery_attempts]}"
134
+ # puts "Rejects: #{stats[:rejects]}"
135
+ # puts "Bounces: #{stats[:bounces]}"
136
+ # puts "Complaints: #{stats[:complaints]}"
137
+ # end
138
+ #
139
+ class SimpleEmailService
140
+
141
+ include ServiceInterface
142
+
143
+ # @return [EmailAddressCollection] Returns a collection that represents
144
+ # all of the verified email addresses for your account.
145
+ def email_addresses
146
+ EmailAddressCollection.new(:config => config)
147
+ end
148
+
149
+ # Sends an email.
150
+ #
151
+ # ses.send_email(
152
+ # :subject => 'A Sample Email',
153
+ # :to => 'john@doe.com',
154
+ # :from => 'no@reply.com',
155
+ # :body_text => 'sample text ...',
156
+ # :body_html => '<p>sample text ...</p>')
157
+ #
158
+ # You can also pass multiple email addresses for the +:to+, +:cc+,
159
+ # +:bcc+ and +:reply_to+ options. Email addresses can also be
160
+ # formatted with names.
161
+ #
162
+ # ses.send_email(
163
+ # :subject => 'A Sample Email',
164
+ # :to => ['"John Doe" <john@doe.com>', '"Jane Doe" <jane@doe.com>'],
165
+ # :from => 'no@reply.com',
166
+ # :body_text => 'sample text ...')
167
+ #
168
+ # @param [Hash] options
169
+ # @option options [required,String] :subject The subject of the message.
170
+ # A short summary of the content, which will appear in the #
171
+ # recipient's inbox.
172
+ # @option options [required,String] :from The sender's email address.
173
+ # @option options [String,Array] :to The address(es) to send the email to.
174
+ # @option options [String,Array] :cc The address(es) to cc (carbon copy)
175
+ # the email to.
176
+ # @option options [String,Array] :bcc The address(es) to bcc (blind
177
+ # carbon copy) the email to.
178
+ # @option options [String,Array] :reply_to The reply-to email address(es)
179
+ # for the message. If the recipient replies to the message, each
180
+ # reply-to address will receive the reply.
181
+ # @option options [String] :return_path The email address to which
182
+ # bounce notifications are to be forwarded. If the message cannot be
183
+ # delivered to the recipient, then an error message will be returned
184
+ # from the recipient's ISP; this message will then be forwarded to
185
+ # the email address specified by the +:return_path+ option.
186
+ # @option options [String] :body_text The email text contents.
187
+ # You must provide +:body_text+, +:body_html+ or both.
188
+ # @option options [String] :body_html The email html contents.
189
+ # You must provide +:body_text+, +:body_html+ or both.
190
+ # @option options [String] :subject_charset The character set of the
191
+ # +:subject+ string. If the text must contain any other characters,
192
+ # then you must also specify the character set. Examples include
193
+ # UTF-8, ISO-8859-1, and Shift_JIS. Defaults to 7-bit ASCII.
194
+ # @option options [String] :body_text_charset The character set of the
195
+ # +:body_text+ string. If the text must contain any other characters,
196
+ # then you must also specify the character set. Examples include
197
+ # UTF-8, ISO-8859-1, and Shift_JIS. Defaults to 7-bit ASCII.
198
+ # @option options [String] :body_html_charset The character set of the
199
+ # +:body_html+ string. If the text must contain any other characters,
200
+ # then you must also specify the character set. Examples include
201
+ # UTF-8, ISO-8859-1, and Shift_JIS. Defaults to 7-bit ASCII.
202
+ # @option options [String] :body_html
203
+ # @return [nil]
204
+ def send_email options = {}
205
+
206
+ require_each(options, :subject, :from)
207
+ require_one_of(options, :to, :cc, :bcc)
208
+ require_one_of(options, :body_text, :body_html)
209
+
210
+ # these three options can be passed strings or arrays of strings,
211
+ # but the service requires them in a list (array)
212
+ [:to, :cc, :bcc, :reply_to].each do |key|
213
+ if options[key]
214
+ options[key] = [options[key]].flatten
215
+ end
216
+ end
217
+
218
+ accepted_options = {
219
+ :subject => %w(message subject data),
220
+ :subject_charset => %w(message subject charset),
221
+ :to => %w(destination to_addresses),
222
+ :cc => %w(destination cc_addresses),
223
+ :bcc => %w(destination bcc_addresses),
224
+ :from => %w(source),
225
+ :reply_to => %w(reply_to_addresses),
226
+ :return_path => %w(return_path),
227
+ :body_text => %w(message body text data),
228
+ :body_text_charset => %w(message body text charset),
229
+ :body_html => %w(message body html data),
230
+ :body_html_charset => %w(message body html charset),
231
+ }
232
+
233
+ client.send_email(nest_options(options, accepted_options))
234
+ nil
235
+
236
+ end
237
+
238
+ # Sends a raw email (email message, with header and content specified).
239
+ # Useful for sending multipart MIME emails. The raw text of the message
240
+ # must comply with Internet email standards; otherwise, the message
241
+ # cannot be sent.
242
+ #
243
+ # raw = <<-EMAIL
244
+ # Date: Wed, 1 Jun 2011 09:13:07 -0700
245
+ # Subject: A Sample Email
246
+ # From: "John Doe" <johndoe@domain.com>
247
+ # To: "Jane Doe" <janedoe@domain.com>
248
+ # Accept-Language: en-US
249
+ # Content-Language: en-US
250
+ # Content-Type: text/plain; charset="utf-8"
251
+ # Content-Transfer-Encoding: base64
252
+ # MIME-Version: 1.0
253
+ #
254
+ # c2FtcGxlIHRleHQNCg==
255
+ # EMAIL
256
+ #
257
+ # ses.send_raw_email(raw)
258
+ #
259
+ # Amazon SES has a limit on the total number of recipients per
260
+ # message: The combined number of To:, CC: and BCC: email addresses
261
+ # cannot exceed 50. If you need to send an email message to a larger
262
+ # audience, you can divide your recipient list into groups of 50 or
263
+ # fewer, and then call Amazon SES repeatedly to send the message to
264
+ # each group.
265
+ #
266
+ # @param [required, String] raw_message The raw text of the message.
267
+ # You can pass in any object whos #to_s returns a valid formatted
268
+ # email (e.g. ruby Mail gem). The raw message should:
269
+ # * Contain a header and a body, separated by a blank line
270
+ # * Contain all required internet email headers
271
+ # * Each part of a multipart MIME message must be formatted properly
272
+ # * MIME content types must be among those supported by Amazon SES.
273
+ # Refer to the Amazon SES Developer Guide for more details.
274
+ # * Use content that is base64-encoded, if MIME requires it
275
+ # @option options [String,Array] :to One or more email addresses to
276
+ # send the email to.
277
+ # @option options [String] :from The sender's email address.
278
+ # If you specify the :from option, then bounce notifications and
279
+ # complaints will be sent to this email address. This takes
280
+ # precedence over any Return-Path header that you might include in
281
+ # the +raw_message+.
282
+ # @return [nil]
283
+ def send_raw_email raw_message, options = {}
284
+
285
+ send_opts = {}
286
+ send_opts[:raw_message] = {}
287
+ send_opts[:raw_message][:data] = raw_message.to_s
288
+ send_opts[:source] = options[:from] if options[:from]
289
+ send_opts[:destinations] = [options[:to]].flatten if options[:to]
290
+
291
+ client.send_raw_email(send_opts)
292
+ nil
293
+
294
+ end
295
+
296
+ # for compatability with ActionMailer
297
+ alias_method :deliver, :send_raw_email
298
+ alias_method :deliver!, :send_raw_email
299
+
300
+ # @example
301
+ #
302
+ # ses.quotas
303
+ # # {:max_24_hour_send=>200, :max_send_rate=>1.0, :sent_last_24_hours=>22}
304
+ #
305
+ # @return [Hash] Returns a hash of SES quotas and limits.
306
+ def quotas
307
+ Quotas.new(:config => config).to_h
308
+ end
309
+
310
+ # Returns an array of email statistics. Each object in this array is a
311
+ # hash with the following keys:
312
+ #
313
+ # * +:delivery_attempts+
314
+ # * +:rejects+
315
+ # * +:bounces+
316
+ # * +:complaints+
317
+ # * +:timestamp+
318
+ #
319
+ # @return [Array of Hashes] An array of email statistic hashes.
320
+ def statistics
321
+ client.get_send_statistics.send_data_points.inject([]) do |stats, data|
322
+ stats << {
323
+ :sent => data.timestamp,
324
+ :delivery_attempts => data.delivery_attempts,
325
+ :rejects => data.rejects,
326
+ :bounces => data.bounces,
327
+ :complaints => data.complaints,
328
+ }
329
+ end
330
+ end
331
+
332
+ # @private
333
+ protected
334
+ def require_one_of options, *keys
335
+ unless keys.any?{|key| options[key] }
336
+ parts = keys.collect{|key| ":#{key}" }.join(', ')
337
+ raise ArgumentError, "you must provide at least one of #{parts}"
338
+ end
339
+ end
340
+
341
+ # @private
342
+ protected
343
+ def require_each options, *keys
344
+ keys.each do |key|
345
+ unless options[key]
346
+ raise ArgumentError, "missing required option :#{key}"
347
+ end
348
+ end
349
+ end
350
+
351
+ # @private
352
+ protected
353
+ def nest_options options, accepted_options
354
+
355
+ send_opts = {}
356
+ accepted_options.each_pair do |option, keys|
357
+ next unless options[option]
358
+ hash = send_opts
359
+ keys.collect{|k| k.to_sym }.each do |key|
360
+ hash[key] = {} unless hash[key]
361
+ if keys.last == key.to_s
362
+ hash[key] = options[option]
363
+ else
364
+ hash = hash[key]
365
+ end
366
+ end
367
+ end
368
+
369
+ send_opts
370
+ end
371
+
372
+ end
373
+ end