Module: S3::Parser

Includes:
REXML
Included in:
Bucket, Connection, Object, Service
Defined in:
lib/s3/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_acl(xml) ⇒ Object

Parse acl response and return hash with grantee and their permissions



54
55
56
57
58
59
60
# File 'lib/s3/parser.rb', line 54

def parse_acl(xml)
  grants = {}
  rexml_document(xml).elements.each("AccessControlPolicy/AccessControlList/Grant") do |grant|
    grants.merge!(extract_grantee(grant))
  end
  grants
end

#parse_copy_object_result(xml) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/s3/parser.rb', line 33

def parse_copy_object_result(xml)
  object_attributes = {}
  document = rexml_document(xml)
  object_attributes[:etag] = document.elements["CopyObjectResult/ETag"].text
  object_attributes[:last_modified] = document.elements["CopyObjectResult/LastModified"].text
  object_attributes
end

#parse_error(xml) ⇒ Object



41
42
43
44
45
46
# File 'lib/s3/parser.rb', line 41

def parse_error(xml)
  document = rexml_document(xml)
  code = document.elements["Error/Code"].text
  message = document.elements["Error/Message"].text
  [code, message]
end

#parse_is_truncated(xml) ⇒ Object



48
49
50
# File 'lib/s3/parser.rb', line 48

def parse_is_truncated xml
  rexml_document(xml).elements["ListBucketResult/IsTruncated"].text =='true'
end

#parse_list_all_my_buckets_result(xml) ⇒ Object



10
11
12
13
14
# File 'lib/s3/parser.rb', line 10

def parse_list_all_my_buckets_result(xml)
  names = []
  rexml_document(xml).elements.each("ListAllMyBucketsResult/Buckets/Bucket/Name") { |e| names << e.text }
  names
end

#parse_list_bucket_result(xml) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/s3/parser.rb', line 20

def parse_list_bucket_result(xml)
  objects_attributes = []
  rexml_document(xml).elements.each("ListBucketResult/Contents") do |e|
    object_attributes = {}
    object_attributes[:key] = e.elements["Key"].text
    object_attributes[:etag] = e.elements["ETag"].text
    object_attributes[:last_modified] = e.elements["LastModified"].text
    object_attributes[:size] = e.elements["Size"].text
    objects_attributes << object_attributes
  end
  objects_attributes
end

#parse_location_constraint(xml) ⇒ Object



16
17
18
# File 'lib/s3/parser.rb', line 16

def parse_location_constraint(xml)
  rexml_document(xml).elements["LocationConstraint"].text
end

#rexml_document(xml) ⇒ Object



5
6
7
8
# File 'lib/s3/parser.rb', line 5

def rexml_document(xml)
  xml.force_encoding(::Encoding::UTF_8) if xml.respond_to? :force_encoding
  Document.new(xml)
end