Class: Klient::ResponseData

Inherits:
Object
  • Object
show all
Defined in:
lib/klient/response_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, parsed_body) ⇒ ResponseData

Returns a new instance of ResponseData.



13
14
15
16
# File 'lib/klient/response_data.rb', line 13

def initialize(status_code, parsed_body)
  @status_code = status_code
  @parsed_body = parsed_body.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

TODO: Bandaid.



23
24
25
# File 'lib/klient/response_data.rb', line 23

def method_missing(mth, *args, &block)
  @parsed_body.send(mth, *args, &block)
end

Instance Attribute Details

#original_responseObject (readonly)

Returns the value of attribute original_response.



3
4
5
# File 'lib/klient/response_data.rb', line 3

def original_response
  @original_response
end

#parsed_bodyObject (readonly)

Returns the value of attribute parsed_body.



3
4
5
# File 'lib/klient/response_data.rb', line 3

def parsed_body
  @parsed_body
end

#parsed_headersObject (readonly)

Returns the value of attribute parsed_headers.



3
4
5
# File 'lib/klient/response_data.rb', line 3

def parsed_headers
  @parsed_headers
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



3
4
5
# File 'lib/klient/response_data.rb', line 3

def status_code
  @status_code
end

Instance Method Details

#bodyObject



5
6
7
# File 'lib/klient/response_data.rb', line 5

def body
  nil
end

#headersObject



9
10
11
# File 'lib/klient/response_data.rb', line 9

def headers
  nil
end

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/klient/response_data.rb', line 18

def ok?
  (200..299).include?(status_code)
end

#respond_to_missing?(mth, *args) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/klient/response_data.rb', line 27

def respond_to_missing?(mth, *args)
  mth.to_s =~ /http_(\d+)\?/ || @parsed_body.respond_to?(mth) || super
end