Class: Urtak::Response
- Inherits:
-
Object
- Object
- Urtak::Response
- Defined in:
- lib/urtak.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#format ⇒ Object
Returns the value of attribute format.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #code ⇒ Object
- #error ⇒ Object
- #failure? ⇒ Boolean
-
#found? ⇒ Boolean
naive.
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #not_found? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/urtak.rb', line 264 def initialize(response) @raw = response @format = nil # TODO case statement if response.headers[:content_type].nil? || response.body.empty? @body = response elsif response.headers[:content_type].match(/json/) @body = JSON.parse(response) @format = "JSON" elsif response.headers[:content_type].match(/xml/) raise Urtak::Errors::Unimplemented @format = "XML" else @body = response end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
262 263 264 |
# File 'lib/urtak.rb', line 262 def body @body end |
#format ⇒ Object
Returns the value of attribute format.
262 263 264 |
# File 'lib/urtak.rb', line 262 def format @format end |
#raw ⇒ Object
Returns the value of attribute raw.
262 263 264 |
# File 'lib/urtak.rb', line 262 def raw @raw end |
Instance Method Details
#code ⇒ Object
282 283 284 |
# File 'lib/urtak.rb', line 282 def code raw.code end |
#error ⇒ Object
286 287 288 |
# File 'lib/urtak.rb', line 286 def error response.body['error'] ? response.body['error']['message'] : nil end |
#failure? ⇒ Boolean
298 299 300 |
# File 'lib/urtak.rb', line 298 def failure? code >= 400 end |
#found? ⇒ Boolean
naive
307 308 309 |
# File 'lib/urtak.rb', line 307 def found? code == 200 || code == 304 end |
#headers ⇒ Object
290 291 292 |
# File 'lib/urtak.rb', line 290 def headers raw.headers end |
#not_found? ⇒ Boolean
302 303 304 |
# File 'lib/urtak.rb', line 302 def not_found? code == 404 end |
#success? ⇒ Boolean
294 295 296 |
# File 'lib/urtak.rb', line 294 def success? code >= 200 && code < 400 end |