kashflow_api 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +2 -0
- data/README.markdown +29 -7
- data/kashflow_api.gemspec +1 -1
- data/lib/kashflow_api.rb +35 -24
- data/lib/kashflow_api/api.rb +25 -25
- data/lib/kashflow_api/api_call.rb +19 -55
- data/lib/kashflow_api/client.rb +24 -22
- data/lib/kashflow_api/models/customer.rb +41 -84
- data/lib/kashflow_api/models/invoice.rb +38 -36
- data/lib/kashflow_api/models/line.rb +46 -40
- data/lib/kashflow_api/models/nominal_code.rb +9 -8
- data/lib/kashflow_api/models/quote.rb +15 -11
- data/lib/kashflow_api/models/receipt.rb +35 -37
- data/lib/kashflow_api/models/supplier.rb +41 -58
- data/lib/kashflow_api/soap_object.rb +72 -30
- data/lib/kashflow_api/version.rb +1 -1
- data/{spec → spec-old}/kashflow_api_customer_balance_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_customer_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_nominal_codes_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_quote_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_receipt_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_spec.rb +0 -0
- data/{spec → spec-old}/kashflow_api_supplier_spec.rb +0 -0
- data/spec-old/spec_helper.rb +21 -0
- data/{spec → spec-old}/test_data.example.yml +0 -0
- data/spec/core/api_call_spec.rb +25 -0
- data/spec/core/api_spec.rb +31 -0
- data/spec/core/client_spec.rb +23 -0
- data/spec/core/kashflow_api_spec.rb +14 -0
- data/spec/core/soap_object_spec.rb +25 -0
- data/spec/objects/customer_spec.rb +11 -0
- data/spec/objects/inherited_methods_spec.rb +45 -0
- data/spec/objects/invoice_spec.rb +6 -0
- data/spec/objects/line_spec.rb +5 -0
- data/spec/objects/nominal_code_spec.rb +5 -0
- data/spec/objects/quote_spec.rb +10 -0
- data/spec/objects/receipt_spec.rb +6 -0
- data/spec/objects/supplier_spec.rb +6 -0
- data/spec/spec_helper.rb +60 -15
- data/spec/support/macros.rb +53 -0
- metadata +49 -27
@@ -1,47 +1,49 @@
|
|
1
1
|
module KashflowApi
|
2
2
|
class Invoice < KashflowApi::SoapObject
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def customer
|
9
|
-
KashflowApi::Customer.find_by_customer_id(self.customerid)
|
10
|
-
end
|
3
|
+
Keys = [
|
4
|
+
"InvoiceNumber", "InvoiceDate", "DueDate", "CustomerID", "CustomerReference", ["InvoiceDBID", "0"]
|
5
|
+
]
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
Finds = [ "InvoiceNumber" ]
|
8
|
+
|
9
|
+
KFObject = { singular: "invoice", plural: "invoices" }
|
10
|
+
|
11
|
+
XMLKey = "InvoiceDBID"
|
12
|
+
|
13
|
+
define_methods
|
14
|
+
|
15
|
+
def self.build_arguments(action, object, field, argument)
|
16
|
+
if action == "get"
|
17
|
+
expects argument, String
|
18
|
+
return "<InvoiceNumber>#{argument}</InvoiceNumber>" if object == "invoice"
|
19
|
+
elsif action == "update" || action == "insert"
|
20
|
+
expects argument, KashflowApi::Invoice
|
21
|
+
return "<InvoiceID>#{argument.invoiceid}</InvoiceID><InvLine>#{argument.to_xml}</InvLine>" if field == "Line"
|
22
|
+
return "<InvoiceNumber>#{argument.invoicenumber}</InvoiceNumber><InvLine>#{argument.to_xml}</InvLine>" if field == "Number"
|
23
|
+
return "<Inv>#{argument.to_xml}</Inv>" if object == "invoice"
|
18
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def customer
|
28
|
+
KashflowApi::Customer.find_by_customer_id(self.customerid)
|
29
|
+
end
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
|
26
|
-
else
|
27
|
-
xml.push("<#{key}>#{@hash[key]}</#{key}>")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
[id_line, xml.join].join
|
31
|
+
def save
|
32
|
+
if @hash["InvoiceDBID"] == "0"
|
33
|
+
insert_invoice
|
34
|
+
else
|
35
|
+
update_invoice
|
31
36
|
end
|
37
|
+
end
|
32
38
|
|
33
|
-
|
39
|
+
private
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def update_invoice
|
40
|
-
KashflowApi.api.update_invoice(self)
|
41
|
-
end
|
41
|
+
def update_invoice
|
42
|
+
KashflowApi.api.update_invoice(self)
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
def insert_invoice
|
46
|
+
KashflowApi.api.insert_invoice(self)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
@@ -1,50 +1,56 @@
|
|
1
1
|
module KashflowApi
|
2
2
|
class Line < KashflowApi::SoapObject
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
Keys = [
|
4
|
+
"Quantity", "Description", "ChargeType", "VatAmount", "VatRate", "Rate", "ReceiptID", "InvoiceID", "InvoiceNumber", "ReceiptNumber"
|
5
|
+
]
|
6
|
+
|
7
|
+
Finds = []
|
8
|
+
|
9
|
+
KFObject = {singular: "line", plural: "lines"}
|
10
|
+
|
11
|
+
XMLKey = "LineID"
|
12
|
+
|
13
|
+
def save
|
14
|
+
if @hash["ReceiptID"] != ""
|
15
|
+
insert_receipt_line
|
16
|
+
elsif @hash["InvoiceID"] != ""
|
17
|
+
insert_invoice_line
|
18
|
+
elsif @hash["InvoiceNumber"] != ""
|
19
|
+
insert_invoice_number_line
|
20
|
+
elsif @hash["ReceiptNumber"] != ""
|
21
|
+
insert_receipt_number_line
|
13
22
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
[id_line, xml.join].join
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def blank_object_hash
|
31
|
-
{"Quantity" => "", "Description" => "", "ChargeType" => "", "VatAmount" => "", "VatRate" => "", "Rate" => "", "ReceiptID" => "", "InvoiceID" => "", "InvoiceNumber" => "", "ReceiptNumber" => "" }
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_xml
|
26
|
+
xml = []
|
27
|
+
id_line = ""
|
28
|
+
@hash.keys.each do |key|
|
29
|
+
if key == "LineID"
|
30
|
+
id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
|
31
|
+
elsif key != "ReceiptID" && key != "InvoiceID" && @hash[key] != ""
|
32
|
+
xml.push("<#{key}>#{@hash[key]}</#{key}>")
|
33
|
+
end
|
32
34
|
end
|
35
|
+
[id_line, xml.join].join
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
def insert_receipt_line
|
41
|
+
KashflowApi.api.insert_receipt_line(self)
|
42
|
+
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
def insert_invoice_line
|
45
|
+
KashflowApi.api.insert_invoice_line(self)
|
46
|
+
end
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
def insert_invoice_number_line
|
49
|
+
KashflowApi.api.insert_invoice_line_with_invoice_number(self)
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
def insert_receipt_number_line
|
53
|
+
KashflowApi.api.insert_receipt_line_from_number(self)
|
54
|
+
end
|
49
55
|
end
|
50
56
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module KashflowApi
|
2
2
|
class NominalCode < KashflowApi::SoapObject
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
Keys = [
|
4
|
+
"Code", "Name", "Debit", "Credit", "Balance"
|
5
|
+
]
|
6
|
+
|
7
|
+
Finds = []
|
8
|
+
|
9
|
+
KFObject = { singular: "nominal_code", plural: "nominal_codes" }
|
10
|
+
|
11
|
+
XMLKey = "NominalCodeID"
|
11
12
|
end
|
12
13
|
end
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
class Quote < KashflowApi::Invoice
|
3
|
+
|
4
|
+
KFObject = {singular: "quote", plural: "quotes"}
|
5
|
+
|
6
|
+
def self.build_arguments(action, object, field, argument)
|
7
|
+
if action == "get"
|
8
|
+
expects argument, String
|
9
|
+
return "<Quote#{field}>#{argument}</Quote#{field}>" if object == "quote"
|
10
|
+
elsif action == "update" || action == "insert"
|
11
|
+
expects argument, KashflowApi::Quote
|
12
|
+
return "<InvoiceID>#{argument.invoiceid}</InvoiceID><InvLine>#{argument.to_xml}</InvLine>" if field == "Line"
|
13
|
+
return "<InvoiceNumber>#{argument.invoicenumber}</InvoiceNumber><InvLine>#{argument.to_xml}</InvLine>" if field == "Number"
|
14
|
+
return "<Inv>#{argument.to_xml}</Inv>" if object == "quote"
|
15
|
+
end
|
13
16
|
end
|
17
|
+
end
|
14
18
|
end
|
@@ -1,43 +1,41 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
2
|
+
class Receipt < KashflowApi::SoapObject
|
3
|
+
Keys = KashflowApi::Invoice::Keys
|
4
|
+
|
5
|
+
Finds = KashflowApi::Invoice::Finds
|
6
|
+
|
7
|
+
KFObject = { singular: "receipt", plural: "receipts" }
|
8
|
+
|
9
|
+
XMLKey = "InvoiceDBID"
|
10
|
+
|
11
|
+
def self.build_arguments(action, object, field, argument)
|
12
|
+
if action == "get"
|
13
|
+
expects argument, String
|
14
|
+
return "<ReceiptNumber>#{argument}</ReceiptNumber>" if object == "receipt"
|
15
|
+
elsif action == "update" || action == "insert"
|
16
|
+
expects argument, KashflowApi::Receipt
|
17
|
+
return "<ReceiptID>#{argument.receiptid}</ReceiptID><InvLine>#{argument.to_xml}</InvLine>" if field == "Line"
|
18
|
+
return "<ReceiptNumber>#{argument.invoicenumber}</ReceiptNumber><InvLine>#{argument.to_xml}</InvLine>" if field == "Number"
|
19
|
+
return "<Inv>#{argument.to_xml}</Inv>" if object == "receipt"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save
|
24
|
+
if @hash["InvoiceDBID"] == "0"
|
25
|
+
insert_receipt
|
26
|
+
else
|
27
|
+
update_receipt
|
28
|
+
end
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
{ "InvoiceNumber" => "", "InvoiceDate" => "", "DueDate" => "", "CustomerID" => "", "CustomerReference" => "", "InvoiceDBID" => "0" }
|
33
|
-
end
|
31
|
+
private
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def update_receipt
|
34
|
+
KashflowApi.api.update_receipt(self)
|
35
|
+
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
37
|
+
def insert_receipt
|
38
|
+
KashflowApi.api.insert_receipt(self)
|
42
39
|
end
|
40
|
+
end
|
43
41
|
end
|
@@ -1,62 +1,45 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
xml.push("<#{key}>#{@hash[key]}</#{key}>")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
[id_line, xml.join].join
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def blank_object_hash
|
50
|
-
{"Code" => "", "Name" => "", "Contact" => "", "Telephone" => "", "Mobile" => "", "Fax" => "", "Email" => "", "Address1" => "", "Address2" => "",
|
51
|
-
"Address3" => "", "Address4" => "", "Postcode" => "", "Website" => "", "VATNumber" => "", "Notes" => ""}.merge(KashflowApi::Supplier.find("").hash)
|
52
|
-
end
|
53
|
-
|
54
|
-
def update_supplier
|
55
|
-
KashflowApi.api.update_supplier(self)
|
56
|
-
end
|
2
|
+
class Supplier < KashflowApi::SoapObject
|
3
|
+
Keys = [
|
4
|
+
"Code", "Name", "Contact", "Telephone", "Mobile", "Fax", "Email", "Address1", "Address2", "Address3", "Address4", "Postcode", "Website", "VATNumber", "Notes"
|
5
|
+
]
|
6
|
+
|
7
|
+
Finds = [ "code", "id" ]
|
8
|
+
|
9
|
+
KFObject = { singular: "supplier", plural: "suppliers" }
|
10
|
+
|
11
|
+
XMLKey = "SupplierID"
|
12
|
+
|
13
|
+
def self.build_arguments(action, object, field, argument)
|
14
|
+
if action == "get"
|
15
|
+
expects argument, String
|
16
|
+
return "<Supplier#{field}>#{argument}</Supplier#{field}>" if object == "supplier"
|
17
|
+
return "<#{field}>#{argument}</#{field}>" if object == "suppliers"
|
18
|
+
elsif action == "update"
|
19
|
+
expects argument, KashflowApi::Supplier
|
20
|
+
return "<sup>#{argument.to_xml}</sup>" if object == "supplier"
|
21
|
+
elsif action == "insert"
|
22
|
+
expects argument, KashflowApi::Supplier
|
23
|
+
return "<supl>#{argument.to_xml}</supl>" if object == "supplier"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
if @hash["SupplierID"] == "0"
|
29
|
+
insert_supplier
|
30
|
+
else
|
31
|
+
update_supplier
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def update_supplier
|
38
|
+
KashflowApi.api.update_supplier(self)
|
39
|
+
end
|
57
40
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
41
|
+
def insert_supplier
|
42
|
+
KashflowApi.api.insert_supplier(self)
|
61
43
|
end
|
44
|
+
end
|
62
45
|
end
|
@@ -1,40 +1,82 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
class SoapObject
|
3
|
+
include Expects
|
4
|
+
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
def initialize(hash = nil)
|
8
|
+
expects(hash, Hash) if hash
|
9
|
+
@hash = (hash || new_object_hash)
|
10
|
+
init_class
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.inherited(klass)
|
14
|
+
KashflowApi.add_soap_object(klass)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
result = KashflowApi.api.send("get_#{self::KFObject[:plural]}".to_sym)
|
19
|
+
results = []
|
20
|
+
result.hash[:envelope][:body]["get_#{self::KFObject[:plural]}_response".to_sym]["get_#{self::KFObject[:plural]}_result".to_sym][self::KFObject[:singular].to_sym].each do |result|
|
21
|
+
results.push self.new result
|
22
|
+
end
|
23
|
+
return results
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(search)
|
27
|
+
self.send(find_method, search)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_method
|
31
|
+
"find_by_#{self::Finds.first}".to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.define_methods
|
35
|
+
self::Finds.each do |find|
|
36
|
+
method_name = "find_by_#{find}".to_sym
|
37
|
+
result_name = find == self::Finds.first ? "get_#{self::KFObject[:singular]}" : "get_#{self::KFObject[:singular]}_by_#{find}"
|
14
38
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
39
|
+
self.define_singleton_method(method_name, Proc.new { |search|
|
40
|
+
result = KashflowApi.api.send(result_name.to_sym, search)
|
41
|
+
hash = result.hash[:envelope][:body]["#{result_name}_response".to_sym]["#{result_name}_result".to_sym]
|
42
|
+
return self.new(hash)
|
43
|
+
})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_xml
|
48
|
+
xml = []
|
49
|
+
id_line = ""
|
50
|
+
@hash.keys.each do |key|
|
51
|
+
if key == self.class::XMLKey
|
52
|
+
id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
|
22
53
|
else
|
23
|
-
|
54
|
+
xml.push("<#{key}>#{@hash[key]}</#{key}>")
|
24
55
|
end
|
25
56
|
end
|
57
|
+
[id_line, xml.join].join
|
58
|
+
end
|
26
59
|
|
27
|
-
|
28
|
-
|
60
|
+
private
|
61
|
+
|
62
|
+
def new_object_hash
|
63
|
+
hash = {}
|
64
|
+
self.class::Keys.each do |key|
|
65
|
+
key = [*key]
|
66
|
+
hash[key.first] = (key.last == key.first ? "" : key.last )
|
67
|
+
end
|
68
|
+
return hash
|
69
|
+
end
|
70
|
+
|
71
|
+
def init_class
|
72
|
+
@hash.keys.each do |key|
|
73
|
+
self.class.send(:define_method, key.downcase.to_sym) do
|
74
|
+
@hash[key]
|
29
75
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def build_field_hash
|
34
|
-
@fields = {}
|
35
|
-
@hash.keys.each do |key|
|
36
|
-
@fields[key.downcase.to_sym] = key
|
37
|
-
end
|
76
|
+
self.class.send(:define_method, "#{key.downcase}=".to_sym) do |set|
|
77
|
+
@hash[key] = set
|
38
78
|
end
|
79
|
+
end
|
39
80
|
end
|
81
|
+
end
|
40
82
|
end
|