Class: RestWorld::Response
- Inherits:
-
Object
- Object
- RestWorld::Response
- Defined in:
- lib/blix/rest/cucumber/world.rb
Overview
a class to represent a response from the server
Instance Method Summary collapse
- #[](k) ⇒ Object
- #body ⇒ Object
- #content_type ⇒ Object
- #data ⇒ Object
- #error ⇒ Object
- #header ⇒ Object
-
#initialize(resp) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(resp) ⇒ Response
Returns a new instance of Response.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/blix/rest/cucumber/world.rb', line 17 def initialize(resp) @resp = resp content_type = @resp.headers['Content-Type'] || @resp.headers['content-type'] if content_type == 'application/json' begin @h = MultiJson.load(body) || {} rescue Exception => e log 'INVALID RESPONSE BODY=>' + body raise end else @h = { 'html' => body } end # get_ids_from_hash end |
Instance Method Details
#[](k) ⇒ Object
34 35 36 |
# File 'lib/blix/rest/cucumber/world.rb', line 34 def [](k) @h[k] end |
#body ⇒ Object
38 39 40 |
# File 'lib/blix/rest/cucumber/world.rb', line 38 def body [@resp.body].flatten.join('') end |
#content_type ⇒ Object
58 59 60 |
# File 'lib/blix/rest/cucumber/world.rb', line 58 def content_type header['Content-Type'] end |
#data ⇒ Object
42 43 44 |
# File 'lib/blix/rest/cucumber/world.rb', line 42 def data @h['data'] end |
#error ⇒ Object
46 47 48 |
# File 'lib/blix/rest/cucumber/world.rb', line 46 def error @h['error'] end |
#header ⇒ Object
54 55 56 |
# File 'lib/blix/rest/cucumber/world.rb', line 54 def header @resp.headers || {} end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/blix/rest/cucumber/world.rb', line 62 def inspect @resp.inspect end |
#status ⇒ Object
50 51 52 |
# File 'lib/blix/rest/cucumber/world.rb', line 50 def status @resp.status.to_i end |