Module: ApiHelpers::ClassMethods
- Defined in:
- lib/sila-ruby/api_helpers.rb
Overview
CLASS-METHODS ================================
Instance Method Summary collapse
-
#sila_post_signed(api_group, header = {}, message = {}, params = {}, user_key, business_key) ⇒ Object
——————————————– SILA-POST-SIGNED ————————— ——————————————–.
-
#sila_uri ⇒ Object
——————————————– SILA-URI ———————————– ——————————————–.
Instance Method Details
#sila_post_signed(api_group, header = {}, message = {}, params = {}, user_key, business_key) ⇒ Object
SILA-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 69 70 71 72 73 |
# File 'lib/sila-ruby/api_helpers.rb', line 39 def sila_post_signed(api_group, header={}, ={}, params={}, user_key, business_key) # Set the post URL url = "#{sila_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: } 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 # Sign the business request unless business_key.nil? business_key = Eth::Key.new priv: business_key business_signature = sila_personal_sign(business_key, bodyJSON) end # Post to the API endpoint begin response = HTTParty.post(url, { "body": bodyJSON, "headers": { "authsignature": auth_signature, "usersignature": user_signature, "businesssignature": business_signature }}) res_hash(response) rescue => e e.inspect end end |
#sila_uri ⇒ Object
SILA-URI ———————————–
32 33 34 |
# File 'lib/sila-ruby/api_helpers.rb', line 32 def sila_uri SilaRuby.configuration.env == 'production' ? 'https://api.silamoney.com' : 'https://sandbox.silamoney.com' end |