Class: OpenTransact::Asset
- Inherits:
-
Object
- Object
- OpenTransact::Asset
- Defined in:
- lib/opentransact/asset.rb
Overview
The Asset is the most important concept in OpenTransact. It represents an asset type.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#transaction_url ⇒ Object
Returns the value of attribute transaction_url.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #available_balance ⇒ Object
- #balance ⇒ Object
-
#info ⇒ Object
Load meta data about asset from server.
-
#initialize(url, options = {}) ⇒ Asset
constructor
A new instance of Asset.
- #name ⇒ Object
-
#transfer(amount, to, memo = nil) ⇒ Object
Perform a transfer (payment).
-
#transfer_url(amount, to, memo, options = {}) ⇒ Object
Create a redirect url for a simple web payment.
Constructor Details
#initialize(url, options = {}) ⇒ Asset
Returns a new instance of Asset.
6 7 8 9 10 11 |
# File 'lib/opentransact/asset.rb', line 6 def initialize(url,={}) @url = url @transaction_url = [:transaction_url]||@url @client = [:client] @options = ||{} end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/opentransact/asset.rb', line 4 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/opentransact/asset.rb', line 4 def @options end |
#transaction_url ⇒ Object
Returns the value of attribute transaction_url.
4 5 6 |
# File 'lib/opentransact/asset.rb', line 4 def transaction_url @transaction_url end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/opentransact/asset.rb', line 4 def url @url end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/opentransact/asset.rb', line 43 def [](key) @options[key] if @options end |
#available_balance ⇒ Object
39 40 41 |
# File 'lib/opentransact/asset.rb', line 39 def available_balance @balance ||= @options["available_balance"] || info["available_balance"] end |
#balance ⇒ Object
35 36 37 |
# File 'lib/opentransact/asset.rb', line 35 def balance @balance ||= @options["balance"] || info["balance"] end |
#info ⇒ Object
Load meta data about asset from server
48 49 50 |
# File 'lib/opentransact/asset.rb', line 48 def info @info ||= client.try(:get, transaction_url)||{} end |
#name ⇒ Object
31 32 33 |
# File 'lib/opentransact/asset.rb', line 31 def name @name ||= @options["name"] || info["name"] end |
#transfer(amount, to, memo = nil) ⇒ Object
Perform a transfer (payment)
@asset.transfer 12, "[email protected]", "For implementing shopping cart"
27 28 29 |
# File 'lib/opentransact/asset.rb', line 27 def transfer(amount,to,memo=nil) client.post(transaction_url,{:amount=>amount,:to=>to,:memo=>memo}) if client end |
#transfer_url(amount, to, memo, options = {}) ⇒ Object
Create a redirect url for a simple web payment
redirect_to @asset.transfer_url 12, "[email protected]", "For implementing shopping cart"
17 18 19 20 21 |
# File 'lib/opentransact/asset.rb', line 17 def transfer_url(amount,to,memo,={}) uri = URI.parse(transaction_url) uri.query = URI.escape("amount=#{amount}&to=#{to}&memo=#{memo}") uri.to_s end |