Class: Bond::Order
- Inherits:
-
Object
- Object
- Bond::Order
- Defined in:
- lib/bond/order.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#links ⇒ Object
Returns the value of attribute links.
-
#products ⇒ Object
Returns the value of attribute products.
-
#shipping ⇒ Object
Returns the value of attribute shipping.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
- .all(options = {}) ⇒ Array<Bond::Order>
- .create ⇒ Bond::Order
- .find(guid) ⇒ Bond::Order
- .pagination ⇒ Hash
Instance Method Summary collapse
- #add_message(message_hash) ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Order
constructor
A new instance of Order.
- #message_pagination ⇒ Hash
- #messages ⇒ Array<Bond::Message>
- #process ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Order
Returns a new instance of Order.
49 50 51 |
# File 'lib/bond/order.rb', line 49 def initialize(attributes = {}) attributes.each { |name, value| instance_variable_set("@#{name}", value) } end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def created_at @created_at end |
#guid ⇒ Object
Returns the value of attribute guid.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def guid @guid end |
#links ⇒ Object
Returns the value of attribute links.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def links @links end |
#products ⇒ Object
Returns the value of attribute products.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def products @products end |
#shipping ⇒ Object
Returns the value of attribute shipping.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def shipping @shipping end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def status @status end |
#total ⇒ Object
Returns the value of attribute total.
6 7 8 |
# File 'lib/bond/order.rb', line 6 def total @total end |
Class Method Details
.all(options = {}) ⇒ Array<Bond::Order>
11 12 13 14 15 16 17 18 |
# File 'lib/bond/order.rb', line 11 def all( = {}) page = [:page] response = Bond::Connection.connection.get("/orders?page=#{page || 1}") JSON.parse(response.body)['data'].map do |attributes| new(attributes) end end |
.create ⇒ Bond::Order
37 38 39 40 41 42 43 44 45 |
# File 'lib/bond/order.rb', line 37 def create response = Bond::Connection.connection.post('/orders') json = JSON.parse(response.body) Bond::BondError.handle_errors(json) attributes = json['data'] new(attributes) end |
.find(guid) ⇒ Bond::Order
30 31 32 33 34 |
# File 'lib/bond/order.rb', line 30 def find(guid) response = Bond::Connection.connection.get("/orders/#{guid}") attributes = JSON.parse(response.body)['data'] new(attributes) end |
.pagination ⇒ Hash
21 22 23 24 25 26 |
# File 'lib/bond/order.rb', line 21 def pagination @pagination ||= begin response = Bond::Connection.connection.get('/orders') JSON.parse(response.body)['pagination'] || {} end end |
Instance Method Details
#add_message(message_hash) ⇒ Boolean
68 69 70 71 72 73 |
# File 'lib/bond/order.rb', line 68 def () response = Bond::Connection.connection.post("/orders/#{guid}/messages", ) @messages = nil response.success? end |
#message_pagination ⇒ Hash
87 88 89 90 91 92 |
# File 'lib/bond/order.rb', line 87 def @message_pagination ||= begin response = Bond::Connection.connection.get("/orders/#{guid}/messages") JSON.parse(response.body)['pagination'] || {} end end |
#messages ⇒ Array<Bond::Message>
76 77 78 79 80 81 82 83 84 |
# File 'lib/bond/order.rb', line 76 def @messages ||= begin response = Bond::Connection.connection.get("/orders/#{guid}/messages") = JSON.parse(response.body)['data'] .map do |attributes| Message.new(attributes) end end end |
#process ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bond/order.rb', line 54 def process response = Bond::Connection.connection.post("/orders/#{guid}/process") json = JSON.parse(response.body) Bond::BondError.handle_errors(json) attributes = json['data'] attributes.each { |name, value| instance_variable_set("@#{name}", value) } self.links = json['links'] response.success? end |