Class: Lce::Order
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Lce::Order
- Includes:
- Hashie::Extensions::Coercion
- Defined in:
- lib/lce/order.rb
Class Method Summary collapse
- .all(page = nil) ⇒ Object
- .find(id) ⇒ Object
- .labels_for(id) ⇒ Object
- .place(params) ⇒ Object
- .tracking_for(id) ⇒ Object
Instance Method Summary collapse
Class Method Details
.all(page = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lce/order.rb', line 16 def all(page = nil) if page page = 1 if page <= 0 = {page: page} end response = Lce.client.get('orders', nil, nil, nil , ) response.map! do |q| new(q) end end |
.find(id) ⇒ Object
27 28 29 30 |
# File 'lib/lce/order.rb', line 27 def find(id) response = Lce.client.get('orders', id) new(response) end |
.labels_for(id) ⇒ Object
32 33 34 35 |
# File 'lib/lce/order.rb', line 32 def labels_for(id) order = new(id: id) order.labels end |
.place(params) ⇒ Object
11 12 13 14 |
# File 'lib/lce/order.rb', line 11 def place(params) response = Lce.client.post('orders', {order: params}) new(response) end |
.tracking_for(id) ⇒ Object
37 38 39 40 |
# File 'lib/lce/order.rb', line 37 def tracking_for(id) order = new(id: id) order.tracking end |
Instance Method Details
#labels ⇒ Object
43 44 45 |
# File 'lib/lce/order.rb', line 43 def labels @labels ||= Lce.client.get('orders', id, 'labels', 'pdf') end |
#tracking ⇒ Object
54 55 56 57 58 |
# File 'lib/lce/order.rb', line 54 def tracking Lce.client.get('orders', id, 'tracking').map! do |t| Hashie::Mash.new(t) end end |
#write_labels(name = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/lce/order.rb', line 47 def write_labels(name = nil) name = (name.is_a?(String)) ? name : "labels-#{id}.pdf" File.open(name, "wb") do |f| f.write(labels) end end |