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,78 @@
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/s3/prefix_and_delimiter_collection'
16
+ require 'aws/s3/multipart_upload'
17
+ require 'aws/s3/s3_object'
18
+
19
+ module AWS
20
+ class S3
21
+
22
+ # Represents the uploads in progress for a bucket.
23
+ #
24
+ # @example Finding uploads by prefix
25
+ # bucket.multipart_uploads.with_prefix("photos/").
26
+ # map { |upload| upload.object.key }
27
+ # # => ["photos/1.jpg", "photos/2.jpg", ...]
28
+ #
29
+ # @example Browsing with a tree interface
30
+ # bucket.multipart_uploads.with_prefix("photos").as_tree.
31
+ # children.select(&:branch?).map(&:prefix)
32
+ # # => ["photos/2010", "photos/2011", ...]
33
+ #
34
+ # @see Tree
35
+ class MultipartUploadCollection
36
+
37
+ include Enumerable
38
+ include Model
39
+ include PrefixAndDelimiterCollection
40
+
41
+ # @return [Bucket] The bucket in which the uploads are taking
42
+ # place.
43
+ attr_reader :bucket
44
+
45
+ # @private
46
+ def initialize(bucket, opts = {})
47
+ @bucket = bucket
48
+ super
49
+ end
50
+
51
+ protected
52
+ def each_member_in_page(page, &block)
53
+ super
54
+ page.uploads.each do |u|
55
+ object = S3Object.new(bucket, u.key)
56
+ upload = MultipartUpload.new(object, u.upload_id)
57
+ yield(upload)
58
+ end
59
+ end
60
+
61
+ protected
62
+ def list_request(options)
63
+ client.list_multipart_uploads(options)
64
+ end
65
+
66
+ protected
67
+ def limit_param; :max_uploads; end
68
+
69
+ protected
70
+ def pagination_markers; super + [:upload_id_marker]; end
71
+
72
+ protected
73
+ def page_size(resp); super + resp.uploads.size; end
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,159 @@
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/s3/s3_object'
16
+ require 'aws/s3/prefix_and_delimiter_collection'
17
+
18
+ module AWS
19
+ class S3
20
+
21
+ # Represents a collection of S3 objects.
22
+ #
23
+ # == Getting an S3Object by Key
24
+ #
25
+ # If you know the key of the object you want, you can reference it this way:
26
+ #
27
+ # # this will not make any requests against S3
28
+ # object = bucket.objects['foo.jpg']
29
+ # object.key #=> 'foo.jpg'
30
+ #
31
+ # == Finding objects with a Prefix
32
+ #
33
+ # Given a bucket with the following keys:
34
+ #
35
+ # photos/sunset.jpg
36
+ # photos/sunrise.jpg
37
+ # photos/winter.jpg
38
+ # videos/comedy.mpg
39
+ # videos/dancing.mpg
40
+ #
41
+ # You can list objects that share a prefix:
42
+ #
43
+ # bucket.objects.with_prefix('videos').collect(&:key)
44
+ # #=> ['videos/comedy.mpg', 'videos/dancing.mpg']
45
+ #
46
+ # == Exploring Objects with a Tree Interface
47
+ #
48
+ # Given a bucket with the following keys:
49
+ #
50
+ # README.txt
51
+ # videos/wedding.mpg
52
+ # videos/family_reunion.mpg
53
+ # photos/2010/house.jpg
54
+ # photos/2011/fall/leaves.jpg
55
+ # photos/2011/summer/vacation.jpg
56
+ # photos/2011/summer/family.jpg
57
+ #
58
+ # tree = bucket.objects.with_prefix.prefix('photos').as_tree
59
+ #
60
+ # directories = tree.children.select(&:branch?).collect(&:prefix)
61
+ # #=> ['photos/2010', 'photos/2011']
62
+ #
63
+ class ObjectCollection
64
+
65
+ include Model
66
+ include Enumerable
67
+ include PrefixAndDelimiterCollection
68
+
69
+ # @param [Bucket] The S3 bucket this object collection belongs to.
70
+ def initialize(bucket, options = {})
71
+ @bucket = bucket
72
+ super
73
+ end
74
+
75
+ # @return [Bucket] The bucket this collection belongs to.
76
+ attr_reader :bucket
77
+
78
+ # Writes a new object to S3.
79
+ #
80
+ # The first param is the key you want to write this object to.
81
+ # All other params/options are documented in {S3Object#write}.
82
+ #
83
+ # @see S3Object#write
84
+ #
85
+ # @param [String] key Where in S3 to write the object.
86
+ # @return [S3Object]
87
+ def create key, *args
88
+ self[key].write(*args)
89
+ end
90
+
91
+ # Returns an S3Object given its name. For example:
92
+ #
93
+ # @example
94
+ #
95
+ # object = bucket.objects['file.txt']
96
+ # object.class #=> S3Object
97
+ #
98
+ # @param [String] key The object key.
99
+ # @return [S3Object]
100
+ def [] key
101
+ S3Object.new(bucket, key.to_s)
102
+ end
103
+
104
+ # (see PrefixedCollection#with_prefix)
105
+ def with_prefix prefix, mode = :replace
106
+ super(prefix, mode)
107
+ end
108
+
109
+ # Iterates the collection, yielding instances of S3Object.
110
+ #
111
+ # Use break or raise an exception to terminate the enumeration.
112
+ #
113
+ # @param [Hash] options
114
+ # @option options [Integer] :limit (nil) The maximum number of
115
+ # objects to yield.
116
+ # @option options [Integer] :batch_size (1000) The number of objects to
117
+ # fetch each request to S3. Maximum is 1000 keys at time.
118
+ # @return [nil]
119
+ def each options = {}, &block
120
+ super
121
+ end
122
+
123
+ # @private
124
+ protected
125
+ def each_member_in_page(page, &block)
126
+ super
127
+ page.contents.each do |content|
128
+ yield(S3Object.new(bucket, content.key))
129
+ end
130
+ end
131
+
132
+ # @private
133
+ protected
134
+ def list_request(options)
135
+ client.list_objects(options)
136
+ end
137
+
138
+ # @private
139
+ protected
140
+ def limit_param
141
+ :max_keys
142
+ end
143
+
144
+ # @private
145
+ protected
146
+ def page_size resp
147
+ super + resp.contents.size
148
+ end
149
+
150
+ # @private
151
+ protected
152
+ def next_markers page
153
+ { :marker => (last = page.contents.last and last.key) }
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+ end
@@ -0,0 +1,67 @@
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 S3
18
+
19
+ # Returns an object that represents the metadata for an S3 object.
20
+ class ObjectMetadata
21
+
22
+ include Model
23
+
24
+ # @param [S3Object]
25
+ # @param [Hash] options
26
+ # @option options [String] :version_id A specific version of the object
27
+ # to get metadata for
28
+ def initialize(object, options = {})
29
+ @object = object
30
+ @version_id = options[:version_id]
31
+ super
32
+ end
33
+
34
+ # @return [S3Object]
35
+ attr_reader :object
36
+
37
+ # Returns the value for the given name stored in the S3Objects
38
+ # metadata:
39
+ #
40
+ # bucket.objects['myobject'].metadata['purpose']
41
+ # # returns nil if the given metadata key has not been set
42
+ #
43
+ # @return [String,nil] Returns the metadata for the given name.
44
+ def [] name
45
+ to_h[name.to_s]
46
+ end
47
+
48
+ # Proxies the method to {#[]}.
49
+ # @return (see #[])
50
+ def method_missing name
51
+ self[name]
52
+ end
53
+
54
+ # @return [Hash] Returns the user-generated metadata stored with
55
+ # this S3 Object.
56
+ def to_h
57
+ options = {}
58
+ options[:bucket_name] = object.bucket.name
59
+ options[:key] = object.key
60
+ options[:version_id] = @version_id if @version_id
61
+ client.head_object(options).meta
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,83 @@
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/s3/paginated_collection'
16
+ require 'aws/s3/multipart_upload'
17
+ require 'aws/s3/multipart_upload_collection'
18
+ require 'aws/s3/s3_object'
19
+
20
+ module AWS
21
+ class S3
22
+
23
+ # Represents uploads in progress for a single object.
24
+ #
25
+ # @example Cancel all uploads for an object
26
+ # object.multipart_uploads.each(&:abort)
27
+ #
28
+ # @example Get an upload by ID
29
+ # object.multipart_uploads[id]
30
+ class ObjectUploadCollection
31
+
32
+ include Enumerable
33
+ include Model
34
+
35
+ # @return [S3Object] The object to which the uploads belong.
36
+ attr_reader :object
37
+
38
+ # @private
39
+ def initialize(object, opts = {})
40
+ @all_uploads =
41
+ MultipartUploadCollection.new(object.bucket).
42
+ with_prefix(object.key)
43
+ @object = object
44
+ super
45
+ end
46
+
47
+ # Creates a new multipart upload. It is usually more
48
+ # convenient to use {S3Object#multipart_upload}.
49
+ def create(options = {})
50
+ options[:storage_class] = :reduced_redundancy if
51
+ options.delete(:reduced_redundancy)
52
+ initiate_opts = {
53
+ :bucket_name => object.bucket.name,
54
+ :key => object.key
55
+ }.merge(options)
56
+ id = client.initiate_multipart_upload(initiate_opts).upload_id
57
+ MultipartUpload.new(object, id)
58
+ end
59
+
60
+ # Iterates the uploads in the collection.
61
+ #
62
+ # @yieldparam [MultipartUpload] upload An upload in the
63
+ # collection.
64
+ # @return [nil]
65
+ def each(options = {}, &block)
66
+ @all_uploads.each(options) do |upload|
67
+ yield(upload) if upload.object.key == @object.key
68
+ end
69
+ nil
70
+ end
71
+
72
+ # @return [MultipartUpload] An object representing the upload
73
+ # with the given ID.
74
+ #
75
+ # @param [String] id The ID of an upload to get.
76
+ def [] id
77
+ MultipartUpload.new(object, id)
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,141 @@
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/errors'
16
+
17
+ module AWS
18
+ class S3
19
+
20
+ # Represents a single version of an S3Object.
21
+ #
22
+ # When you enable versioning on a S3 bucket, writing to an object
23
+ # will create an object version instead of replacing the existing
24
+ # object.
25
+ class ObjectVersion
26
+
27
+ include Model
28
+
29
+ # @param [S3Object] object The object this is a version of.
30
+ # @param [String] version_id The unique id for this version.
31
+ # @param [Hash] options
32
+ # @option options [Boolean] :delete_marker Is this version a
33
+ # delete marker?
34
+ def initialize(object, version_id, options = {})
35
+ @object = object
36
+ @version_id = version_id
37
+ @delete_marker = options[:delete_marker]
38
+ super
39
+ end
40
+
41
+ # @return [S3Object] the object this is a version of.
42
+ attr_reader :object
43
+
44
+ def bucket
45
+ object.bucket
46
+ end
47
+
48
+ # @return [String] The unique version identifier.
49
+ attr_reader :version_id
50
+
51
+ # @return (see S3Object#key)
52
+ def key
53
+ object.key
54
+ end
55
+
56
+ # @see S3Object#head
57
+ # @return (see S3Object#head)
58
+ def head
59
+ object.head(:version_id => @version_id)
60
+ end
61
+
62
+ # @see S3Object#etag
63
+ # @return (see S3Object#etag)
64
+ def etag
65
+ head.etag
66
+ end
67
+
68
+ # @return (see S3Object#content_length)
69
+ def content_length
70
+ head.content_length
71
+ end
72
+
73
+ # @note (see S3Object#content_type)
74
+ # @see S3Object#content_type
75
+ # @return (see S3Object#content_type)
76
+ def content_type
77
+ head.content_type
78
+ end
79
+
80
+ # @see S3Object#metadata
81
+ # @return (see S3Object#metadata)
82
+ def metadata
83
+ object.metadata(:version_id => @version_id)
84
+ end
85
+
86
+ # Reads the data from this object version.
87
+ # @see S3Object#read
88
+ # @options (see S3Object#read)
89
+ # @return (see S3Object#read)
90
+ def read options = {}, &block
91
+ object.read(options.merge(:version_id => @version_id), &block)
92
+ end
93
+
94
+ # Deletes this object version from S3.
95
+ # @return (see S3Object#delete)
96
+ def delete
97
+ object.delete(:version_id => @version_id)
98
+ end
99
+
100
+ # @return [Boolean] Returns this if this is the latest version of
101
+ # the object, false if the object has been written to since
102
+ # this version was created.
103
+ def latest?
104
+ object.versions.latest.version_id == self.version_id
105
+ end
106
+
107
+ # If you delete an object in a versioned bucket, a delete marker
108
+ # is created.
109
+ # @return [Boolean] Returns true if this version is a delete marker.
110
+ def delete_marker?
111
+ if @delete_marker.nil?
112
+ begin
113
+ # S3 responds with a 405 (method not allowed) when you try
114
+ # to HEAD an s3 object version that is a delete marker
115
+ metadata['foo']
116
+ @delete_marker = false
117
+ rescue Errors::MethodNotAllowed => error
118
+ @delete_marker = true
119
+ end
120
+ end
121
+ @delete_marker
122
+ end
123
+
124
+ # @return [Boolean] Returns true if the other object version has
125
+ # the same s3 object key and version id.
126
+ def ==(other)
127
+ other.kind_of?(ObjectVersion) and
128
+ other.object == object and
129
+ other.version_id == version_id
130
+ end
131
+
132
+ alias_method :eql?, :==
133
+
134
+ # @private
135
+ def inspect
136
+ "<#{self.class}:#{object.bucket.name}:#{object.key}:#{version_id}>"
137
+ end
138
+
139
+ end
140
+ end
141
+ end