Class: Netki::WalletName
- Inherits:
-
Object
- Object
- Netki::WalletName
- Defined in:
- lib/netki/netki.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,
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/netki/netki.rb', line 90 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.
102 103 104 |
# File 'lib/netki/netki.rb', line 102 def domain_name @domain_name end |
#external_id ⇒ Object
Returns the value of attribute external_id.
102 103 104 |
# File 'lib/netki/netki.rb', line 102 def external_id @external_id end |
#id ⇒ Object
Returns the value of attribute id.
102 103 104 |
# File 'lib/netki/netki.rb', line 102 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
102 103 104 |
# File 'lib/netki/netki.rb', line 102 def name @name end |
Instance Method Details
#delete ⇒ Object
Delete this WalletName object from the remote service
181 182 183 184 185 186 187 188 189 |
# File 'lib/netki/netki.rb', line 181 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}] } Netki.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
107 108 109 |
# File 'lib/netki/netki.rb', line 107 def get_address(currency) @wallets[currency][:address] end |
#remove_currency(currency) ⇒ Object
Remove a used currency from this wallet name
124 125 126 |
# File 'lib/netki/netki.rb', line 124 def remove_currency(currency) @wallets.delete(currency) if @wallets.has_key? currency end |
#save ⇒ Object
Save the currency WalletName object to the remote service
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 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/netki/netki.rb', line 139 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 = Netki.process_request(@api_key, @partner_id, "#{@api_url}/v1/partner/walletname", 'PUT', JSON.dump(wn_api_data)) else response = Netki.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
130 131 132 133 134 |
# File 'lib/netki/netki.rb', line 130 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
119 120 121 |
# File 'lib/netki/netki.rb', line 119 def set_currency_address(currency, address) @wallets[currency][:address] = address end |
#used_currencies ⇒ Object
Get Wallet Name Array of Used Currencies
112 113 114 |
# File 'lib/netki/netki.rb', line 112 def used_currencies @wallets.keys end |