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,118 @@
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/errors'
15
+ require 'aws/model'
16
+ require 'aws/simple_db/domain_metadata'
17
+ require 'aws/simple_db/item_collection'
18
+
19
+ module AWS
20
+ class SimpleDB
21
+
22
+ # Represents a domain in SimpleDB.
23
+ #
24
+ # Domains, like database tables, must exist before you can write to one.
25
+ #
26
+ # @example Creating a domain
27
+ # domain = SimpleDB.new.domains.create('mydomain')
28
+ #
29
+ # @example Getting a domain
30
+ # domain = SimpleDB.new.domains['mydomain']
31
+ #
32
+ # @see DomainCollection
33
+ #
34
+ class Domain
35
+
36
+ # @private
37
+ class NonEmptyDeleteError < StandardError; end
38
+
39
+ include Model
40
+
41
+ # @param [String] The name of a SimpleDB domain to reference.
42
+ def initialize(name, options = {})
43
+ super(options)
44
+ @name = name
45
+ end
46
+
47
+ # Returns the name for this domain.
48
+ #
49
+ # @return [String] The name of this domain.
50
+ attr_reader :name
51
+
52
+ # Returns true if the domain has no items, false otherwise.
53
+ #
54
+ # @return [Boolean] Returns true if the domain has no items.
55
+ def empty?
56
+ metadata.item_count == 0
57
+ end
58
+
59
+ # Deletes the (empty) domain.
60
+ #
61
+ # @note If you need to delete a domain with items, call {#delete!}
62
+ # @raise [NonEmptyDeleteError] Raises if the domain is not empty.
63
+ # @return [nil]
64
+ def delete
65
+ unless empty?
66
+ raise NonEmptyDeleteError, "delete called without :force " +
67
+ "on a non-empty domain"
68
+ end
69
+ client.delete_domain(:domain_name => name)
70
+ nil
71
+ end
72
+
73
+ # Deletes the domain and all of its items.
74
+ #
75
+ # @return [nil]
76
+ def delete!
77
+ client.delete_domain(:domain_name => name)
78
+ nil
79
+ end
80
+
81
+ # Returns true if this domain exists, false otherwise.
82
+ #
83
+ # @return [Boolean] Returns true if the domain exists.
84
+ def exists?
85
+ begin
86
+ client.domain_metadata(:domain_name => name)
87
+ true
88
+ rescue Errors::NoSuchDomain
89
+ false
90
+ end
91
+ end
92
+
93
+ # Returns a metadata object that can provide information about
94
+ # this domain.
95
+ #
96
+ # @return [DomainMetadata]
97
+ def metadata
98
+ DomainMetadata.new(self)
99
+ end
100
+
101
+ # Returns a collection that represents all of the items in this domain.
102
+ #
103
+ # @return [ItemCollection]
104
+ def items
105
+ ItemCollection.new(self)
106
+ end
107
+
108
+ # An irb-friendly string representation of this object.
109
+ #
110
+ # @return [String]
111
+ # @private
112
+ def inspect
113
+ "#<#{self.class}:#{name}>"
114
+ end
115
+
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,116 @@
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/model'
15
+ require 'aws/simple_db/domain'
16
+
17
+ module AWS
18
+ class SimpleDB
19
+
20
+ # An Enumerable collection representing all your domains in SimpleDB.
21
+ #
22
+ # Use a DomainCollection to create, get and list domains.
23
+ #
24
+ # @example Creating a domain in SimpleDB
25
+ #
26
+ # sdb = SimpleDB.new
27
+ # domain = sdb.domains.create('mydomain')
28
+ #
29
+ # @example Getting a domain with indifferent access
30
+ #
31
+ # domain = sdb.domains[:mydomain]
32
+ # domain = sdb.domains['mydomain']
33
+ #
34
+ # @example Enumerating domains
35
+ #
36
+ # sdb.domains.each do |domain|
37
+ # puts domain.name
38
+ # end
39
+ #
40
+ class DomainCollection
41
+
42
+ include Model
43
+ include Enumerable
44
+
45
+ # Creates a domain in SimpleDB and returns a domain object.
46
+ #
47
+ # @note This operation might take 10 or more seconds to complete.
48
+ # @note Creating a domain in SimpleDB is an idempotent operation;
49
+ # running it multiple times using the same domain name will not
50
+ # result in an error.
51
+ # @note You can create up to 100 domains per account.
52
+ # @param [String] domain_name
53
+ # @return [Domain] Returns a new domain with the given name.
54
+ def create(domain_name)
55
+ client.create_domain(:domain_name => domain_name)
56
+ domain_named(domain_name)
57
+ end
58
+
59
+ # Returns a domain object with the given name.
60
+ #
61
+ # @note This does not attempt to create the domain if it does not
62
+ # already exist in SimpleDB. Use {#create} to add a domain to SDB.
63
+ #
64
+ # @param [String] domain_name The name of the domain to return.
65
+ # @return [Domain] Returns the domain with the given name.
66
+ def [] domain_name
67
+ domain_named(domain_name)
68
+ end
69
+
70
+ # @note Normally your account has a limit of 100 SimpleDB domains. You can {request more here}[http://aws.amazon.com/contact-us/simpledb-limit-request/]
71
+ # @yield [domain] Yields once for every domain in your account.
72
+ # @yieldparam [Domain] domain
73
+ # @param [Hash] options
74
+ # @option options [Integer] :limit (nil) The maximum number of
75
+ # domains to yield.
76
+ # @option options [Integer] :batch_size (100) The number of domains to
77
+ # fetch each request to SimpleDB. Maximum is 100.
78
+ # @return [nil]
79
+ def each options = {}, &block
80
+
81
+ total_limit = options[:limit]
82
+ batch_size = options[:batch_size] || 100
83
+ received = 0
84
+ next_token = nil
85
+
86
+ begin
87
+
88
+ limit = total_limit ?
89
+ [total_limit - received, batch_size].min :
90
+ batch_size
91
+
92
+ list_options = { :limit => limit }
93
+ list_options[:next_token] = next_token if next_token
94
+ list = client.list_domains(list_options)
95
+
96
+ next_token = list.next_token
97
+ received += list.domain_names.length
98
+
99
+ list.domain_names.each do |name|
100
+ yield(domain_named(name))
101
+ end
102
+
103
+ end while next_token and (total_limit.nil? or received < total_limit)
104
+ nil
105
+ end
106
+
107
+ # @return [Domain] Returns a domain with the given name.
108
+ # @private
109
+ protected
110
+ def domain_named name
111
+ Domain.new(name.to_s, :config => config)
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,112 @@
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/model'
15
+
16
+ module AWS
17
+ class SimpleDB
18
+
19
+ # SimpleDB can report on the amount of data stored in a domain,
20
+ # the number of items, etc.
21
+ #
22
+ # @example
23
+ #
24
+ # sdb = SimpleDB.new
25
+ # sdb.domains['mydomain'].metadata.to_h
26
+ #
27
+ # # the hash returned above might look like:
28
+ # {
29
+ # :timestamp => 1300841880,
30
+ # :attribute_names_size_bytes => 12,
31
+ # :item_count => 1,
32
+ # :attribute_value_count => 6,
33
+ # :attribute_values_size_bytes => 25,
34
+ # :item_names_size_bytes => 3,
35
+ # :attribute_name_count => 3
36
+ # }
37
+ #
38
+ class DomainMetadata
39
+
40
+ include Model
41
+
42
+ # @private
43
+ ATTRIBUTES = [
44
+ :item_count,
45
+ :item_names_size_bytes,
46
+ :attribute_name_count,
47
+ :attribute_names_size_bytes,
48
+ :attribute_value_count,
49
+ :attribute_values_size_bytes,
50
+ :timestamp,
51
+ ]
52
+
53
+ # @param [Domain] The domain to fetch metadata for.
54
+ # @return [DomainMetadata]
55
+ def initialize domain, options = {}
56
+ @domain = domain
57
+ super
58
+ end
59
+
60
+ # @return [Domain] The domain this metadata is describing.
61
+ attr_reader :domain
62
+
63
+ # @return [Integer] The number of all items in the {#domain}.
64
+ def item_count
65
+ self.to_h[:item_count]
66
+ end
67
+
68
+ # @return [Integer] The total size of all item names in the {#domain},
69
+ # in bytes.
70
+ def item_names_size_bytes
71
+ self.to_h[:item_names_size_bytes]
72
+ end
73
+
74
+ # @return [Integer] The number of unique attribute names in the
75
+ # {#domain}.
76
+ def attribute_name_count
77
+ self.to_h[:attribute_name_count]
78
+ end
79
+
80
+ # @return [Integer] The total size of all unique attribute names,
81
+ # in bytes.
82
+ def attribute_names_size_bytes
83
+ self.to_h[:attribute_names_size_bytes]
84
+ end
85
+
86
+ # @return [Integer] The number of all attribute name/value pairs in
87
+ # the {#domain}.
88
+ def attribute_value_count
89
+ self.to_h[:attribute_value_count]
90
+ end
91
+
92
+ # @return [Integer] The total size of all attribute values, in bytes.
93
+ def attribute_values_size_bytes
94
+ self.to_h[:attribute_values_size_bytes]
95
+ end
96
+
97
+ # @return [Integer] The data and time when metadata was calculated
98
+ # in Epoch (UNIX) time.
99
+ def timestamp
100
+ self.to_h[:timestamp]
101
+ end
102
+
103
+ # @return [Hash] A hash of all of the metadata attributes for
104
+ # this {#domain}.
105
+ def to_h
106
+ meta = client.domain_metadata(:domain_name => domain.name)
107
+ ATTRIBUTES.inject({}) {|h,attr| h[attr] = meta.send(attr); h }
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,46 @@
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/lazy_error_classes'
15
+ require 'aws/simple_db/client/xml'
16
+
17
+ module AWS
18
+ class SimpleDB
19
+
20
+ # This module contains exception classes for each of the error
21
+ # types that SimpleDB can return. You can use these classes to
22
+ # rescue specific errors, for example:
23
+ #
24
+ # begin
25
+ # SimpleDB.new.domains.mydomain.
26
+ # items["foo"].attributes.set(:color => "red")
27
+ # rescue SimpleDB::Errors::NoSuchDomain => e
28
+ # SimpleDB.new.domians.create("mydomain")
29
+ # retry
30
+ # end
31
+ #
32
+ # Each exception has:
33
+ #
34
+ # * +code+: returns the error code as a string.
35
+ # * +box_usage+: returns the box usage for the operation.
36
+ #
37
+ # All errors raised as a result of error responses from the
38
+ # service are instances of either {ClientError} or {ServerError}.
39
+ # @private
40
+ module Errors
41
+ BASE_ERROR_GRAMMAR = Client::XML::BaseError
42
+ include LazyErrorClasses
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,45 @@
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
+ # @private
18
+ module ExpectConditionOption
19
+
20
+ # @private
21
+ protected
22
+ def expect_condition_opts(opts)
23
+ expected = []
24
+ opts.each do |name, value|
25
+ case name
26
+ when :if
27
+ (expected_name, expected_value) = value.to_a.first
28
+ expected << {
29
+ :name => expected_name.to_s,
30
+ :value => expected_value
31
+ }
32
+ when :unless
33
+ expected << {
34
+ :name => value.to_s,
35
+ :exists => false
36
+ }
37
+ end
38
+ end
39
+ expected
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,84 @@
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/model'
15
+ require 'aws/simple_db/item_data'
16
+ require 'aws/simple_db/attribute_collection'
17
+ require 'aws/simple_db/expect_condition_option'
18
+ require 'aws/simple_db/consistent_read_option'
19
+
20
+ module AWS
21
+ class SimpleDB
22
+
23
+ # Represents a single item in a SimpleDB domain. You can use
24
+ # this class to delete the item or get its data. You can also
25
+ # use it to access the {AttributeCollection} for the item in
26
+ # order to add, remove, or read the item's attributes.
27
+ #
28
+ # item = AWS::SimpleDB.new.domains['mydomain'].items['item-id']
29
+ #
30
+ class Item
31
+
32
+ include Model
33
+ include ExpectConditionOption
34
+ include ConsistentReadOption
35
+
36
+ # @param [Domain] domain The domain the item belongs to
37
+ # @param [String] name The name of the item in SimpleDB.
38
+ # @param [Hash] options
39
+ def initialize domain, name, options = {}
40
+ @domain = domain
41
+ @name = name
42
+ super
43
+ end
44
+
45
+ # @return [Domain] The domain this item belongs to.
46
+ attr_reader :domain
47
+
48
+ # @return [String] The item name.
49
+ attr_reader :name
50
+
51
+ # @return [AttributeCollection] A collection representing all attributes
52
+ # for this item.
53
+ def attributes
54
+ AttributeCollection.new(self)
55
+ end
56
+
57
+ # Deletes the item and all of its attributes from SimpleDB.
58
+ # @return [nil]
59
+ def delete options = {}
60
+ delete_opts = {}
61
+ delete_opts[:domain_name] = domain.name
62
+ delete_opts[:item_name] = name
63
+ delete_opts[:expected] = expect_condition_opts(options)
64
+ delete_opts.delete(:expected) if delete_opts[:expected].empty?
65
+ client.delete_attributes(delete_opts)
66
+ nil
67
+ end
68
+
69
+ # Returns all of the item's attributes in an {ItemData} instance.
70
+ # @return [ItemData] An object with all of the loaded attribute names
71
+ # and values for this item.
72
+ def data options = {}
73
+ get_opts = {}
74
+ get_opts[:domain_name] = domain.name
75
+ get_opts[:item_name] = name
76
+ get_opts[:consistent_read] = consistent_read(options)
77
+ r = client.get_attributes(get_opts)
78
+ ItemData.new(:name => name, :domain => domain, :response_object => r)
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end