Class: RestWorld::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/blix/rest/cucumber/world.rb

Overview

a class to represent a response from the server

Instance Method Summary collapse

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

#bodyObject



38
39
40
# File 'lib/blix/rest/cucumber/world.rb', line 38

def body
  [@resp.body].flatten.join('')
end

#content_typeObject



58
59
60
# File 'lib/blix/rest/cucumber/world.rb', line 58

def content_type
  header['Content-Type']
end

#dataObject



42
43
44
# File 'lib/blix/rest/cucumber/world.rb', line 42

def data
  @h['data']
end

#errorObject



46
47
48
# File 'lib/blix/rest/cucumber/world.rb', line 46

def error
  @h['error']
end

#headerObject



54
55
56
# File 'lib/blix/rest/cucumber/world.rb', line 54

def header
  @resp.headers || {}
end

#inspectObject



62
63
64
# File 'lib/blix/rest/cucumber/world.rb', line 62

def inspect
  @resp.inspect
end

#statusObject



50
51
52
# File 'lib/blix/rest/cucumber/world.rb', line 50

def status
  @resp.status.to_i
end