Class: CoinTracking::Response

Inherits:
Object
  • Object
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_responseObject (readonly)

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

#bodyObject



23
24
25
# File 'lib/coin_tracking/response.rb', line 23

def body
  @http_response.body
end

#dataObject



19
20
21
# File 'lib/coin_tracking/response.rb', line 19

def data
  to_h
end

#error?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/coin_tracking/response.rb', line 31

def error?
  !success?
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/coin_tracking/response.rb', line 27

def success?
  data['success'].to_i == 1
end

#to_hObject



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