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
-
#http_result ⇒ Object
Returns the value of attribute http_result.
Class Method Summary collapse
-
.create_customer(customer) ⇒ Hash
Create a new customer.
-
.create_location(location) ⇒ Object
Create a new location.
-
.create_order(order) ⇒ Object
Create new order.
-
.delete_customer(customer_id) ⇒ Object
Delete a customer.
-
.delete_location(location_id) ⇒ Object
Delete a location.
-
.delete_order(order_id) ⇒ Object
Delete an order.
-
.list_customers ⇒ Hash
List all customers.
-
.list_order_types ⇒ Object
List order types.
-
.list_orders ⇒ Object
List all orders.
-
.list_service_types ⇒ Object
List service types.
-
.list_workers ⇒ Object
List all workers.
Instance Attribute Details
#http_result ⇒ Object
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
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
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
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
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
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_customers ⇒ Hash
List all customers
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_types ⇒ Object
List order types
116 117 118 |
# File 'lib/aceroute/core.rb', line 116 def self.list_order_types self.call_api("order.type.list", nil) end |
.list_orders ⇒ Object
List all orders
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_types ⇒ Object
List service types
122 123 124 |
# File 'lib/aceroute/core.rb', line 122 def self.list_service_types self.call_api("product.type.list", nil) end |
.list_workers ⇒ Object
List all workers
129 130 131 |
# File 'lib/aceroute/core.rb', line 129 def self.list_workers workers = self.call_api("worker.list", nil).res end |