Class: Aceroute::Customer
Instance Attribute Summary (collapse)
-
- (Object) cid
Returns the value of attribute cid.
-
- (Object) email
Returns the value of attribute email.
-
- (Object) id
Returns the value of attribute id.
-
- (Object) locations
Returns the value of attribute locations.
-
- (Object) name
Returns the value of attribute name.
Class Method Summary (collapse)
-
+ (Object) delete(id)
Deletes Aceroute::Customer of given id from Aceroute.
Instance Method Summary (collapse)
-
- (Aceroute::Customer) create!
Persists Customer object to Aceroute API.
-
- (Object) destroy!(id = nil)
Deletes this Aceroute::Customer object (self) from Aceroute;.
-
- (Aceroute::Customer) initialize(name, email, location = {}, cid = nil)
constructor
Creates a new Aceroute::Customer object.
Constructor Details
- (Aceroute::Customer) initialize(name, email, location = {}, cid = nil)
Creates a new Aceroute::Customer object. Note this does not persist the Customer to Aceroute, that can be done by calling the create! method on the new object.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aceroute/customer.rb', line 16 def initialize(name, email, location = {}, cid = nil) self.locations = [] #create getters/setters for each param self.email = email self.name = name self.cid = cid if !location.empty? locations << Aceroute::Location.new(location[:address1], location[:address2], location[:description], location[:name], location[:phone]) end end |
Instance Attribute Details
- (Object) cid
Returns the value of attribute cid
6 7 8 |
# File 'lib/aceroute/customer.rb', line 6 def cid @cid end |
- (Object) email
Returns the value of attribute email
4 5 6 |
# File 'lib/aceroute/customer.rb', line 4 def email @email end |
- (Object) id
Returns the value of attribute id
6 7 8 |
# File 'lib/aceroute/customer.rb', line 6 def id @id end |
- (Object) locations
Returns the value of attribute locations
3 4 5 |
# File 'lib/aceroute/customer.rb', line 3 def locations @locations end |
- (Object) name
Returns the value of attribute name
5 6 7 |
# File 'lib/aceroute/customer.rb', line 5 def name @name end |
Class Method Details
+ (Object) delete(id)
Deletes Aceroute::Customer of given id from Aceroute
62 63 64 65 66 |
# File 'lib/aceroute/customer.rb', line 62 def self.delete(id) recs = "<data><del><id>#{id}</id></del></data>" ret = Aceroute::call_api("customer.delete", recs) ret.success == "true" ? true : false end |
Instance Method Details
- (Aceroute::Customer) create!
Persists Customer object to Aceroute API.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/aceroute/customer.rb', line 32 def create! recs = "<data> <cst> <nm>#{self.name}</nm> <locnm>#{self.locations.first.description}</locnm> <adr>#{self.locations.first.address1}</adr> <adr2>#{self.locations.first.address2}</adr2> <cntnm>#{self.locations.first.name}</cntnm> <tel>#{self.locations.first.phone}</tel> <eml>#{self.email}</eml> </cst> </data>" #puts recs data = Aceroute::call_api("customer.create", recs) location = data.locs.loc customer = data.cnts.cnt update_attrs(customer) self.cid = customer.cid locations.first.update_attrs(location) return self end |
- (Object) destroy!(id = nil)
Deletes this Aceroute::Customer object (self) from Aceroute;
56 57 58 |
# File 'lib/aceroute/customer.rb', line 56 def destroy!(id = nil) Customer.delete(id ? id : self.cid) end |