Class: Netether::WalletName
- Inherits:
-
Object
- Object
- Netether::WalletName
- Defined in:
- lib/netether/netether.rb
Overview
The WalletName object represents a Netki Wallet Name object.
Instance Attribute Summary collapse
-
#domain_name ⇒ Object
Returns the value of attribute domain_name.
-
#external_id ⇒ Object
Returns the value of attribute external_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete this WalletName object from the remote service.
-
#get_address(currency) ⇒ Object
Get Address for Existing Currency.
-
#initialize(domain_name, name, wallets = {}, external_id: nil, id: nil) ⇒ WalletName
constructor
:args: domain_name, name, wallets, external_id, id,.
-
#remove_currency(currency) ⇒ Object
Remove a used currency from this wallet name.
-
#save ⇒ Object
Save the currency WalletName object to the remote service.
-
#set_api_opts(api_url, partner_id, api_key) ⇒ Object
:section: Setters.
-
#set_currency_address(currency, address) ⇒ Object
Set the address or URI for the given currency for this wallet name.
-
#used_currencies ⇒ Object
Get Wallet Name Array of Used Currencies.
Constructor Details
#initialize(domain_name, name, wallets = {}, external_id: nil, id: nil) ⇒ WalletName
:args: domain_name, name, wallets, external_id, id,
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/netether/netether.rb', line 75 def initialize(domain_name, name, wallets={}, external_id: nil, id: nil) @domain_name = domain_name @name = name @wallets = wallets.inject({}) do |hsh, (currency, value)| hsh[currency] = value.is_a?(Hash) ? value : { address: value } hsh end @external_id = external_id @id = id end |
Instance Attribute Details
#domain_name ⇒ Object
Returns the value of attribute domain_name.
87 88 89 |
# File 'lib/netether/netether.rb', line 87 def domain_name @domain_name end |
#external_id ⇒ Object
Returns the value of attribute external_id.
87 88 89 |
# File 'lib/netether/netether.rb', line 87 def external_id @external_id end |
#id ⇒ Object
Returns the value of attribute id.
87 88 89 |
# File 'lib/netether/netether.rb', line 87 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
87 88 89 |
# File 'lib/netether/netether.rb', line 87 def name @name end |
Instance Method Details
#delete ⇒ Object
Delete this WalletName object from the remote service
168 169 170 171 172 173 174 175 176 |
# File 'lib/netether/netether.rb', line 168 def delete raise 'Unable to Delete Object that Does Not Exist Remotely' unless @id wn_api_data = { wallet_names: [ { domain_name: @domain_name, id: @id } ] } Netether.process_request(@api_key, @partner_id, "#{@api_url}/v1/partner/walletname", 'DELETE', JSON.dump(wn_api_data)) end |
#get_address(currency) ⇒ Object
Get Address for Existing Currency
92 93 94 |
# File 'lib/netether/netether.rb', line 92 def get_address(currency) @wallets[currency][:address] end |
#remove_currency(currency) ⇒ Object
Remove a used currency from this wallet name
109 110 111 |
# File 'lib/netether/netether.rb', line 109 def remove_currency(currency) @wallets.delete(currency) if @wallets.has_key? currency end |
#save ⇒ Object
Save the currency WalletName object to the remote service
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/netether/netether.rb', line 124 def save wallet_data = [] @wallets.each do |currency, wallet| # NOTE: Unsure if remote service supports storing metadata (params/bip70 req)? wallet_data.push( { currency: currency, wallet_address: wallet[:_raw] ? wallet[:_raw] : wallet[:address] } ) end wn_data = { domain_name: @domain_name, name: @name, wallets: wallet_data, external_id: @external_id || 'null' } wn_api_data = {} wn_api_data['wallet_names'] = [wn_data] if @id wn_data['id'] = @id response = Netether.process_request(@api_key, @partner_id, "#{@api_url}/v1/partner/walletname", 'PUT', JSON.dump(wn_api_data)) else response = Netether.process_request(@api_key, @partner_id, "#{@api_url}/v1/partner/walletname", 'POST', JSON.dump(wn_api_data)) end unless @id response['wallet_names'].each do |wn| if (response['success'] && wn['domain_name'] == @domain_name && wn['name'] == @name) @id = wn['id'] else raise 'Success, but invalid response received!' end end end end |
#set_api_opts(api_url, partner_id, api_key) ⇒ Object
:section: Setters
115 116 117 118 119 |
# File 'lib/netether/netether.rb', line 115 def set_api_opts(api_url, partner_id, api_key) # :nodoc: @api_url = api_url @partner_id = partner_id @api_key = api_key end |
#set_currency_address(currency, address) ⇒ Object
Set the address or URI for the given currency for this wallet name
104 105 106 |
# File 'lib/netether/netether.rb', line 104 def set_currency_address(currency, address) @wallets[currency] = { address: address } end |
#used_currencies ⇒ Object
Get Wallet Name Array of Used Currencies
97 98 99 |
# File 'lib/netether/netether.rb', line 97 def used_currencies @wallets.keys end |