Class: UberS3::Response
- Inherits:
-
Object
- Object
- UberS3::Response
- Defined in:
- lib/uber-s3/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#error_key ⇒ Object
Returns the value of attribute error_key.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#header ⇒ Object
Returns the value of attribute header.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
TODO: can/should we normalize the keys..? downcase..
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/uber-s3/response.rb', line 6 def initialize(={}) if !([:status, :header, :body, :raw] - .keys).empty? raise "Expecting keys :status, :header, :body and :raw" end self.status = [:status] self.header = [:header] self.body = [:body] self.raw = [:raw] success? end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def body @body end |
#error_key ⇒ Object
Returns the value of attribute error_key.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def error_key @error_key end |
#error_message ⇒ Object
Returns the value of attribute error_message.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def @error_message end |
#header ⇒ Object
Returns the value of attribute header.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def header @header end |
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def raw @raw end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/uber-s3/response.rb', line 4 def status @status end |
Instance Method Details
#error ⇒ Object
41 42 43 44 45 |
# File 'lib/uber-s3/response.rb', line 41 def error if !error_key.nil? "#{error_key}: #{}" end end |
#success? ⇒ Boolean
TODO: can/should we normalize the keys..? downcase.. etc.? def header=(header) end
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/uber-s3/response.rb', line 23 def success? return if status < 400 || body.to_s.empty? # Errors are XML doc = Util::XmlDocument.new(body) self.error_key = doc.xpath('//Error/Code').first.text self. = doc.xpath('//Error/Message').first.text error_klass = instance_eval("Error::#{error_key}") rescue nil if error_klass.nil? raise Error::Unknown, "HTTP Response: #{status}, Body: #{body}" else raise error_klass.new(error_key, ) end end |