Class: Aceroute::Location

Inherits:
Base
  • Object
show all
Defined in:
lib/aceroute/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address1, address2, description, name, phone, cid = nil, id = nil) ⇒ Aceroute::Location

Creates a new Aceroute::Location object. Note this does not persist the Location to Aceroute, that can be done by calling the create! method on the new object.

Parameters:

  • address1 (String)

    customer address line 1 (street)

  • address2 (String)

    customer address line 2 (eg apartment number)

  • description (String)

    description of address (eg ‘Home’)

  • name (String)

    name of address (eg ‘Home’)

  • phone (String)

    phone number associated with this address

  • cid (Integer) (defaults to: nil)

    Aceroute customer id, optional; associates this Location with that Customer

  • id (Integer) (defaults to: nil)

    Aceroute location id, optional; useful for instantiating Location objects from Aceroute API response



22
23
24
25
26
27
28
29
30
# File 'lib/aceroute/location.rb', line 22

def initialize(address1, address2, description, name, phone, cid = nil, id= nil)
  self.address1 = address1
  self.address2 = address2
  self.description = description
  self.name = name
  self.phone = phone
  self.cid = cid
  self.id = id
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



3
4
5
# File 'lib/aceroute/location.rb', line 3

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



4
5
6
# File 'lib/aceroute/location.rb', line 4

def address2
  @address2
end

#cidObject

Returns the value of attribute cid.



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

def cid
  @cid
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/aceroute/location.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/aceroute/location.rb', line 6

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



7
8
9
# File 'lib/aceroute/location.rb', line 7

def phone
  @phone
end

Class Method Details

.delete(id) ⇒ Object

Deletes Aceroute::Location of given id from Aceroute

Parameters:

  • id (Integer)


55
56
57
58
59
# File 'lib/aceroute/location.rb', line 55

def self.delete(id)
  req = "<data><del><id>#{id}</id></del></data>"
  ret = Aceroute::call_api("customer.location.delete", req)
  ret.success == "true" ? true : false  #maybe raise error here instead
end

Instance Method Details

#create!Aceroute::Location

Persists Aceroute::Location object to Aceroute API.

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aceroute/location.rb', line 35

def create!
  recs = "<data><loc><id>0</id>
    <cid>#{self.cid}</cid>
    <nm>#{self.description}</nm>
    <adr>#{self.address1}</adr>
    <adr2>#{self.address2}</adr2>
    </loc></data>"
  data = Aceroute::call_api("customer.location.save", recs)
  loc = data.loc
  update_attrs(loc)
  return self
end

#destroy!(id = nil) ⇒ Object

Deletes this Aceroute::Location object (self) from Aceroute



49
50
51
# File 'lib/aceroute/location.rb', line 49

def destroy!(id = nil)
  Location.delete(id ? id : self.id)
end