Class: Coinigy::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/coinigy/response.rb

Overview

Represents the response from the API

Instance Method Summary collapse

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

#dataObject



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

def data
  return nil if error?
  @json['data']
end

#errorObject



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

Returns:

  • (Boolean)


8
9
10
# File 'lib/coinigy/response.rb', line 8

def error?
  @json.is_a?(Hash) && !@json['err_num'].nil?
end

#notificationsObject



28
29
30
31
# File 'lib/coinigy/response.rb', line 28

def notifications
  return nil if error?
  @json['notifications']
end

#to_jsonObject



33
34
35
# File 'lib/coinigy/response.rb', line 33

def to_json
  @json
end