Class: Btcmrb::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/btcmrb/client.rb

Constant Summary collapse

BTCM_ACCESS_KEY =
ENV['BTCM_ACCESS_KEY']
BTCM_SECRET_KEY =
ENV['BTCM_SECRET']
DC_BTCM_ACCESS_KEY =
Base64.decode64(BTCM_ACCESS_KEY)
DC_BTCM_SECRET_KEY =
Base64.decode64(BTCM_SECRET_KEY)
BASE_URI =
'https://api.btcmarkets.net'

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



15
16
# File 'lib/btcmrb/client.rb', line 15

def initialize
end

Instance Method Details

#send_request(object) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/btcmrb/client.rb', line 18

def send_request(object)
  if object[:auth] == false
    # Hooray! We can write less code, authentication is not necessary.
    response = send(object[:uri])
  else
    # Extra work is necessary, we need to prepare and sign the request
    timestamp = create_timestamp
    options = {
      :uri => object[:uri],
      :timestamp => timestamp,
      :body => object[:body]
    }
    request = format_request(options)
    signature = sign_request(request)
    encoded_signature = Base64.encode64(signature).to_s.gsub("\n",'')

    send(object[:uri],
      { :method => object[:verb],
        :authentication => object[:auth],
        :timestamp => timestamp,
        :encoded_signature => encoded_signature,
        :body => object[:body]
    })
  end

end