module CryptoWallet
Constants
- VERSION
Public Class Methods
method_missing(m, *args, &block)
click to toggle source
# File lib/crypto_wallet.rb, line 27 def self.method_missing(m, *args, &block) method_name = m.to_s params = get_params(args.first) self.api_call([method_name, params]) end
set_options(args = {})
click to toggle source
# File lib/crypto_wallet.rb, line 14 def self.set_options(args = {}) # initialize BlockIo @api_key = args[:api_key] @pin = args[:pin] # @encryptionKey = Helper.pinToAesKey(@pin) if !@pin.nil? @conn_pool = ConnectionPool.new(size: 5, timeout: 300) { HTTPClient.new } @version = args[:version] || 2 # default version is 2 self.api_call(['get_balances',""]) end
Private Class Methods
api_call(endpoint)
click to toggle source
# File lib/crypto_wallet.rb, line 38 def self.api_call(endpoint) body = nil @conn_pool.with do |hc| # prevent initiation of HTTPClients every time we make this call, use a connection_pool # puts endpoint hc.ssl_config.ssl_version = :TLSv1 response = hc.get("#{@base_url.gsub('API_CALL',endpoint[0]).gsub('VERSION', 'v'+@version.to_s) + @api_key}", endpoint[1]) begin body = JSON.parse(response.body) raise Exception.new(body['result']) if !body['status'].eql?('1') rescue raise Exception.new('Unknown error occurred. Please report this.') end end body end
get_params(args = {})
click to toggle source
# File lib/crypto_wallet.rb, line 62 def self.get_params(args = {}) # construct the parameter string params = "" args = {} if args.nil? args.each do |k,v| params += '&' if params.length > 0 params += "#{k.to_s}=#{v.to_s}" end return params end