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
867 868 869 870 871 872 873 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 867 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
876 877 878 879 880 881 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 876 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
390 391 392 393 394 395 396 397 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 390 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.
85 86 87 88 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 85 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
93 94 95 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 93 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteObjectOutput
423 424 425 426 427 428 429 430 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 423 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
47 48 49 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 47 def etag data[:etag] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 100 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
509 510 511 512 513 514 515 516 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 509 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.
916 917 918 919 920 921 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 916 def identifiers { bucket_name: @bucket_name, key: @key } end |
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 622 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
42 43 44 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 42 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.
76 77 78 79 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 76 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
885 886 887 888 889 890 891 892 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 885 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
895 896 897 898 899 900 901 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 895 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
63 64 65 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 63 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
748 749 750 751 752 753 754 755 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 748 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.put_object() resp.data end |
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
855 856 857 858 859 860 861 862 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 855 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.restore_object() resp.data end |
#size ⇒ Integer Also known as: content_length
52 53 54 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 52 def size data[:size] end |
#storage_class ⇒ String
The class of storage used to store the object.
58 59 60 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 58 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
905 906 907 908 909 910 911 912 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 905 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
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 227 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
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 117 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
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 136 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 |