Class: Coinbase::FundOperation
- Inherits:
-
Object
- Object
- Coinbase::FundOperation
- Defined in:
- lib/coinbase/fund_operation.rb
Overview
A representation of a Fund Operation, which buys funds from the Coinbase platform, and sends then to the developer’s address.
Defined Under Namespace
Modules: Status
Class Method Summary collapse
-
.create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil) ⇒ FundOperation
Creates a new Fund Operation object.
-
.list(wallet_id:, address_id:) ⇒ Enumerable<Coinbase::FundOperation>
Enumerates the fund operation for a given address belonging to a wallet.
Instance Method Summary collapse
-
#address_id ⇒ String
Returns the Address ID that the fund quote was created for.
-
#amount ⇒ Coinbase::CryptoAmount
Returns the amount that the wallet will receive in crypto.
-
#asset ⇒ Coinbase::Asset
Returns the Asset of the Fund Operation.
-
#buy_fee ⇒ Coinbase::FiatAmount
Returns the fee that the wallet’s owner will pay in fiat.
-
#fiat_amount ⇒ Coinbase::FiatAmount
Returns the amount that the wallet’s owner will pay in fiat.
-
#id ⇒ String
Returns the Fund Operation ID.
-
#initialize(model) ⇒ FundOperation
constructor
Returns a new Fund Operation object.
-
#inspect ⇒ String
Same as to_s.
-
#network ⇒ Coinbase::Network
Returns the Network of the Fund Operation.
-
#reload ⇒ Transfer
Reload reloads the Transfer model with the latest version from the server side.
-
#status ⇒ Symbol
Returns the status of the Fund Operation.
-
#to_s ⇒ String
Returns a String representation of the Fund Operation.
-
#transfer_fee ⇒ Coinbase::CryptoAmount
Returns the fee that the wallet’s owner will pay in crypto.
-
#wait!(interval_seconds = 1, timeout_seconds = 60) ⇒ Coinbase::FundOperation
Waits until the Fund Operation is completed or failed by polling the at the given interval.
-
#wallet_id ⇒ String
Returns the Wallet ID that the fund quote was created for.
Constructor Details
#initialize(model) ⇒ FundOperation
Returns a new Fund Operation object. Do not use this method directly. Instead, use Wallet#fund or Address#fund.
96 97 98 99 100 |
# File 'lib/coinbase/fund_operation.rb', line 96 def initialize(model) raise ArgumentError, 'must be a FundOperation' unless model.is_a?(Coinbase::Client::FundOperation) @model = model end |
Class Method Details
.create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil) ⇒ FundOperation
Creates a new Fund Operation object. This takes an optional FundQuote object that can be used to lock in the rate and fees. Without an explicit quote, we will use the current rate and fees.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/coinbase/fund_operation.rb', line 38 def create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil) network = Coinbase::Network.from_id(network) asset = network.get_asset(asset_id) model = Coinbase.call_api do fund_api.create_fund_operation( wallet_id, address_id, { amount: asset.to_atomic_amount(amount).to_i.to_s, asset_id: asset.primary_denomination.to_s, fund_quote_id: quote_id(quote) }.compact ) end new(model) end |
.list(wallet_id:, address_id:) ⇒ Enumerable<Coinbase::FundOperation>
Enumerates the fund operation for a given address belonging to a wallet. The result is an enumerator that lazily fetches from the server, and can be iterated over, converted to an array, etc…
61 62 63 64 65 66 67 |
# File 'lib/coinbase/fund_operation.rb', line 61 def list(wallet_id:, address_id:) Coinbase::Pagination.enumerate( ->(page) { fetch_page(wallet_id, address_id, page) } ) do |fund_operation| new(fund_operation) end end |
Instance Method Details
#address_id ⇒ String
Returns the Address ID that the fund quote was created for.
122 123 124 |
# File 'lib/coinbase/fund_operation.rb', line 122 def address_id @model.address_id end |
#amount ⇒ Coinbase::CryptoAmount
Returns the amount that the wallet will receive in crypto.
134 135 136 |
# File 'lib/coinbase/fund_operation.rb', line 134 def amount @amount ||= CryptoAmount.from_model(@model.crypto_amount) end |
#asset ⇒ Coinbase::Asset
Returns the Asset of the Fund Operation.
128 129 130 |
# File 'lib/coinbase/fund_operation.rb', line 128 def asset amount.asset end |
#buy_fee ⇒ Coinbase::FiatAmount
Returns the fee that the wallet’s owner will pay in fiat.
146 147 148 |
# File 'lib/coinbase/fund_operation.rb', line 146 def buy_fee @buy_fee ||= FiatAmount.from_model(@model.fees.buy_fee) end |
#fiat_amount ⇒ Coinbase::FiatAmount
Returns the amount that the wallet’s owner will pay in fiat.
140 141 142 |
# File 'lib/coinbase/fund_operation.rb', line 140 def fiat_amount @fiat_amount ||= FiatAmount.from_model(@model.fiat_amount) end |
#id ⇒ String
Returns the Fund Operation ID.
104 105 106 |
# File 'lib/coinbase/fund_operation.rb', line 104 def id @model.fund_operation_id end |
#inspect ⇒ String
Same as to_s.
212 213 214 |
# File 'lib/coinbase/fund_operation.rb', line 212 def inspect to_s end |
#network ⇒ Coinbase::Network
Returns the Network of the Fund Operation.
110 111 112 |
# File 'lib/coinbase/fund_operation.rb', line 110 def network @network ||= Coinbase::Network.from_id(@model.network_id) end |
#reload ⇒ Transfer
Reload reloads the Transfer model with the latest version from the server side.
164 165 166 167 168 169 170 |
# File 'lib/coinbase/fund_operation.rb', line 164 def reload @model = Coinbase.call_api do fund_api.get_fund_operation(wallet_id, address_id, id) end self end |
#status ⇒ Symbol
Returns the status of the Fund Operation.
158 159 160 |
# File 'lib/coinbase/fund_operation.rb', line 158 def status @model.status end |
#to_s ⇒ String
Returns a String representation of the Fund Operation.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/coinbase/fund_operation.rb', line 195 def to_s Coinbase.pretty_print_object( self.class, id: id, network_id: network.id, wallet_id: wallet_id, address_id: address_id, status: status, crypto_amount: amount, fiat_amount: fiat_amount, buy_fee: buy_fee, transfer_fee: transfer_fee ) end |
#transfer_fee ⇒ Coinbase::CryptoAmount
Returns the fee that the wallet’s owner will pay in crypto.
152 153 154 |
# File 'lib/coinbase/fund_operation.rb', line 152 def transfer_fee @transfer_fee ||= CryptoAmount.from_model(@model.fees.transfer_fee) end |
#wait!(interval_seconds = 1, timeout_seconds = 60) ⇒ Coinbase::FundOperation
Waits until the Fund Operation is completed or failed by polling the at the given interval.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/coinbase/fund_operation.rb', line 177 def wait!(interval_seconds = 1, timeout_seconds = 60) start_time = Time.now loop do reload return self if terminal_state? raise Timeout::Error, 'Fund Operation timed out' if Time.now - start_time > timeout_seconds self.sleep interval_seconds end self end |
#wallet_id ⇒ String
Returns the Wallet ID that the fund quote was created for.
116 117 118 |
# File 'lib/coinbase/fund_operation.rb', line 116 def wallet_id @model.wallet_id end |