Created
January 23, 2019 22:25
-
-
Save aguayma/5bf6da8c3d3040e194e0ae4c3a8fa28f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'openssl' | |
require 'json' | |
require 'byebug' | |
class WyreApi | |
ACCOUNT_ID = '**-*************' | |
API_KEY = '****-****-****-****' | |
SEC_KEY = '****-****-****-****' | |
API_URL = 'https://api.testwyre.com' | |
def create_account options | |
api_post '/accounts', options | |
end | |
private | |
def api_post path, post_data = {} | |
params = { | |
'timestamp' => (Time.now.to_i * 1000).to_s | |
} | |
url = API_URL + path + '?' + URI.encode_www_form(params) | |
headers = { | |
'X-Api-Key' => API_KEY, | |
'X-Api-Signature' => calc_auth_sig_hash(url + post_data.to_json.to_s), | |
'X-Api-Version' => '2' | |
} | |
uri = URI API_URL | |
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
http.request_post(url, post_data.to_json.to_s, headers) do |res| | |
p res.methods - Object.methods | |
response = JSON.parse res.body | |
p response | |
raise response['message'] if res.code != '200' | |
return response | |
end | |
end | |
end | |
def calc_auth_sig_hash url_body | |
digest = OpenSSL::Digest.new('sha256') | |
return OpenSSL::HMAC.hexdigest digest, url_body, SEC_KEY | |
end | |
end | |
api = WyreApi.new | |
info = { | |
'type'=>'INDIVIDUAL', | |
'country'=>'US', | |
'profileFields'=>[ | |
{ | |
"fieldId"=> "individualLegalName", | |
"value"=>"Mario Tester" | |
}, | |
{ | |
"fieldId"=>"individualEmail", | |
"value"=>"mario@cblocks.io" | |
}, | |
{ | |
"fieldId"=>"individualResidenceAddress", | |
"value"=>{ | |
"street1"=>"123 Fake St", | |
"street2"=>"#17 402", | |
"city"=>"Miami Beach", | |
"state"=>"FL", | |
"postalCode"=>"33141", | |
"country"=>"US" | |
} | |
} | |
], | |
'subaccount'=>true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment