Class: Coinbase::User

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/user.rb

Overview

A representation of a User. Users have Wallets, which can hold balances of Assets. Access the default User through Coinbase#default_user.

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ User

Returns a new User object. Do not use this method directly. Instead, use Coinbase#default_user.

Parameters:



12
13
14
# File 'lib/coinbase/user.rb', line 12

def initialize(model)
  @model = model
end

Instance Method Details

#create_wallet(create_wallet_options = {}) ⇒ Coinbase::Wallet

Creates a new Wallet belonging to the User.

Parameters:

  • network_id (String)

    (Optional) the ID of the blockchain network. Defaults to ‘base-sepolia’.

Returns:



25
26
27
28
29
30
31
# File 'lib/coinbase/user.rb', line 25

def create_wallet(create_wallet_options = {})
  # For ruby 2.7 compatibility we cannot pass in keyword args when the create wallet
  # options is empty
  return Wallet.create if create_wallet_options.empty?

  Wallet.create(**create_wallet_options)
end

#idString

Returns the User ID.

Returns:

  • (String)

    the User ID



18
19
20
# File 'lib/coinbase/user.rb', line 18

def id
  @model.id
end

#import_wallet(data) ⇒ Coinbase::Wallet

Imports a Wallet belonging to the User.

Parameters:

Returns:



36
37
38
# File 'lib/coinbase/user.rb', line 36

def import_wallet(data)
  Wallet.import(data)
end

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the User



61
62
63
# File 'lib/coinbase/user.rb', line 61

def inspect
  to_s
end

#to_sString

Returns a string representation of the User.

Returns:

  • (String)

    a string representation of the User



55
56
57
# File 'lib/coinbase/user.rb', line 55

def to_s
  "Coinbase::User{user_id: '#{id}'}"
end

#wallet(wallet_id) ⇒ Coinbase::Wallet

Returns the Wallet with the given ID.

Parameters:

  • wallet_id (String)

    the ID of the Wallet

Returns:



49
50
51
# File 'lib/coinbase/user.rb', line 49

def wallet(wallet_id)
  Wallet.fetch(wallet_id)
end

#walletsEnumerator<Coinbase::Wallet>

Enumerates the Wallets belonging to the User.

Returns:



42
43
44
# File 'lib/coinbase/user.rb', line 42

def wallets
  Wallet.list
end