Class: Oshpark::Order
Constant Summary
collapse
- STATES =
%w| EMPTY NEW RECEIVED PROCESSING SHIPPED CANCELLED |
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Stateful
included
#destroy!, included, #reload!, #save!
Methods included from Model
#dirty?, included, #initialize
Class Method Details
.attrs ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/oshpark/order.rb', line 6
def self.attrs
%w| id board_cost cancellation_reason cancelled_at ordered_at
payment_provider payment_received_at project_name quantity
shipping_address shipping_cost shipping_country
shipping_method shipping_name state total_cost project_id
panel_id coupon_rebate address shipping_rate order_items |
end
|
.create ⇒ Object
18
19
20
|
# File 'lib/oshpark/order.rb', line 18
def self.create
self.from_json(Oshpark::client.create_order['order'])
end
|
Instance Method Details
#add_item(order_item, quantity) ⇒ Object
22
23
24
|
# File 'lib/oshpark/order.rb', line 22
def add_item order_item, quantity
reload_with Oshpark::client.add_order_item id, order_item.id, quantity
end
|
#address ⇒ Object
62
63
64
|
# File 'lib/oshpark/order.rb', line 62
def address
Oshpark::Address.from_json @address if @address
end
|
#cancel ⇒ Object
38
39
40
|
# File 'lib/oshpark/order.rb', line 38
def cancel
reload_with Oshpark.client.cancel_order id
end
|
#cancelled_at ⇒ Object
50
51
52
|
# File 'lib/oshpark/order.rb', line 50
def cancelled_at
time_from @cancelled_at
end
|
#checkout ⇒ Object
34
35
36
|
# File 'lib/oshpark/order.rb', line 34
def checkout
reload_with Oshpark.client.checkout_order id
end
|
#order_items ⇒ Object
70
71
72
73
74
|
# File 'lib/oshpark/order.rb', line 70
def order_items
Array(@order_items).map do |order_item|
Oshpark::OrderItem.from_json order_item
end
end
|
#ordered_at ⇒ Object
54
55
56
|
# File 'lib/oshpark/order.rb', line 54
def ordered_at
time_from @ordered_at
end
|
#panel ⇒ Object
42
43
44
|
# File 'lib/oshpark/order.rb', line 42
def panel
Panel.find panel_id
end
|
#payment_received_at ⇒ Object
58
59
60
|
# File 'lib/oshpark/order.rb', line 58
def payment_received_at
time_from @payment_received_at
end
|
#project ⇒ Object
46
47
48
|
# File 'lib/oshpark/order.rb', line 46
def project
Project.find project_id
end
|
#set_address(address) ⇒ Object
26
27
28
|
# File 'lib/oshpark/order.rb', line 26
def set_address address
reload_with Oshpark::client.set_order_address id, address
end
|
#set_shipping_rate(shipping_rate) ⇒ Object
30
31
32
|
# File 'lib/oshpark/order.rb', line 30
def set_shipping_rate shipping_rate
reload_with Oshpark::client.set_order_shipping_rate id, shipping_rate
end
|
#shipping_rate ⇒ Object
66
67
68
|
# File 'lib/oshpark/order.rb', line 66
def shipping_rate
Oshpark::ShippingRate.from_json @shipping_rate if @shipping_rate
end
|