Class: Coinigy::Response
- Inherits:
-
Object
- Object
- Coinigy::Response
- Defined in:
- lib/coinigy/response.rb
Overview
Represents the response from the API
Instance Method Summary collapse
- #data ⇒ Object
- #error ⇒ Object
- #error? ⇒ Boolean
-
#initialize(body) ⇒ Response
constructor
A new instance of Response.
- #notifications ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(body) ⇒ Response
Returns a new instance of Response
4 5 6 |
# File 'lib/coinigy/response.rb', line 4 def initialize(body) @json = Yajl::Parser.parse(body) end |
Instance Method Details
#data ⇒ Object
23 24 25 26 |
# File 'lib/coinigy/response.rb', line 23 def data return nil if error? @json['data'] end |
#error ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/coinigy/response.rb', line 12 def error return nil unless error? number, method_id, instance = @json['err_num'].split('-') { number: number, method_id: method_id, instance: instance, message: @json['err_msg'] } end |
#error? ⇒ Boolean
8 9 10 |
# File 'lib/coinigy/response.rb', line 8 def error? @json.is_a?(Hash) && !@json['err_num'].nil? end |
#notifications ⇒ Object
28 29 30 31 |
# File 'lib/coinigy/response.rb', line 28 def notifications return nil if error? @json['notifications'] end |
#to_json ⇒ Object
33 34 35 |
# File 'lib/coinigy/response.rb', line 33 def to_json @json end |