Class: S3::ObjectCopyRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/object_copy_request.rb

Constant Summary

Constants inherited from Request

Request::AWS_ALGORITHM, Request::AWS_REQUEST, Request::SERVICE, Request::UNSIGNED_PAYLOAD

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from S3::Request

Instance Method Details

#parse_response(body) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/s3/object_copy_request.rb', line 27

def parse_response( body )
  document = parse_xml( body )
  document.remove_namespaces!

  { etag: document.at( '//ETag' )&.text&.tr( '"', '' ),
    last_modified: Helpers.parse_iso8601( document.at( '//LastModified' )&.text )
  }
end

#submit(options = nil, source_bucket:, source_key:, bucket:, key:, **kwargs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/s3/object_copy_request.rb', line 3

def submit( options = nil, source_bucket:, source_key:, bucket:, key:, **kwargs )
  path = "/#{ bucket }/#{ Helpers.encode_key( key ) }"

  source = "/#{ source_bucket }/#{ Helpers.encode_key( source_key ) }"

  options = merge_options( options, kwargs, ObjectCopyOptions )

  headers = { 'x-amz-copy-source' => source }
  headers[ 'x-amz-metadata-directive' ] = options[ :metadata_directive ] if options[ :metadata_directive ]
  headers[ 'x-amz-storage-class' ] = options[ :storage_class ] if options[ :storage_class ]
  headers[ 'x-amz-acl' ] = options[ :acl ] if options[ :acl ]
  headers[ 'Content-Type' ] = options[ :content_type ] if options[ :content_type ]

  options[ :metadata ]&.each do | meta_key, value |
    headers[ "x-amz-meta-#{ meta_key }" ] = value.to_s
  end

  response = put( path, body: '', headers: headers )

  build_result( response, ObjectCopyResult ) do
    ObjectCopyResult.new( parse_response( response.body ) )
  end
end