Class: ECBExchangeRatesApi::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ecb_exchange_rates_api/result.rb

Overview

Wrapper for HTTParty response object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, status: 200) ⇒ Result

Returns a new instance of Result.



10
11
12
13
14
15
# File 'lib/ecb_exchange_rates_api/result.rb', line 10

def initialize(data, status: 200)
  data = {} unless data.is_a?(Hash)

  @status = status
  @data = OpenStruct.new(data.with_indifferent_access)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object (private)



27
28
29
30
31
32
33
# File 'lib/ecb_exchange_rates_api/result.rb', line 27

def method_missing(method_name, *arguments, &block)
  if @data.respond_to?(method_name)
    @data.send(method_name, *arguments, &block)
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/ecb_exchange_rates_api/result.rb', line 8

def data
  @data
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/ecb_exchange_rates_api/result.rb', line 8

def status
  @status
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ecb_exchange_rates_api/result.rb', line 21

def error?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ecb_exchange_rates_api/result.rb', line 17

def success?
  status == 200
end