Class: Net::HTTPResponse
- Inherits:
-
Object
- Object
- Net::HTTPResponse
- Defined in:
- lib/aliyunoss/extension.rb
Instance Method Summary collapse
- #raise_unless(status) ⇒ Object
- #to_acl_status ⇒ Object
- #to_buckets ⇒ Object
- #to_logging_status ⇒ Object
- #to_multipart_id ⇒ Object
- #to_mutlipart_task ⇒ Object
- #to_objects ⇒ Object
- #to_website_status ⇒ Object
Instance Method Details
#raise_unless(status) ⇒ Object
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_status ⇒ Object
80 81 82 83 |
# File 'lib/aliyunoss/extension.rb', line 80 def to_acl_status raise unless Net::HTTPOK === self Nokogiri::XML(self.body).xpath('//Grant')[0].content end |
#to_buckets ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/aliyunoss/extension.rb', line 46 def to_buckets raise 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_status ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/aliyunoss/extension.rb', line 66 def to_logging_status raise 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_id ⇒ Object
85 86 87 88 |
# File 'lib/aliyunoss/extension.rb', line 85 def to_multipart_id raise unless Net::HTTPOK === self Nokogiri::XML(body).xpath('//UploadId').first.content end |
#to_mutlipart_task ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/aliyunoss/extension.rb', line 90 def to_mutlipart_task raise 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_objects ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/aliyunoss/extension.rb', line 56 def to_objects raise 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_status ⇒ Object
74 75 76 77 78 |
# File 'lib/aliyunoss/extension.rb', line 74 def to_website_status raise 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 |