Class: BitgoClient::V2

Inherits:
Object
  • Object
show all
Defined in:
lib/bitgo_client/v2.rb

Constant Summary collapse

ENV_PROD =
"prod"
ENV_TEST =
"test"
PATH_PROD =
"https://www.bitgo.com/api/v2"
PATH_TEST =
"https://test.bitgo.com/api/v2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, env: ENV_TEST, express_path: "http://localhost:3080") ⇒ V2

Returns a new instance of V2.



14
15
16
17
18
# 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

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



12
13
14
# File 'lib/bitgo_client/v2.rb', line 12

def access_token
  @access_token
end

#envObject (readonly)

Returns the value of attribute env.



12
13
14
# File 'lib/bitgo_client/v2.rb', line 12

def env
  @env
end

#express_pathObject (readonly)

Returns the value of attribute express_path.



12
13
14
# File 'lib/bitgo_client/v2.rb', line 12

def express_path
  @express_path
end

Instance Method Details

#address(wallet_id, address, coin_code: :tbtc, logger: nil) ⇒ Object



32
33
34
# 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_pathObject



20
21
22
# File 'lib/bitgo_client/v2.rb', line 20

def base_path
  env == ENV_PROD ? PATH_PROD : PATH_TEST
end

#clientObject



24
25
26
# 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) ⇒ Object



28
29
30
# 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) ⇒ Object



36
37
38
# 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) ⇒ Object



40
41
42
# 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) ⇒ Object



44
45
46
47
48
49
50
51
# 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) ⇒ Object



63
64
65
# 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) ⇒ Object



53
54
55
56
57
58
59
60
61
# 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) ⇒ Object



67
68
69
70
71
72
73
74
75
# 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) ⇒ Object



77
78
79
80
81
# 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