Class: KashflowApi::Supplier
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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class KashflowApi::SoapObject
Class Method Details
.all ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/kashflow_api/models/supplier.rb', line 17
def self.all
result = KashflowApi.api.get_suppliers
suppliers = []
result.basic_hash["soap:Envelope"]["soap:Body"]["GetSuppliersResponse"]["GetSuppliersResult"]["Supplier"].each do |supplier|
suppliers.push self.build_from_soap supplier
end
suppliers.sort { |x, y| x.name <=> y.name }
end
|
.find(search) ⇒ Object
3
4
5
|
# File 'lib/kashflow_api/models/supplier.rb', line 3
def self.find(search)
self.find_by_supplier_code(search)
end
|
.find_by_supplier_code(search) ⇒ Object
7
8
9
10
|
# File 'lib/kashflow_api/models/supplier.rb', line 7
def self.find_by_supplier_code(search)
result = KashflowApi.api.get_supplier(search)
self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetSupplierResponse"]["GetSupplierResult"])
end
|
.find_by_supplier_id(search) ⇒ Object
12
13
14
15
|
# File 'lib/kashflow_api/models/supplier.rb', line 12
def self.find_by_supplier_id(search)
result = KashflowApi.api.get_supplier_by_id(search)
self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetSupplierByIDResponse"]["GetSupplierByIDResult"])
end
|
Instance Method Details
#save ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/kashflow_api/models/supplier.rb', line 26
def save
if @hash["SupplierID"] == "0"
insert_supplier
else
update_supplier
end
end
|
#to_xml ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/kashflow_api/models/supplier.rb', line 34
def to_xml
xml = []
id_line = ""
@hash.keys.each do |key|
if key == "SupplierID"
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
|