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
- .create!(funding_source_id, gifts, external_id = nil, organization_id = nil) ⇒ Object
- .list(filters = {}) ⇒ Object
- .retrieve(id) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(attributes) ⇒ 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!(funding_source_id, gifts, external_id = nil, organization_id = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/giftrocket/order.rb', line 18 def self.create!(funding_source_id, gifts, external_id=nil, organization_id=nil) data_to_post = { funding_source_id: funding_source_id, external_id: external_id, organization_id: organization_id, gifts: gifts }.merge(Giftrocket.) response = Giftrocket::Request.post 'orders', body: data_to_post.to_json, headers: { 'Content-Type' => 'application/json' } Giftrocket::Order.new(response[:order]) end |
.list(filters = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/giftrocket/order.rb', line 33 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
43 44 45 46 47 48 49 |
# File 'lib/giftrocket/order.rb', line 43 def self.retrieve(id) response = Giftrocket::Request.get "orders/#{id}", query: Giftrocket., format: 'json' Giftrocket::Order.new(response[:order]) end |