Module: Bitstamp::Handler

Included in:
Client, Websocket
Defined in:
lib/bitstamp/handler.rb

Instance Method Summary collapse

Instance Method Details

#handle_body(raw_body) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bitstamp/handler.rb', line 5

def handle_body(raw_body)
  body = JSON.parse(raw_body)

  if body.kind_of?(Hash)
    if body.has_key?('error')
      raise ::Bitstamp::Exception::ServiceError.new(body.fetch('error'))
    elsif body.has_key?('status') && body.fetch('status') == 'error'
      raise ::Bitstamp::Exception::ServiceError.new(body.fetch('reason'))
    end
  end

  return body
rescue JSON::ParserError
  raise ::Bitstamp::Exception::InvalidContent.new(raw_body)
end