Class: Giftrocket::Order
- Inherits:
-
Object
- Object
- Giftrocket::Order
- Includes:
- HTTParty
- Defined in:
- lib/giftrocket/order.rb
Instance Attribute Summary collapse
-
#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.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/giftrocket/order.rb', line 9 def initialize(attributes) attributes = attributes.with_indifferent_access self.id = attributes[: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
#gifts ⇒ Object
Returns the value of attribute gifts.
7 8 9 |
# File 'lib/giftrocket/order.rb', line 7 def gifts @gifts end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/giftrocket/order.rb', line 7 def id @id end |
#payment ⇒ Object
Returns the value of attribute payment.
7 8 9 |
# File 'lib/giftrocket/order.rb', line 7 def payment @payment end |
#sender ⇒ Object
Returns the value of attribute sender.
7 8 9 |
# File 'lib/giftrocket/order.rb', line 7 def sender @sender end |
Class Method Details
.create!(funding_source_id, gifts_data_array) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/giftrocket/order.rb', line 20 def self.create!(funding_source_id, gifts_data_array) data_to_post = { funding_source_id: funding_source_id, gifts: gifts_data_array }.merge(Giftrocket.) response = post '/', body: data_to_post.to_json, headers: { 'Content-Type' => 'application/json' } if response.success? response_json = JSON.parse(response.body).with_indifferent_access Giftrocket::Order.new(response_json[:order]) else raise Giftrocket::Error.new(response) end end |
.list ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/giftrocket/order.rb', line 35 def self.list response = get '/', query: Giftrocket., format: 'json' if response.success? response_json = JSON.parse(response.body).with_indifferent_access response_json[:orders].map do |order_attributes| Giftrocket::Order.new(order_attributes) end else raise Giftrocket::Error.new(response) end end |
.retrieve(id) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/giftrocket/order.rb', line 47 def self.retrieve(id) response = get "/#{id}", query: Giftrocket., format: 'json' if response.success? response_json = JSON.parse(response.body).with_indifferent_access Giftrocket::Order.new(response_json[:order]) else raise Giftrocket::Error.new(response) end end |