Class: Bond::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/bond/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.

Parameters:

  • attributes (Hash) (defaults to: {})


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_atObject

Returns the value of attribute created_at.



6
7
8
# File 'lib/bond/order.rb', line 6

def created_at
  @created_at
end

#guidObject

Returns the value of attribute guid.



6
7
8
# File 'lib/bond/order.rb', line 6

def guid
  @guid
end

Returns the value of attribute links.



6
7
8
# File 'lib/bond/order.rb', line 6

def links
  @links
end

#productsObject

Returns the value of attribute products.



6
7
8
# File 'lib/bond/order.rb', line 6

def products
  @products
end

#shippingObject

Returns the value of attribute shipping.



6
7
8
# File 'lib/bond/order.rb', line 6

def shipping
  @shipping
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/bond/order.rb', line 6

def status
  @status
end

#totalObject

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>

Parameters:

  • options (Hash) (defaults to: {})

Returns:



11
12
13
14
15
16
17
18
# File 'lib/bond/order.rb', line 11

def all(options = {})
  page = options[:page]
  response = Bond::Connection.connection.get("/orders?page=#{page || 1}")

  JSON.parse(response.body)['data'].map do |attributes|
    new(attributes)
  end
end

.createBond::Order

Returns:



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

Parameters:

  • guid (String)

Returns:



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

.paginationHash

Returns:

  • (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

Parameters:

  • message_hash (Hash)

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/bond/order.rb', line 68

def add_message(message_hash)
  response = Bond::Connection.connection.post("/orders/#{guid}/messages", message_hash)

  @messages = nil
  response.success?
end

#message_paginationHash

Returns:

  • (Hash)


87
88
89
90
91
92
# File 'lib/bond/order.rb', line 87

def message_pagination
  @message_pagination ||= begin
    response = Bond::Connection.connection.get("/orders/#{guid}/messages")
    JSON.parse(response.body)['pagination'] || {}
  end
end

#messagesArray<Bond::Message>

Returns:



76
77
78
79
80
81
82
83
84
# File 'lib/bond/order.rb', line 76

def messages
  @messages ||= begin
    response = Bond::Connection.connection.get("/orders/#{guid}/messages")
    messages = JSON.parse(response.body)['data']
    messages.map do |attributes|
      Message.new(attributes)
    end
  end
end

#processBoolean

Returns:

  • (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