Class: Net::HTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyunoss/extension.rb

Instance Method Summary collapse

Instance Method Details

#raise_unless(status) ⇒ Object

Raises:



41
42
43
44
# File 'lib/aliyunoss/extension.rb', line 41

def raise_unless(status)
  raise OssException.new(self) unless status === self
  self
end

#to_acl_statusObject



80
81
82
83
# File 'lib/aliyunoss/extension.rb', line 80

def to_acl_status
  raise message unless Net::HTTPOK === self
  Nokogiri::XML(self.body).xpath('//Grant')[0].content
end

#to_bucketsObject



46
47
48
49
50
51
52
53
54
# File 'lib/aliyunoss/extension.rb', line 46

def to_buckets
  raise message unless Net::HTTPOK === self
  nodes = Nokogiri::XML(self.body).xpath('//Bucket') rescue []
  nodes.map do |node|
    bucket = Aliyun::Oss::Bucket.new
    node.elements.each {|e| bucket.send("#{e.name.underscore}=".to_sym, e.content) rescue nil }
    bucket
  end
end

#to_logging_statusObject



66
67
68
69
70
71
72
# File 'lib/aliyunoss/extension.rb', line 66

def to_logging_status
  raise message unless Net::HTTPOK === self
  node = Nokogiri::XML(self.body).xpath('//LoggingEnabled') rescue []
  hash = Hash.new
  node[0].elements.each {|e| hash[e.name.underscore] = e.content }
  hash                                                     
end

#to_multipart_idObject



85
86
87
88
# File 'lib/aliyunoss/extension.rb', line 85

def to_multipart_id
  raise message unless Net::HTTPOK === self
  Nokogiri::XML(body).xpath('//UploadId').first.content      
end

#to_mutlipart_taskObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/aliyunoss/extension.rb', line 90

def to_mutlipart_task
  raise message unless Net::HTTPOK === self
  tasks = Array.new
  nodes = Nokogiri::XML(response.body).xpath('//Upload')
  nodes.each do |node|
    path = '/' + node.xpath('Key').first.content
    id = node.xpath('UploadId').first.content
    tasks << {'path'=> path, 'upload_id' => id}
  end
  tasks
end

#to_objectsObject



56
57
58
59
60
61
62
63
64
# File 'lib/aliyunoss/extension.rb', line 56

def to_objects
  raise message unless Net::HTTPOK === self
  nodes = Nokogiri::XML(self.body).xpath('//Contents') rescue []
  nodes.map do |node|
    hash = Hash.new
    node.elements.each {|e| hash[e.name.underscore] = e.content unless e.name == 'Owner' }
    hash
  end      
end

#to_website_statusObject



74
75
76
77
78
# File 'lib/aliyunoss/extension.rb', line 74

def to_website_status
  raise message unless Net::HTTPOK === self
  xml = Nokogiri::XML(self.body)
  {'index_page' => xml.xpath('//Suffix')[0].content, 'error_page' => xml.xpath('//Key')[0].content } rescue {}
end