Class: OpenTransact::Asset

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (Asset) initialize(url, options = {})

A new instance of Asset



6
7
8
9
10
11
# File 'lib/opentransact/asset.rb', line 6

def initialize(url,options={})
  @url = url
  @transaction_url = options[:transaction_url]||@url
  @client = options[:client]
  @options = options||{}
end

Instance Attribute Details

- (Object) client

Returns the value of attribute client



4
5
6
# File 'lib/opentransact/asset.rb', line 4

def client
  @client
end

- (Object) options

Returns the value of attribute options



4
5
6
# File 'lib/opentransact/asset.rb', line 4

def options
  @options
end

- (Object) transaction_url

Returns the value of attribute transaction_url



4
5
6
# File 'lib/opentransact/asset.rb', line 4

def transaction_url
  @transaction_url
end

- (Object) url

Returns the value of attribute url



4
5
6
# File 'lib/opentransact/asset.rb', line 4

def url
  @url
end

Instance Method Details

- (Object) [](key)



43
44
45
# File 'lib/opentransact/asset.rb', line 43

def [](key)
  @options[key] if @options
end

- (Object) available_balance



39
40
41
# File 'lib/opentransact/asset.rb', line 39

def available_balance
  @balance ||= @options["available_balance"] || info["available_balance"]
end

- (Object) balance



35
36
37
# File 'lib/opentransact/asset.rb', line 35

def balance
  @balance ||= @options["balance"] || info["balance"]
end

- (Object) info

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

- (Object) name



31
32
33
# File 'lib/opentransact/asset.rb', line 31

def name
  @name ||= @options["name"] || info["name"]
end

- (Object) transfer(amount, to, memo = nil)

Perform a transfer (payment)

@asset.transfer 12, "bob@test.com", "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

- (Object) transfer_url(amount, to, memo, options = {})

Create a redirect url for a simple web payment

redirect_to @asset.transfer_url 12, "bob@test.com", "For implementing shopping cart"


17
18
19
20
21
# File 'lib/opentransact/asset.rb', line 17

def transfer_url(amount,to,memo,options={})
  uri = URI.parse(transaction_url)
  uri.query = URI.escape("amount=#{amount}&to=#{to}&memo=#{memo}")
  uri.to_s
end