class Bitopro::Client
Constants
- AUTH_HTTP_ACTION
- BASE_URL
Public Class Methods
new()
click to toggle source
# File lib/bitopro/client.rb, line 16 def initialize @config = Bitopro::Config.instance end
Private Instance Methods
build_headers(payload)
click to toggle source
# File lib/bitopro/client.rb, line 86 def build_headers(payload) { "X-BITOPRO-APIKEY": @config.key, "X-BITOPRO-PAYLOAD": payload, "X-BITOPRO-SIGNATURE": signature(payload) }.merge!(tracking_header) end
build_json_body(params:, action:)
click to toggle source
# File lib/bitopro/client.rb, line 69 def build_json_body(params:, action:) body = action == "post" ? params[:body] : { identity: @config.email, nonce: timestamp } body.to_json end
build_payload(json_body)
click to toggle source
# File lib/bitopro/client.rb, line 65 def build_payload(json_body) Base64.strict_encode64(json_body) end
complete_url(url)
click to toggle source
# File lib/bitopro/client.rb, line 22 def complete_url(url) "#{BASE_URL}#{url}" end
get(url, params = {})
click to toggle source
# File lib/bitopro/client.rb, line 49 def get(url, params = {}) begin response = RestClient::Request.execute(method: :get, url: complete_url(url), payload: params, headers: tracking_header, timeout: 10) response_body = response.body rescue => error response_body = error.response end JSON.parse(response_body) end
signature(payload)
click to toggle source
# File lib/bitopro/client.rb, line 78 def signature(payload) OpenSSL::HMAC.hexdigest("SHA384", @config.secret, payload) end
timestamp()
click to toggle source
# File lib/bitopro/client.rb, line 74 def timestamp (Time.now.to_f * 1000).floor end
tracking_header()
click to toggle source
# File lib/bitopro/client.rb, line 82 def tracking_header { "X-BITOPRO-API": "ruby" } end