class GatecoinAPI::Client
Constants
- InvalidCredentials
Attributes
private_key[RW]
public_key[RW]
url[RW]
Public Class Methods
new(public_key:, private_key:, url: GatecoinAPI::TEST_URL)
click to toggle source
# File lib/gatecoin-api/client.rb, line 24 def initialize(public_key:, private_key:, url: GatecoinAPI::TEST_URL) @public_key = public_key @private_key = private_key @url = url end
Public Instance Methods
bank_accounts()
click to toggle source
# File lib/gatecoin-api/client.rb, line 131 def bank_accounts response = connection(sign: true).get('/api/Bank/UserAccounts') parse_response(response) end
connection(sign: false)
click to toggle source
# File lib/gatecoin-api/client.rb, line 186 def connection(sign: false) Faraday.new(connection_options) do |faraday| if sign raise InvalidCredentials unless @public_key && @private_key faraday.use SigningMiddleware, @public_key, @private_key end faraday.response(:logger, GatecoinAPI.logger, GatecoinAPI.logger_options || {}) if GatecoinAPI.logger faraday.adapter :net_http end end
create_quote(currency_to:, amount:, is_amount_in_currency_from: false, reference: nil, label: nil)
click to toggle source
# File lib/gatecoin-api/client.rb, line 137 def create_quote(currency_to:, amount:, is_amount_in_currency_from: false, reference: nil, label: nil) params = { CurrencyTo: currency_to, Amount: amount, IsAmountInCurrencyFrom: is_amount_in_currency_from, } params[:Reference] = reference if reference params[:Label] = label if label response = connection(sign: true).post('/api/Merchant/Payment/Quote') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
documents_status()
click to toggle source
# File lib/gatecoin-api/client.rb, line 90 def documents_status result = {} response = connection(sign: true).get('/api/Account/DocumentID') parsed = parse_response(response) result['DocumentID'] = parsed['status'] response = connection(sign: true).get('/api/Account/DocumentAddress') parsed = parse_response(response) result['DocumentAddress'] = parsed['status'] result end
gateways()
click to toggle source
# File lib/gatecoin-api/client.rb, line 165 def gateways response = connection(sign: true).get('/api/Merchant/Gateway') parse_response(response) end
link_bank_account(bank_name:, label:, account_number:, currency:, holder_name:, city:, country_code:, password:, swift_code: nil, bank_code: nil, branch_name: nil, bank_address: nil, bank_phone: nil, validation_code: nil)
click to toggle source
fails unless documents are verified
# File lib/gatecoin-api/client.rb, line 105 def link_bank_account(bank_name:, label:, account_number:, currency:, holder_name:, city:, country_code:, password:, swift_code: nil, bank_code: nil, branch_name: nil, bank_address: nil, bank_phone: nil, validation_code: nil) params = { BankName: bank_name, Label: label, AccountNumber: account_number, Currency: currency, HolderName: holder_name, City: city, CountryCode: country_code, Password: password, } params[:SwiftCode] = swift_code if swift_code params[:BankCode] = bank_code if bank_code params[:BranchName] = branch_name if branch_name params[:Address] = bank_address if bank_address params[:Phone] = bank_phone if bank_phone params[:ValidationCode] = validation_code if validation_code response = connection(sign: true).post('/api/Bank/UserAccounts') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
login(username:, password:, validation_code: nil)
click to toggle source
# File lib/gatecoin-api/client.rb, line 46 def login(username:, password:, validation_code: nil) params = { UserName: username, Password: password, } params[:ValidationCode] = validation_code if validation_code response = connection(sign: true).post('/api/Auth/Login') do |req| req.body = MultiJson.dump(params) end result = parse_response(response) client = self.class.new(public_key: result['publicKey'], private_key: result['apiKey'], url: url) [client, result] end
parse_response(response)
click to toggle source
# File lib/gatecoin-api/client.rb, line 178 def parse_response(response) result = MultiJson.load(response.body) if (status = result['responseStatus']) && (error_code = status['errorCode']) fail ApiError.new(status['message'], error_code, status) end result end
payments()
click to toggle source
# File lib/gatecoin-api/client.rb, line 171 def payments response = connection(sign: true).get('/api/Merchant/Payment') parse_response(response) end
post_document_address(content:, mime_type: 'image/jpeg')
click to toggle source
# File lib/gatecoin-api/client.rb, line 77 def post_document_address(content:, mime_type: 'image/jpeg') params = { Content: Base64.strict_encode64(content), MimeType: mime_type, } response = connection(sign: true).post('/api/Account/DocumentAddress') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
post_document_id(number:, country:, content:, mime_type: 'image/jpeg')
click to toggle source
# File lib/gatecoin-api/client.rb, line 62 def post_document_id(number:, country:, content:, mime_type: 'image/jpeg') params = { DocumentNumber: number, IssuingCountry: country, Content: Base64.strict_encode64(content), MimeType: mime_type, } response = connection(sign: true).post('/api/Account/DocumentID') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
register_user(email:, password:, is_corporate_account: false, language: 'en', referral_code: nil)
click to toggle source
# File lib/gatecoin-api/client.rb, line 30 def register_user(email:, password:, is_corporate_account: false, language: 'en', referral_code: nil) params = { Email: email, Password: password, IsCorporateAccount: is_corporate_account, language: language, } params[:ReferralCode] = referral_code if referral_code response = connection(sign: true).post('/api/RegisterUser') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
update_gateway(expiry_second: nil, webhook: nil)
click to toggle source
# File lib/gatecoin-api/client.rb, line 153 def update_gateway(expiry_second: nil, webhook: nil) params = {} params[:Webhook] = webhook if webhook params[:ExpirySecond] = expiry_second if expiry_second response = connection(sign: true).put('/api/Merchant/Gateway') do |req| req.body = MultiJson.dump(params) end parse_response(response) end
Private Instance Methods
connection_options()
click to toggle source
# File lib/gatecoin-api/client.rb, line 197 def connection_options { url: @url, ssl: { ca_path: ENV['SSL_CERT_DIR'] || '/etc/ssl/certs', }, headers: { content_type: 'application/json', }, } end