Module: Aceroute

Includes:
HTTParty
Defined in:
lib/aceroute.rb,
lib/aceroute/base.rb,
lib/aceroute/core.rb,
lib/aceroute/order.rb,
lib/aceroute/version.rb,
lib/aceroute/customer.rb,
lib/aceroute/location.rb

Defined Under Namespace

Classes: Base, Customer, Location, Order

Constant Summary collapse

VERSION =
"0.2.1"
@@DEBUG =
false
@@API_KEY =
ENV['ACEROUTE_API_TOKEN']
@@query_params =
{
  token: @@API_KEY,
  updsince: '0'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#http_resultObject

Returns the value of attribute http_result.



13
14
15
# File 'lib/aceroute/core.rb', line 13

def http_result
  @http_result
end

Class Method Details

.create_customer(customer) ⇒ Hash

Create a new customer

Parameters:

  • customer (Hash)
    • :name (String) the name of customer

    • :email (String) the email for this customer

    • :address [Hash]

      • :description (String) the description of this address, eg ‘home’

      • :address1 (String) line 1 of the address, eg ‘123 Fake Street’

      • :address2 (String) line 2 of the address, eg ‘New York, NY 12345’

      • :name (String) address name

      • :phone (String) address phone number

Returns:

  • (Hash)

    customer and address



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aceroute/core.rb', line 56

def self.create_customer(customer)
  recs = "<data>
    <cst>
      <nm>#{customer[:name]}</nm>
      <locnm>#{customer[:address][:description]}</locnm>
      <adr>#{customer[:address][:address1]}</adr>
      <adr2>#{customer[:address][:address2]}</adr2>
      <cntnm>#{customer[:address][:name]}</cntnm>
      <tel>#{customer[:address][:phone]}</tel>
      <eml>#{customer[:email]}</eml>
    </cst>
  </data>"

  data = self.call_api("customer.create", recs)
  location = data.locs.loc
  customer = data.cnts.cnt
  return customer, location
end

.create_location(location) ⇒ Object

Create a new location

Parameters:

  • location (Hash)
    • :id (Integer)

    • :description (String) the description of this address, eg ‘home’

    • :address1 (String) line 1 of the address, eg ‘123 Fake Street’

    • :address2 (String) line 2 of the address, eg ‘New York, NY 12345’

    • :customer

      • :cid (Integer) cid from Aceroute Customer object

Returns:

  • Aceroute location object



94
95
96
97
98
99
100
101
102
103
# File 'lib/aceroute/core.rb', line 94

def self.create_location(location)
  recs = "<data><loc><id>#{location[:id]}</id>
    <cid>#{location[:customer][:cid]}</cid>
    <nm>#{location[:description]}</nm>
    <adr>#{location[:address1]}</adr>
    <adr2>#{location[:address2]}</adr2>
    </loc></data>"
  data = self.call_api("customer.location.save", recs)
  loc = data.loc
end

.create_order(order) ⇒ Object

Create new order

Parameters:

  • order (Hash)
    • :cid (Integer) Aceroute customer id

    • :nm (String) ‘name’, descriptive field for this order

    • :dir (Integer) ‘duration’, in 5 minute increments

    • :sched (Integer) 1 = scheduled, 0 = unscheduled

    • :start_epoch (Integer) time in msec since epoch

    • :lid (Integer) optional – customer location id

    • :cntid (Integer) optional – customer contact id

    • :rid (Integer) optional – worker id, to assign this order to a specific worker

    • :dtl (String) optional – order summary

    • po (String) optional – ‘purchase order’, descriptive field for use as desired

Returns:

  • Aceroute Order object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/aceroute/core.rb', line 155

def self.create_order(order)
  recs = "<data>
        <event>
          <cid>#{order[:cid]}</cid>
          <nm>#{order[:nm]}</nm>
          <dur>#{order[:dur]}</dur>
          <schd>#{order[:schd]}</schd>
          <start_epoch>#{order[:start_epoch]}</start_epoch>
          <lid>#{order[:lid]}</lid>
          <cntid>#{order[:cntid]}</cntid>
          <rid>#{order[:rid]}</rid>
          <dtl>#{order[:dtl]}</dtl>
          <po>#{order[:po]}</po>
        </event>
      </data>"
  puts recs if @@DEBUG
  data = self.call_api("order.create", recs)
  puts data if @@DEBUG
  order = data.event
end

.delete_customer(customer_id) ⇒ Object

Delete a customer

Parameters:

  • customer_id (Integer)

    id of Aceroute Customer object

Returns:

  • success or failure hash



79
80
81
82
# File 'lib/aceroute/core.rb', line 79

def self.delete_customer(customer_id)
  recs = "<data><del><id>#{customer_id}</id></del></data>"
  self.call_api("customer.delete", recs)
end

.delete_location(location_id) ⇒ Object

Delete a location

Parameters:

  • location_id (Integer)

    id from Aceroute Location object

Returns:

  • nil



109
110
111
112
# File 'lib/aceroute/core.rb', line 109

def self.delete_location(location_id)
  recs = "<data><del><id>#{location_id}</id></del></data>"
  types = self.call_api("customer.location.delete", recs).otype
end

.delete_order(order_id) ⇒ Object

Delete an order



177
178
179
180
# File 'lib/aceroute/core.rb', line 177

def self.delete_order(order_id)
  recs = "<data><del><id>#{order_id}</id></del></data>"
  self.call_api("order.delete", recs)
end

.list_customersHash

List all customers

Returns:

  • (Hash)

    list of customer objects



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/aceroute/core.rb', line 28

def self.list_customers
  customers = []
  res = self.call_api("customer.list", nil)
  res.cnts.cnt.each do |r|
    c = Aceroute::Customer.new(name: r['nm'], email: r['eml'], cid: r['cid'])
    customers << c
    #find corresponding addresses for this customer
    locations = res.locs.loc.find_all{|l| l["cid"] == c.cid }
    locations.each do |a|
      c.locations << Aceroute::Location.new(address1: a['adr'], address2: a['adr2'],
        phone: a['tel'], description: a['nm'])
    end
  end
  customers
end

.list_order_typesObject

List order types

Returns:

  • list of available order types for this account



116
117
118
# File 'lib/aceroute/core.rb', line 116

def self.list_order_types
  self.call_api("order.type.list", nil)
end

.list_ordersObject

List all orders

Returns:

  • list of all orders in this account



135
136
137
# File 'lib/aceroute/core.rb', line 135

def self.list_orders
  workers = self.call_api("order.list", nil).event
end

.list_service_typesObject

List service types

Returns:

  • list of available service types for this account



122
123
124
# File 'lib/aceroute/core.rb', line 122

def self.list_service_types
  self.call_api("product.type.list", nil)
end

.list_workersObject

List all workers

Returns:

  • list of available workers for this account



129
130
131
# File 'lib/aceroute/core.rb', line 129

def self.list_workers
  workers = self.call_api("worker.list", nil).res
end