Class: Aceroute::Order

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer, location, start_time, description = nil, duration = 10, scheduled = true, worker = nil, summary = nil, purchase_order = nil) ⇒ Aceroute::Order

Creates a new Aceroute::Order object. Note this does not persist the Location to Aceroute, that can be done by calling the create! method on the new object.

Parameters:

  • customer (Aceroute::Customer)

    recipient of this Order

  • location (Aceroute::Location)

    location of this Order (delivery destination)

  • start_time (Integer)

    start time of Order, in msec since epoch (note: msec not sec)

  • description (String) (defaults to: nil)

    description of Order (e.g., contents of order)

  • duration (Integer) (defaults to: 10)

    duration of Order in minutes (time to service customer); used to aid in route optimization. Defaults to 10 minutes

  • scheduled (Boolean) (defaults to: true)

    whether this Order is scheduled or not; defaults to true

  • worker (Integer) (defaults to: nil)

    Worker ID of aceroute worker to assign this Order to; defaults to nil (not implemented)

  • summary (String) (defaults to: nil)

    Summary of order, to be displated in app. Defaults to none.

  • purchase_order (String) (defaults to: nil)

    arbitrary string to indicate PO or other note, if needed



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aceroute/order.rb', line 24

def initialize(customer, location, start_time, description = nil, duration = 10,
  scheduled = true, worker = nil, summary = nil, purchase_order = nil)
  self.customer = customer
  self.location = location
  self.start_time = start_time
  #FIXME: taking a DateTime argument is friendlier
  #self.start_time = start_time.to_i * 1000 #DateTime object
  self.description = description
  self.duration = duration
  self.scheduled = scheduled
  self.worker = worker
  self.summary = summary
  self.purchase_order = purchase_order
end

Instance Attribute Details

#cidObject

Returns the value of attribute cid.



5
6
7
# File 'lib/aceroute/order.rb', line 5

def cid
  @cid
end

#customerObject

in msec (not sec) since epoch



3
4
5
# File 'lib/aceroute/order.rb', line 3

def customer
  @customer
end

#descriptionObject

any freeform text here



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

def description
  @description
end

#durationObject

any freeform text here



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

def duration
  @duration
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/aceroute/order.rb', line 5

def id
  @id
end

#locationObject

in msec (not sec) since epoch



3
4
5
# File 'lib/aceroute/order.rb', line 3

def location
  @location
end

#purchase_orderObject

any freeform text here



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

def purchase_order
  @purchase_order
end

#scheduledObject

any freeform text here



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

def scheduled
  @scheduled
end

#start_timeObject

in msec (not sec) since epoch



3
4
5
# File 'lib/aceroute/order.rb', line 3

def start_time
  @start_time
end

#summaryObject

any freeform text here



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

def summary
  @summary
end

#workerObject

any freeform text here



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

def worker
  @worker
end

Class Method Details

.delete(id) ⇒ Object

Deletes Aceroute::Location of given id from Aceroute

Parameters:

  • id (Integer)


73
74
75
76
77
# File 'lib/aceroute/order.rb', line 73

def self.delete(id)
  req = "<data><del><id>#{id}</id></del></data>"
  ret = Aceroute::call_api("order.delete", req)
  ret.success == "true" ? true : false  #maybe raise error here instead
end

Instance Method Details

#create!Aceroute::Order

Persists Aceroute::Order object to Aceroute API.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aceroute/order.rb', line 43

def create!
  recs = "<data>
        <event>
          <cid>#{self.customer.cid}</cid>
          <nm>#{self.description}</nm>
          <dur>#{self.duration}</dur>
          <schd>#{self.scheduled ? 1 : 0}</schd>
          <start_epoch>#{self.start_time}</start_epoch>
          <lid>#{self.location.id}</lid>
          <cntid>#{0}</cntid>
          <rid>#{self.worker}</rid>
          <dtl>#{self.summary}</dtl>
          <po>#{self.purchase_order}</po>
        </event>
      </data>"
  data = Aceroute::call_api("order.create", recs)
  order = data.event
  update_attrs(order)
  return self
end

#destroy!(id = nil) ⇒ Object

Deletes this Aceroute::Order object (self) from Aceroute



66
67
68
# File 'lib/aceroute/order.rb', line 66

def destroy!(id = nil)
  Order.delete(id ? id : self.id)
end