Class: S3::BucketListRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/bucket_list_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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/s3/bucket_list_request.rb', line 11

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

  buckets = document.xpath( '//Bucket' ).map do | node |
    { name: node.at( 'Name' )&.text,
      creation_date: Helpers.parse_iso8601( node.at( 'CreationDate' )&.text )
    }
  end

  owner_node = document.at( '//Owner' )
  owner_info = if owner_node
                 { id: owner_node.at( 'ID' )&.text,
                   display_name: owner_node.at( 'DisplayName' )&.text
                 }
               end

  { buckets: buckets, owner: owner_info }
end

#submit ⇒ Object



3
4
5
6
7
8
9
# File 'lib/s3/bucket_list_request.rb', line 3

def submit
  response = get( '/' )

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