Class: KashflowApi::Customer

Inherits:
SoapObject show all
Defined in:
lib/kashflow_api/models/customer.rb

Instance Attribute Summary

Attributes inherited from SoapObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SoapObject

build_from_soap, #initialize, #method_missing

Constructor Details

This class inherits a constructor from KashflowApi::SoapObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KashflowApi::SoapObject

Class Method Details

.allObject



27
28
29
30
31
32
33
34
# File 'lib/kashflow_api/models/customer.rb', line 27

def self.all
    result = KashflowApi.api.get_customers
    customers = []
    result.basic_hash["soap:Envelope"]["soap:Body"]["GetCustomersResponse"]["GetCustomersResult"]["Customer"].each do |customer|
        customers.push self.build_from_soap customer
    end
    customers
end

.find(search) ⇒ Object



3
4
5
# File 'lib/kashflow_api/models/customer.rb', line 3

def self.find(search)
    self.find_by_customer_code(search)
end

.find_by_customer_code(search) ⇒ Object



7
8
9
10
# File 'lib/kashflow_api/models/customer.rb', line 7

def self.find_by_customer_code(search)
    result = KashflowApi.api.get_customer(search)
    self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetCustomerResponse"]["GetCustomerResult"])
end

.find_by_customer_email(search) ⇒ Object



17
18
19
20
# File 'lib/kashflow_api/models/customer.rb', line 17

def self.find_by_customer_email(search)
    result = KashflowApi.api.get_customer_by_email(search)
    self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetCustomerByEmailResponse"]["GetCustomerByEmailResult"])
end

.find_by_customer_id(search) ⇒ Object



12
13
14
15
# File 'lib/kashflow_api/models/customer.rb', line 12

def self.find_by_customer_id(search)
    result = KashflowApi.api.get_customer_by_id(search)
    self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetCustomerByIDResponse"]["GetCustomerByIDResult"])
end

.find_by_postcode(search) ⇒ Object



22
23
24
25
# File 'lib/kashflow_api/models/customer.rb', line 22

def self.find_by_postcode(search)
    result = KashflowApi.api.get_customers_by_postcode(search)
    self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetCustomersByPostcodeResponse"]["GetCustomersByPostcode"])
end

Instance Method Details

#balanceObject



48
49
50
# File 'lib/kashflow_api/models/customer.rb', line 48

def balance
    KashflowApi::CustomerBalance.new(self)
end

#destroyObject



44
45
46
# File 'lib/kashflow_api/models/customer.rb', line 44

def destroy
    KashflowApi.api.delete_customer(self.customerid)
end

#saveObject



36
37
38
39
40
41
42
# File 'lib/kashflow_api/models/customer.rb', line 36

def save
   if @hash["CustomerID"] == "0"
       insert_customer
   else
       update_customer
   end 
end

#to_xmlObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kashflow_api/models/customer.rb', line 52

def to_xml
    xml = []
    id_line = ""
    @hash.keys.each do |key|
        if key == "CustomerID"
            id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
        else
            xml.push("<#{key}>#{@hash[key]}</#{key}>")
        end
    end
    [id_line, xml.join].join
end