module Aceroute
Constants
- VERSION
Attributes
http_result[RW]
Public Class Methods
create_customer(customer)
click to toggle source
Create a new customer @param 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
@return [Hash] customer and address
# 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)
click to toggle source
Create a new location @param 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
@return Aceroute
location object
# 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)
click to toggle source
Create new order @param 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
# 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)
click to toggle source
delete_location(location_id)
click to toggle source
delete_order(order_id)
click to toggle source
Delete an order
# 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_customers()
click to toggle source
List all customers @return [Hash] list of customer objects
# 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_types()
click to toggle source
List order types @return list of available order types for this account
# File lib/aceroute/core.rb, line 116 def self.list_order_types self.call_api("order.type.list", nil) end
list_orders()
click to toggle source
List all orders @return list of all orders in this account
# File lib/aceroute/core.rb, line 135 def self.list_orders workers = self.call_api("order.list", nil).event end
list_service_types()
click to toggle source
List service types @return list of available service types for this account
# File lib/aceroute/core.rb, line 122 def self.list_service_types self.call_api("product.type.list", nil) end
list_workers()
click to toggle source
List all workers @return list of available workers for this account
# File lib/aceroute/core.rb, line 129 def self.list_workers workers = self.call_api("worker.list", nil).res end
Private Class Methods
call_api(method, recs)
click to toggle source
# File lib/aceroute/core.rb, line 183 def self.call_api(method, recs) params = @@query_params.merge!({method: method}) params[:recs] = recs unless recs.nil? options = {query: params} http_result = self.get("/api", options).parsed_response puts http_result if @@DEBUG data = Hashit.new(http_result['data']) end