Class: RippleRest::Payments
- Inherits:
-
Object
- Object
- RippleRest::Payments
- Defined in:
- lib/ripple-rest/helpers.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#[](hash) ⇒ Payment
Returns an individual payment.
-
#create(destination_account, destination_amount) ⇒ Payment
Create a Payment object with some field filled.
-
#find_path(destination_account, destination_amount, source_currencies = nil) ⇒ Array<Payment>
Query ‘rippled` for possible payment “paths” through the Ripple Network to deliver the given amount to the specified `destination_account`.
-
#query(options = {}) ⇒ Array<Payment>
Browse historical payments in bulk.
Instance Attribute Details
#account ⇒ Account
105 106 107 |
# File 'lib/ripple-rest/helpers.rb', line 105 def account @account end |
Instance Method Details
#[](hash) ⇒ Payment
Returns an individual payment.
112 113 114 115 |
# File 'lib/ripple-rest/helpers.rb', line 112 def [] hash Payment.new RippleRest .get("v1/accounts/#{account.address}/payments/#{hash}")["payment"] end |
#create(destination_account, destination_amount) ⇒ Payment
Create a Payment object with some field filled.
139 140 141 142 143 144 145 |
# File 'lib/ripple-rest/helpers.rb', line 139 def create destination_account, destination_amount payment = Payment.new payment.account = account payment.destination_account = destination_account.to_s payment.destination_amount = Amount.from_string(destination_amount) payment end |
#find_path(destination_account, destination_amount, source_currencies = nil) ⇒ Array<Payment>
Query ‘rippled` for possible payment “paths” through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ripple-rest/helpers.rb', line 124 def find_path destination_account, destination_amount, source_currencies = nil uri = "v1/accounts/#{account.address}/payments/paths/#{destination_account.to_s}/#{destination_amount.to_s}" if source_currencies cur = source_currencies.join(",") uri += "?source_currencies=#{cur}" end RippleRest.get(uri)["payments"].map(&Payment.method(:new)).each do |i| i.account = account end end |
#query(options = {}) ⇒ Array<Payment>
Browse historical payments in bulk.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ripple-rest/helpers.rb', line 159 def query = {} qs = "" if && .size > 0 qs = "?" + .map { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&') end uri = "v1/accounts/#{account.address}/payments#{qs}" RippleRest.get(uri)["payments"].map do |i| payment = Payment.new(i["payment"]) payment.client_resource_id = i["client_resource_id"] payment end end |