Class: Giftrocket::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/giftrocket/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute external_id.



4
5
6
# File 'lib/giftrocket/order.rb', line 4

def external_id
  @external_id
end

#giftsObject

Returns the value of attribute gifts.



4
5
6
# File 'lib/giftrocket/order.rb', line 4

def gifts
  @gifts
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/giftrocket/order.rb', line 4

def id
  @id
end

#paymentObject

Returns the value of attribute payment.



4
5
6
# File 'lib/giftrocket/order.rb', line 4

def payment
  @payment
end

#senderObject

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

Raises:



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.default_options).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.default_options),
    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.default_options,
                                     format: 'json'

  Giftrocket::Order.new(response[:order])
end