Module: Mexbt::Client
Constant Summary collapse
- SSL_VERSION =
:TLSv1_2
Instance Method Summary collapse
- #auth_params ⇒ Object
- #call(path, params = {}) ⇒ Object
- #call_data(path) ⇒ Object
- #private_key ⇒ Object
- #public_key ⇒ Object
- #url(path) ⇒ Object
- #user_id ⇒ Object
Instance Method Details
#auth_params ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mexbt/client.rb', line 25 def auth_params if public_key.nil? || private_key.nil? raise "You must configure your API keys!" end if user_id.nil? raise "You must configure your user_id!" end nonce = (Time.now.to_f*10000).to_i { apiKey: public_key, apiNonce: nonce, apiSig: OpenSSL::HMAC.hexdigest('sha256', private_key, "#{nonce}#{user_id}#{public_key}").upcase } end |
#call(path, params = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mexbt/client.rb', line 40 def call(path, params={}) payload = params params.merge!(auth_params) if self.respond_to?(:private?) res = Request.execute(method: :post, url: url(path), payload: payload.to_json, ssl_version: SSL_VERSION) if res.length === 0 raise "Empty response from API" end json_response = ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(res)) if json_response[:isAccepted] json_response else raise json_response[:rejectReason] end end |
#call_data(path) ⇒ Object
55 56 57 58 |
# File 'lib/mexbt/client.rb', line 55 def call_data(path) res = Request.execute(method: :get, url: "https://data.mexbt.com/#{path}", ssl_version: SSL_VERSION) ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(res)) end |
#private_key ⇒ Object
17 18 19 |
# File 'lib/mexbt/client.rb', line 17 def private_key @private_key || Mexbt.private_key end |
#public_key ⇒ Object
13 14 15 |
# File 'lib/mexbt/client.rb', line 13 def public_key @public_key || Mexbt.public_key end |
#url(path) ⇒ Object
9 10 11 |
# File 'lib/mexbt/client.rb', line 9 def url(path) "#{endpoint()}/v1/#{path}" end |
#user_id ⇒ Object
21 22 23 |
# File 'lib/mexbt/client.rb', line 21 def user_id @user_id || Mexbt.user_id end |