Class: Aws::S3::ObjectSummary
- Inherits:
-
Object
- Object
- Aws::S3::ObjectSummary
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-s3/object_summary.rb,
lib/aws-sdk-s3/customizations/object_summary.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
- #bucket_name ⇒ String
- #etag ⇒ String
- #key ⇒ String
- #last_modified ⇒ Time
- #owner ⇒ Types::Owner
- #size ⇒ Integer (also: #content_length)
-
#storage_class ⇒ String
The class of storage used to store the object.
Actions collapse
- #copy_from(source, options = {}) ⇒ Types::CopyObjectOutput
- #delete(options = {}) ⇒ Types::DeleteObjectOutput
- #get(options = {}, &block) ⇒ Types::GetObjectOutput
- #initiate_multipart_upload(options = {}) ⇒ MultipartUpload
- #put(options = {}) ⇒ Types::PutObjectOutput
- #restore_object(options = {}) ⇒ Types::RestoreObjectOutput
Associations collapse
- #acl ⇒ ObjectAcl
- #bucket ⇒ Bucket
- #identifiers ⇒ Object deprecated private Deprecated.
- #multipart_upload(id) ⇒ MultipartUpload
- #object ⇒ Object
- #version(id) ⇒ ObjectVersion
Instance Method Summary collapse
- #client ⇒ Client
- #copy_to(target, options = {}) ⇒ Object
-
#data ⇒ Types::Object
Returns the data for this ObjectSummary.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#download_file(destination, options = {}) ⇒ Boolean
Returns ‘true` when the file is downloaded without any errors.
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
-
#initialize(*args) ⇒ ObjectSummary
constructor
A new instance of ObjectSummary.
- #load ⇒ Object (also: #reload) private
- #move_to(target, options = {}) ⇒ void
- #presigned_post(options = {}) ⇒ PresignedPost
- #presigned_url(http_method, params = {}) ⇒ String
- #public_url(options = {}) ⇒ String
-
#upload_file(source, options = {}) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
-
#upload_stream(options = {}, &block) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
-
#wait_until(options = {}, &block) ⇒ Resource
deprecated
Deprecated.
Use [Aws::S3::Client] #wait_until instead
- #wait_until_exists(options = {}) ⇒ ObjectSummary
- #wait_until_not_exists(options = {}) ⇒ ObjectSummary
Constructor Details
#initialize(bucket_name, key, options = {}) ⇒ ObjectSummary #initialize(options = {}) ⇒ ObjectSummary
Returns a new instance of ObjectSummary.
21 22 23 24 25 26 27 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 21 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @bucket_name = extract_bucket_name(args, ) @key = extract_key(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() end |
Instance Method Details
#acl ⇒ ObjectAcl
872 873 874 875 876 877 878 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 872 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
881 882 883 884 885 886 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 881 def bucket Bucket.new( name: @bucket_name, client: @client ) end |
#bucket_name ⇒ String
32 33 34 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 32 def bucket_name @bucket_name end |
#copy_from(source, options = {}) ⇒ Types::CopyObjectOutput
394 395 396 397 398 399 400 401 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 394 def copy_from( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.copy_object() resp.data end |
#copy_to(target, options = {}) ⇒ Object
19 20 21 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 19 def copy_to(target, = {}) object.copy_to(target, ) end |
#data ⇒ Types::Object
Returns the data for this Aws::S3::ObjectSummary.
89 90 91 92 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 89 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
97 98 99 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 97 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteObjectOutput
427 428 429 430 431 432 433 434 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 427 def delete( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.delete_object() resp.data end |
#download_file(destination, options = {}) ⇒ Boolean
Returns ‘true` when the file is downloaded without any errors.
74 75 76 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 74 def download_file(destination, = {}) object.download_file(destination, ) end |
#etag ⇒ String
49 50 51 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 49 def etag data[:etag] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 104 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#get(options = {}, &block) ⇒ Types::GetObjectOutput
513 514 515 516 517 518 519 520 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 513 def get( = {}, &block) = .merge( bucket: @bucket_name, key: @key ) resp = @client.get_object(, &block) resp.data end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
921 922 923 924 925 926 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 921 def identifiers { bucket_name: @bucket_name, key: @key } end |
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 626 def initiate_multipart_upload( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.create_multipart_upload() MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: resp.data.upload_id, client: @client ) end |
#key ⇒ String
37 38 39 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 37 def key @key end |
#last_modified ⇒ Time
43 44 45 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 43 def last_modified data[:last_modified] end |
#load ⇒ Object Also known as: reload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 83 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 80 def load msg = "#load is not implemented, data only available via enumeration" raise NotImplementedError, msg end |
#move_to(target, options = {}) ⇒ void
This method returns an undefined value.
27 28 29 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 27 def move_to(target, = {}) object.move_to(target, ) end |
#multipart_upload(id) ⇒ MultipartUpload
890 891 892 893 894 895 896 897 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 890 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
900 901 902 903 904 905 906 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 900 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
67 68 69 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 67 def owner data[:owner] end |
#presigned_post(options = {}) ⇒ PresignedPost
35 36 37 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 35 def presigned_post( = {}) object.presigned_post() end |
#presigned_url(http_method, params = {}) ⇒ String
43 44 45 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 43 def presigned_url(http_method, params = {}) object.presigned_url(http_method, params) end |
#public_url(options = {}) ⇒ String
51 52 53 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 51 def public_url( = {}) object.public_url() end |
#put(options = {}) ⇒ Types::PutObjectOutput
753 754 755 756 757 758 759 760 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 753 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.put_object() resp.data end |
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
860 861 862 863 864 865 866 867 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 860 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.restore_object() resp.data end |
#size ⇒ Integer Also known as: content_length
55 56 57 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 55 def size data[:size] end |
#storage_class ⇒ String
The class of storage used to store the object.
61 62 63 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 61 def storage_class data[:storage_class] end |
#upload_file(source, options = {}) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
59 60 61 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 59 def upload_file(source, = {}) object.upload_file(source, ) end |
#upload_stream(options = {}, &block) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
66 67 68 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 66 def upload_stream( = {}, &block) object.upload_stream(, &block) end |
#version(id) ⇒ ObjectVersion
910 911 912 913 914 915 916 917 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 910 def version(id) ObjectVersion.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#wait_until(options = {}, &block) ⇒ Resource
Use [Aws::S3::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged
Waiter polls an API operation until a resource enters a desired state.
## Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
## Example
instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }
## Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
## Callbacks
You can be notified before each polling attempt and before each delay. If you throw ‘:success` or `:failure` from these callbacks, it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
## Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 231 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}) ⇒ ObjectSummary
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 121 def wait_until_exists( = {}) , params = () waiter = Waiters::ObjectExists.new() yield_waiter_and_warn(waiter, &Proc.new) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |
#wait_until_not_exists(options = {}) ⇒ ObjectSummary
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 140 def wait_until_not_exists( = {}) , params = () waiter = Waiters::ObjectNotExists.new() yield_waiter_and_warn(waiter, &Proc.new) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |