Module: Sndacs::Parser

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

Instance Method Summary collapse

Instance Method Details

#parse_all_buckets_result(xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sndacs/parser.rb', line 14

def parse_all_buckets_result(xml)
  all_buckets = []
  rexml_document(xml).elements.each("ListAllMyBucketsResult/Buckets/Bucket") do |e|
    bucket_attributes = {}
    bucket_attributes[:name] = e.elements["Name"].text

    element_location = e.elements["Location"]
    if element_location
      bucket_attributes[:location] = element_location.text
    else
      bucket_attributes[:location] = REGION_DEFAULT
    end

    all_buckets << bucket_attributes
  end

  all_buckets
end

#parse_all_objects_result(xml) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sndacs/parser.rb', line 33

def parse_all_objects_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_copy_object_result(xml) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/sndacs/parser.rb', line 57

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



65
66
67
68
69
70
# File 'lib/sndacs/parser.rb', line 65

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



72
73
74
# File 'lib/sndacs/parser.rb', line 72

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

#parse_location_constraint(xml) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/sndacs/parser.rb', line 48

def parse_location_constraint(xml)
  location = rexml_document(xml).elements["LocationConstraint"].text
  if location.nil? || location == ''
    location = REGION_DEFAULT
  end

  location
end

#rexml_document(xml) ⇒ Object



8
9
10
11
12
# File 'lib/sndacs/parser.rb', line 8

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

  Document.new(xml)
end