Class: BlockstreamSatellite::Order
- Inherits:
-
Object
- Object
- BlockstreamSatellite::Order
- Defined in:
- lib/blockstream_satellite/order.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
- #bump(bid_increase) ⇒ Object
-
#initialize(attributes) ⇒ Order
constructor
A new instance of Order.
- #pay ⇒ Object
- #payreq ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Order
Returns a new instance of Order.
12 13 14 |
# File 'lib/blockstream_satellite/order.rb', line 12 def initialize(attributes) self.attributes = attributes.with_indifferent_access end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/blockstream_satellite/order.rb', line 10 def attributes @attributes end |
#file ⇒ Object
Returns the value of attribute file.
10 11 12 |
# File 'lib/blockstream_satellite/order.rb', line 10 def file @file end |
Class Method Details
.create(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/blockstream_satellite/order.rb', line 27 def self.create() if path = .delete(:path) [:file] = UploadIO.new([:file], 'text/plain') # TODO: get rid of this content type here [:file] = File.open(path) end [:bid] ||= ([:file] || [:message]).size * 51 # default price response = BlockstreamSatellite.client.post('order', ) if response.success? Order.new(response.body).tap { |o| o.file = [:file] } else response end end |
Instance Method Details
#bump(bid_increase) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/blockstream_satellite/order.rb', line 65 def bump(bid_increase) response = BlockstreamSatellite.client.post("order/#{self.uuid}/bump", bid_increase: bid_increase) do |req| req.headers['X-Auth-Token'] = self.auth_token end if response.success? self.attributes['lightning_invoice'] = response['lightning_invoice'] else response end end |
#pay ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/blockstream_satellite/order.rb', line 56 def pay response = BlockstreamSatellite.client.pay(self.payreq) if response.payment_error == '' self.refresh else response end end |
#payreq ⇒ Object
23 24 25 |
# File 'lib/blockstream_satellite/order.rb', line 23 def payreq lightning_invoice['payreq'] end |
#refresh ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/blockstream_satellite/order.rb', line 47 def refresh response = BlockstreamSatellite.client.get("order/#{self.uuid}") do |req| req.headers['X-Auth-Token'] = self.auth_token end if response.success? self.attributes.merge!(response.body) end end |