Class: Strobe::Connection::Response
- Inherits:
-
Object
- Object
- Strobe::Connection::Response
- Defined in:
- lib/strobe/connection.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(response, request) ⇒ Response
constructor
A new instance of Response.
- #status ⇒ Object
- #success? ⇒ Boolean
- #to_hash ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(response, request) ⇒ Response
Returns a new instance of Response.
60 61 62 63 64 65 66 67 68 |
# File 'lib/strobe/connection.rb', line 60 def initialize(response, request) @response = response @headers = {} @request = request response.each_header do |key, val| @headers[key] = val end end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
58 59 60 |
# File 'lib/strobe/connection.rb', line 58 def headers @headers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
58 59 60 |
# File 'lib/strobe/connection.rb', line 58 def request @request end |
Instance Method Details
#body ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/strobe/connection.rb', line 74 def body return @body if @body case mime_type when :json @body = json_decode(@response.body) else @body = @response.body end @body end |
#status ⇒ Object
70 71 72 |
# File 'lib/strobe/connection.rb', line 70 def status @response.code.to_i end |
#success? ⇒ Boolean
87 88 89 |
# File 'lib/strobe/connection.rb', line 87 def success? status == 200 end |
#to_hash ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/strobe/connection.rb', line 108 def to_hash { :body => body, :headers => headers, :status => status } end |
#validate! ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/strobe/connection.rb', line 91 def validate! case status when 401 raise UnauthenticatedError, when 404 raise ResourceNotFoundError, when 412 raise OutdatedStrobeVersionError, when 503 headers["x-strobe-maintenance"] ? raise(UnderMaintenanceError) : server_error when 500...600 server_error end self end |