Module: Aceroute

Includes:
HTTParty
Defined in:
lib/aceroute.rb,
lib/aceroute/core.rb,
lib/aceroute/version.rb

Constant Summary

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Attribute Details

- (Object) http_result

Returns the value of attribute http_result



8
9
10
# File 'lib/aceroute/core.rb', line 8

def http_result
  @http_result
end

Class Method Details

+ (Hash) create_customer(customer)

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/aceroute/core.rb', line 37

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)
  address = data.locs.loc
  customer = data.cnts.cnt
  return customer, address
end

+ (Object) create_location(location)

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



75
76
77
78
79
80
81
82
83
84
# File 'lib/aceroute/core.rb', line 75

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

+ (Object) create_order(order)

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



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/aceroute/core.rb', line 136

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
  data = self.call_api("order.create", recs)
  puts data
  order = data.event
end

+ (Object) delete_customer(customer_id)

Delete a customer

Parameters:

  • customer_id (Integer)

    id of Aceroute Customer object

Returns:

  • success or failure hash



60
61
62
63
# File 'lib/aceroute/core.rb', line 60

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

+ (Object) delete_location(location_id)

Delete a location

Parameters:

  • location_id (Integer)

    id from Aceroute Location object

Returns:

  • nil



90
91
92
93
# File 'lib/aceroute/core.rb', line 90

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

+ (Object) delete_order(order_id)

Delete an order



158
159
160
161
# File 'lib/aceroute/core.rb', line 158

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

+ (Hash) list_customers

List all customers

Returns:

  • (Hash)

    list of customer objects



21
22
23
# File 'lib/aceroute/core.rb', line 21

def self.list_customers
  self.call_api("customer.list", nil)
end

+ (Object) list_order_types

List order types

Returns:

  • list of available order types for this account



97
98
99
# File 'lib/aceroute/core.rb', line 97

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

+ (Object) list_orders

List all orders

Returns:

  • list of all orders in this account



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

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

+ (Object) list_service_types

List service types

Returns:

  • list of available service types for this account



103
104
105
# File 'lib/aceroute/core.rb', line 103

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

+ (Object) list_workers

List all workers

Returns:

  • list of available workers for this account



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

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