Class: CoinTracking::Response
- Inherits:
-
Object
- Object
- CoinTracking::Response
show all
- Defined in:
- lib/coin_tracking/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
7
8
9
|
# File 'lib/coin_tracking/response.rb', line 7
def initialize(http_response)
@http_response = http_response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
35
36
37
|
# File 'lib/coin_tracking/response.rb', line 35
def method_missing(method_sym, *arguments, &block)
data.include?(method_sym.to_s) ? data[method_sym.to_s] : super
end
|
Instance Attribute Details
#http_response ⇒ Object
Returns the value of attribute http_response.
5
6
7
|
# File 'lib/coin_tracking/response.rb', line 5
def http_response
@http_response
end
|
Instance Method Details
#body ⇒ Object
23
24
25
|
# File 'lib/coin_tracking/response.rb', line 23
def body
@http_response.body
end
|
#data ⇒ Object
19
20
21
|
# File 'lib/coin_tracking/response.rb', line 19
def data
to_h
end
|
#error? ⇒ Boolean
31
32
33
|
# File 'lib/coin_tracking/response.rb', line 31
def error?
!success?
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
39
40
41
|
# File 'lib/coin_tracking/response.rb', line 39
def respond_to?(method_sym, include_private = false)
data.include?(method_sym.to_s) ? true : super
end
|
#success? ⇒ Boolean
27
28
29
|
# File 'lib/coin_tracking/response.rb', line 27
def success?
data['success'].to_i == 1
end
|
#to_h ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/coin_tracking/response.rb', line 11
def to_h
if @http_response.parsed_response.is_a?(String)
JSON.parse(@http_response.parsed_response)
else
@http_response.parsed_response
end
end
|