Class: Croesus::WebResponse

Inherits:
Object show all
Includes:
Utils, Net::HTTPHeader
Defined in:
lib/croesus/web_client/web_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#callable, #caller_name, #camelize, #class_name, #classify, #command_in_path?, #demodulize, #pluralize, #request_id, #retrier, #singularize, #terminal_dimensions, #twenty_four_hours_ago, #underscore, #utc_httpdate, #verify_options

Constructor Details

#initialize(response) ⇒ WebResponse

Returns a new instance of WebResponse.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/croesus/web_client/web_response.rb', line 29

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

  Croesus.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



58
59
60
61
62
63
64
# File 'lib/croesus/web_client/web_response.rb', line 58

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.



27
28
29
# File 'lib/croesus/web_client/web_response.rb', line 27

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



27
28
29
# File 'lib/croesus/web_client/web_response.rb', line 27

def code
  @code
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



27
28
29
# File 'lib/croesus/web_client/web_response.rb', line 27

def cookies
  @cookies
end

#headersObject (readonly)

Returns the value of attribute headers.



27
28
29
# File 'lib/croesus/web_client/web_response.rb', line 27

def headers
  @headers
end

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



27
28
29
# File 'lib/croesus/web_client/web_response.rb', line 27

def raw_body
  @raw_body
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/croesus/web_client/web_response.rb', line 50

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

#inspectObject



54
55
56
# File 'lib/croesus/web_client/web_response.rb', line 54

def inspect
  @headers.inspect
end

#respond_to?(method) ⇒ Boolean

Returns:



66
67
68
# File 'lib/croesus/web_client/web_response.rb', line 66

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