class BitgoClient::V2

Constants

ENV_PROD
ENV_TEST
PATH_PROD
PATH_TEST

Attributes

access_token[R]
env[R]
express_path[R]

Public Class Methods

new(access_token, env: ENV_TEST, express_path: "http://localhost:3080") click to toggle source
# File lib/bitgo_client/v2.rb, line 14
def initialize(access_token, env: ENV_TEST, express_path: "http://localhost:3080")
  @access_token = access_token
  @env          = env
  @express_path = express_path
end

Public Instance Methods

address(wallet_id, address, coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 32
def address(wallet_id, address, coin_code: :tbtc, logger: nil)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/address/#{address}", logger: logger)
end
base_path() click to toggle source
# File lib/bitgo_client/v2.rb, line 20
def base_path
  env == ENV_PROD ? PATH_PROD : PATH_TEST
end
client() click to toggle source
# File lib/bitgo_client/v2.rb, line 24
def client
  BitgoClient::Client.new(access_token)
end
create_address(wallet_id, coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 28
def create_address(wallet_id, coin_code: :tbtc, logger: nil)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/address", method: :post, logger: logger)
end
fee(coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 36
def fee(coin_code: :tbtc, logger: nil)
  client.request("#{base_path}/#{coin_code}/tx/fee", logger: logger)
end
get_transfer(wallet_id, transfer_id, coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 40
def get_transfer(wallet_id, transfer_id, coin_code: :tbtc, logger: nil)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/transfer/#{transfer_id}", logger: logger)
end
send_transaction(wallet_id, payload, coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 44
def send_transaction(wallet_id, payload, coin_code: :tbtc, logger: nil)
  client.request(
    "#{express_path}/api/v2/#{coin_code}/wallet/#{wallet_id}/sendcoins",
    payload,
    method: :post,
    logger: logger
  )
end
transaction(wallet_id, transaction_id, coin_code: :tbtc, logger: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 63
def transaction(wallet_id, transaction_id, coin_code: :tbtc, logger: nil)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/tx/#{transaction_id}", logger: logger)
end
transactions(wallet_id, coin_code: :tbtc, logger: nil, limit: 25, prev_id: nil, all_tokens: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 53
def transactions(wallet_id, coin_code: :tbtc, logger: nil, limit: 25, prev_id: nil, all_tokens: nil)
  query_string = build_query_string(
    limit:     limit,
    prevId:    prev_id,
    allTokens: all_tokens
  )

  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/tx?#{query_string}", logger: logger)
end
transfers(wallet_id, coin_code: :tbtc, logger: nil, limit: 25, prev_id: nil, all_tokens: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 67
def transfers(wallet_id, coin_code: :tbtc, logger: nil, limit: 25, prev_id: nil, all_tokens: nil)
  query_string = build_query_string(
    limit:     limit,
    prevId:    prev_id,
    allTokens: all_tokens
  )

  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/transfer?#{query_string}", logger: logger)
end
wallet(wallet_id, coin_code: :tbtc, logger: nil, all_tokens: nil) click to toggle source
# File lib/bitgo_client/v2.rb, line 77
def wallet(wallet_id, coin_code: :tbtc, logger: nil, all_tokens: nil)
  query_string = build_query_string(allTokens: all_tokens)

  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}?#{query_string}", logger: logger)
end

Private Instance Methods

build_query_string(hash) click to toggle source
# File lib/bitgo_client/v2.rb, line 85
def build_query_string(hash)
  uri = Addressable::URI.new
  uri.query_values = hash.delete_if { |k, v| v.nil? }
  uri.query
end