Module: ApiHelpers::ClassMethods

Defined in:
lib/sila-ruby/api_helpers.rb

Overview

CLASS-METHODS ================================

Instance Method Summary collapse

Instance Method Details

#base_uriObject


BASE-URI ———————————–




32
33
34
# File 'lib/sila-ruby/api_helpers.rb', line 32

def base_uri
  ENV['environment'] == 'production' ? 'https://api.silamoney.com' : 'https://sandbox.silamoney.com'
end

#post_signed(api_group, header = {}, message = {}, params = {}, user_key) ⇒ Object


POST-SIGNED ——————————–




39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sila-ruby/api_helpers.rb', line 39

def post_signed(api_group, header={}, message={}, params={}, user_key)
  # Set the post URL
  url = "#{base_uri}/0.2/#{api_group}"
  # Create the header
  header = header.merge({reference: SecureRandom.uuid, created: Time.now.to_i, auth_handle: SilaRuby.configuration.handle, version: '0.2', crypto: 'ETH'})
  # Put together the body in JSON
  body = {
    header: header,
    message: message
  }
  unless params.nil?
    body = body.merge(params)
  end
  bodyJSON = body.to_json
  # Sign the authorization request
  auth_key = Eth::Key.new priv: SilaRuby.configuration.private_key
  auth_signature = sila_personal_sign(auth_key, bodyJSON)
  # Sign the user request
  unless user_key.nil?
    user_key = Eth::Key.new priv: user_key
    user_signature = sila_personal_sign(user_key, bodyJSON)
  end
  # Post to the API endpoint
  begin
    response = HTTParty.post(url, { "body": bodyJSON, "headers": { "authsignature": auth_signature, "usersignature": user_signature }})
    res_hash(response)
  rescue => e
    e.inspect
  end
end