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) ⇒ Object



36
37
38
# File 'lib/bitgo_client/v2.rb', line 36

def address(wallet_id, address, coin_code: :tbtc)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/address/#{address}")
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) ⇒ Object



32
33
34
# File 'lib/bitgo_client/v2.rb', line 32

def create_address(wallet_id, coin_code: :tbtc)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/address", method: :post)
end

#send_transaction(wallet_id, payload, coin_code: :tbtc) ⇒ Object



40
41
42
# File 'lib/bitgo_client/v2.rb', line 40

def send_transaction(wallet_id, payload, coin_code: :tbtc)
  client.request("#{express_path}/api/v2/#{coin_code}/wallet/#{wallet_id}/sendcoins", payload, method: :post)
end

#transaction(wallet_id, transaction_id, coin_code: :tbtc) ⇒ Object



54
55
56
# File 'lib/bitgo_client/v2.rb', line 54

def transaction(wallet_id, transaction_id, coin_code: :tbtc)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}/tx/#{transaction_id}")
end

#transactions(wallet_id, coin_code: :tbtc, limit: 25, prev_id: nil, all_tokens: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/bitgo_client/v2.rb', line 44

def transactions(wallet_id, coin_code: :tbtc, 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}")
end

#wallet(wallet_id, coin_code: :tbtc) ⇒ Object



28
29
30
# File 'lib/bitgo_client/v2.rb', line 28

def wallet(wallet_id, coin_code: :tbtc)
  client.request("#{base_path}/#{coin_code}/wallet/#{wallet_id}")
end