Class: Delphix::WebResponse

Inherits:
Object
  • Object
show all
Includes:
Net::HTTPHeader
Defined in:
lib/delphix/web_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ WebResponse

Returns a new instance of WebResponse.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/delphix/web_response.rb', line 48

def initialize(response)
  @code = response.code
  @headers = response.headers
  @raw_body = response
  @body = @raw_body
  @cookies = response.cookies

  Delphix.last_response = {
    code: response.code,
    headers: response.headers,
    body: JSON.parse(response.body),
    cookies: response.cookies,
    description: response.description
  }.recursively_normalize_keys

  begin
    @body = JSON.parse(@raw_body)
  rescue Exception
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/delphix/web_response.rb', line 77

def method_missing(name, *args, &block)
  if @headers.respond_to?(name)
    @headers.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



38
39
40
# File 'lib/delphix/web_response.rb', line 38

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



29
30
31
# File 'lib/delphix/web_response.rb', line 29

def code
  @code
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



46
47
48
# File 'lib/delphix/web_response.rb', line 46

def cookies
  @cookies
end

#headersObject (readonly)

Returns the value of attribute headers.



42
43
44
# File 'lib/delphix/web_response.rb', line 42

def headers
  @headers
end

#method#raw_body (readonly)

The current session cookies.

Returns:



33
# File 'lib/delphix/web_response.rb', line 33

attr_reader :raw_body

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



33
34
35
# File 'lib/delphix/web_response.rb', line 33

def raw_body
  @raw_body
end

Instance Method Details

#==(other) ⇒ Object



69
70
71
# File 'lib/delphix/web_response.rb', line 69

def ==(other)
  @headers == other
end

#inspectObject



73
74
75
# File 'lib/delphix/web_response.rb', line 73

def inspect
  @headers.inspect
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/delphix/web_response.rb', line 85

def respond_to?(method)
  super || @headers.respond_to?(method)
end