Class: PleskLib::Actions::ListCustomers

Inherits:
Base
  • Object
show all
Defined in:
lib/plesk_lib/actions/list_customers.rb

Constant Summary collapse

MAPPING =
{
  'cr_date' => 'created_at', 'cname' => 'company_name', 'pname' => 'person_name',
  'login' => 'login', 'status' => 'status', 'phone' => 'phone', 'fax' => 'fax',
  'email' => 'email', 'address' => 'address', 'city' => 'city', 'state' => 'state',
  'pcode' => 'postal_code', 'country' => 'country', 'locale' => 'locale',
  'guid' => 'guid', 'owner-id' => 'owner_id', 'vendor-guid' => 'vendor_guid',
  'external-id' => 'external_id', 'password' => 'password',
  'password_type' => 'password_type'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#execute_on

Constructor Details

#initialize(owner_id = nil) ⇒ ListCustomers

Returns a new instance of ListCustomers.



14
15
16
# File 'lib/plesk_lib/actions/list_customers.rb', line 14

def initialize(owner_id = nil)
  @owner_id = owner_id
end

Instance Attribute Details

#customersObject (readonly)

Returns the value of attribute customers.



2
3
4
# File 'lib/plesk_lib/actions/list_customers.rb', line 2

def customers
  @customers
end

Instance Method Details

#analyse(xml_document) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/plesk_lib/actions/list_customers.rb', line 37

def analyse(xml_document)
  @customers = []
  xml_document.root.customer.get.nodes.each do |customer_node|
    customer = PleskLib::Customer.new(nil)
    customer_node.data.gen_info.nodes.each do |attribute_node|
      customer_attribute = MAPPING[attribute_node.name]
      next if customer_attribute.blank? || !customer.respond_to?(customer_attribute) ||
              attribute_node.text.blank?
      customer.send("#{customer_attribute}=", attribute_node.text)
    end
    customer.status = customer.status.to_i
    @customers << customer
  end
end

#build_xmlObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/plesk_lib/actions/list_customers.rb', line 18

def build_xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.packet(:version => '1.6.3.5') {
    xml.customer {
      xml.get {
        xml.filter {
          xml.tag!('owner-id', @owner_id) if @owner_id.present?
        }
        xml.dataset {
          xml.gen_info
          xml.stat
        }
      }
    }
  }
  return xml.target!
end