Class: ECBExchangeRatesApi::Result
- Inherits:
-
Object
- Object
- ECBExchangeRatesApi::Result
- Defined in:
- lib/ecb_exchange_rates_api/result.rb
Overview
Wrapper for HTTParty response object
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(data, status: 200) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/ecb_exchange_rates_api/result.rb', line 8 def data @data end |
#status ⇒ Object (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
21 22 23 |
# File 'lib/ecb_exchange_rates_api/result.rb', line 21 def error? !success? end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/ecb_exchange_rates_api/result.rb', line 17 def success? status == 200 end |