Class: Giftrocket::Order
- Inherits:
-
Object
- Object
- Giftrocket::Order
- Defined in:
- lib/giftrocket/order.rb
Instance Attribute Summary collapse
-
#external_id ⇒ Object
Returns the value of attribute external_id.
-
#gifts ⇒ Object
Returns the value of attribute gifts.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payment ⇒ Object
Returns the value of attribute payment.
-
#sender ⇒ Object
Returns the value of attribute sender.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(attributes) ⇒ Order
Returns a new instance of Order.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/giftrocket/order.rb', line 6 def initialize(attributes) attributes = attributes.with_indifferent_access self.id = attributes[:id] self.external_id = attributes[:external_id] self.gifts = attributes[:gifts].map do |gift_attributes| Gift.new(gift_attributes) end self.payment = Giftrocket::Payment.new(attributes[:payment]) self.sender = Giftrocket::User.new(attributes[:sender]) end |
Instance Attribute Details
#external_id ⇒ Object
Returns the value of attribute external_id.
4 5 6 |
# File 'lib/giftrocket/order.rb', line 4 def external_id @external_id end |
#gifts ⇒ Object
Returns the value of attribute gifts.
4 5 6 |
# File 'lib/giftrocket/order.rb', line 4 def gifts @gifts end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/giftrocket/order.rb', line 4 def id @id end |
#payment ⇒ Object
Returns the value of attribute payment.
4 5 6 |
# File 'lib/giftrocket/order.rb', line 4 def payment @payment end |
#sender ⇒ Object
Returns the value of attribute sender.
4 5 6 |
# File 'lib/giftrocket/order.rb', line 4 def sender @sender end |
Class Method Details
.create!(data) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/giftrocket/order.rb', line 18 def self.create!(data) raise Giftrocket::Error.new("funding_source_id required") if data[:funding_source_id] == nil response = Giftrocket::Request.post 'orders', body: data.merge(Giftrocket.).to_json, headers: { 'Content-Type' => 'application/json' } Giftrocket::Order.new(response[:order]) end |
.list(filters = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/giftrocket/order.rb', line 28 def self.list(filters={}) Giftrocket::Request.get( 'orders', query: filters.merge(Giftrocket.), format: 'json' )[:orders].map do |order_attributes| Giftrocket::Order.new(order_attributes) end end |
.retrieve(id) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/giftrocket/order.rb', line 38 def self.retrieve(id) response = Giftrocket::Request.get "orders/#{id}", query: Giftrocket., format: 'json' Giftrocket::Order.new(response[:order]) end |