Class: Deribit::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/deribit/http.rb

Overview

HTTP API adapter

Instance Method Summary collapse

Constructor Details

#initialize(host, key: nil, secret: nil, debug: false, raise_error: true) ⇒ Http

Returns a new instance of Http.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/deribit/http.rb', line 6

def initialize(host, key: nil, secret: nil, debug: false, raise_error: true)
  @connection = Faraday::Connection.new(url: http_url(host)) do |f|
    f.request :json
    f.use Deribit::Authentication, key, secret
    f.response :mashify
    f.response :json
    f.use Faraday::Response::RaiseError if raise_error
    f.response :detailed_logger if debug
    f.adapter Faraday.default_adapter
  end
end

Instance Method Details

#get(uri, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/deribit/http.rb', line 18

def get(uri, params = {})
  response = @connection.get path(uri), params

  # TODO: move to middleware
  # raise response.error unless response.error
  # raise response.body.message unless response.body.success

  body = response.body
  body.result
end

#post(uri, params) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/deribit/http.rb', line 29

def post(uri, params)
  response = @connection.post path(uri), params

  # TODO: move to middleware
  raise response.message unless response.success?
  raise response.body.message unless response.body.success

  response.body.result || response.body.success?
end