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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83aa2d3d9328488253625f5a8c757a8c15f284b2
|
4
|
+
data.tar.gz: 8165b45aeac0f6c38dde74a7000032ba4efb8dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f387a0516f4edd4600f49da3d8cdbd5dfbbaebffcb597a0f49e0d50c32fbcd254af25b951e55258303f63e0d468678a322737bd1a286ab2f8f81c981f475015a
|
7
|
+
data.tar.gz: 3a2fc5bad8acdcc8494fea8587002b8bae8b90ccdd2c0cf55da4fafe90d71d10a68f18093ab8b123a329a686134b8d3b68c14b42486e77b7526a5d065bff80ac
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -1,23 +1,45 @@
|
|
1
1
|
# KashflowApi
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/Ed-ITSolutions/KashflowAPI.png?branch=master)](https://travis-ci.org/Ed-ITSolutions/KashflowAPI) [![Code Climate](https://codeclimate.com/github/Ed-ITSolutions/KashflowAPI.png)](https://codeclimate.com/github/Ed-ITSolutions/KashflowAPI) [![Coverage Status](https://coveralls.io/repos/Ed-ITSolutions/KashflowAPI/badge.png)](https://coveralls.io/r/Ed-ITSolutions/KashflowAPI)
|
4
|
+
|
3
5
|
KashflowApi provides an Active Record like interface to the Kashflow API.
|
4
6
|
|
7
|
+
# Install
|
8
|
+
|
9
|
+
You can install KashflowApi by adding it yo your `Gemfile` like this:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'kashflow_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
and running `bundle install`
|
16
|
+
|
5
17
|
# Usage
|
6
18
|
|
7
19
|
At the beginning of your program, or in an rails initializer call the configure block like so:
|
8
20
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
``` ruby
|
22
|
+
KashflowApi.configure do |c|
|
23
|
+
c.username = "Username"
|
24
|
+
c.password = "Password"
|
25
|
+
c.loggers = false
|
26
|
+
end
|
27
|
+
```
|
14
28
|
|
15
29
|
I recommend settings loggers to false so that you don't get all the soap exchanges echoed out.
|
16
30
|
|
17
31
|
You can now call methods on the models e.g.
|
18
32
|
|
19
|
-
|
33
|
+
``` ruby
|
34
|
+
KashflowApi::Customer.all
|
35
|
+
KashflowApi::Customer.find("Cust01")
|
36
|
+
KashflowApi::Customer.find_by_email("customer@domain.tld")
|
37
|
+
```
|
38
|
+
|
39
|
+
## Saving
|
40
|
+
|
41
|
+
All the Kashflow objects in the gem have a `.save` method which will either insert a new record or update the current one.
|
20
42
|
|
21
43
|
# More Info
|
22
44
|
|
23
|
-
For more info head over to the [wiki]
|
45
|
+
For more info head over to the [wiki](https://github.com/Ed-ITSolutions/KashflowAPI/wiki)
|
data/kashflow_api.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
# Development Dependencies
|
20
20
|
s.add_development_dependency "rspec"
|
21
|
-
s.add_development_dependency "simplecov"
|
22
21
|
|
23
22
|
# Runtime Dependencies
|
24
23
|
s.add_runtime_dependency "savon", "~> 2.3"
|
24
|
+
s.add_runtime_dependency "expects", "~> 0.0.3"
|
25
25
|
end
|
data/lib/kashflow_api.rb
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
# Gems
|
2
|
+
require 'expects'
|
2
3
|
require "savon"
|
4
|
+
|
5
|
+
module KashflowApi
|
6
|
+
def self.configure
|
7
|
+
@config = Config.new
|
8
|
+
yield @config
|
9
|
+
@api = Api.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.api
|
17
|
+
@api
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.api_methods
|
21
|
+
@api_methods ||= Api.method_list
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.client
|
25
|
+
@client ||= Client.new(@config)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.soap_objects
|
29
|
+
@soap_objects ||= []
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.add_soap_object(klass)
|
33
|
+
@soap_objects ||= []
|
34
|
+
@soap_objects.push klass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
3
38
|
# Kashflow Main Clases
|
4
39
|
require "kashflow_api/soap_object" # Soap Object Class
|
5
40
|
require "kashflow_api/config" # Config Class
|
@@ -18,27 +53,3 @@ require "kashflow_api/models/receipt" # Receipt Class
|
|
18
53
|
require "kashflow_api/models/supplier" # Supplier
|
19
54
|
# Version
|
20
55
|
require "kashflow_api/version"
|
21
|
-
|
22
|
-
module KashflowApi
|
23
|
-
def self.configure
|
24
|
-
@config = Config.new
|
25
|
-
yield @config
|
26
|
-
@api = Api.new
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.config
|
30
|
-
@config
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.api
|
34
|
-
@api
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.api_methods
|
38
|
-
@api_methods ||= Api.methods
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.client
|
42
|
-
@client ||= Client.new(@config)
|
43
|
-
end
|
44
|
-
end
|
data/lib/kashflow_api/api.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def self.generate_method_list
|
26
|
-
KashflowApi.client.client.operations
|
2
|
+
class Api
|
3
|
+
def initialize
|
4
|
+
unless KashflowApi.config.username && KashflowApi.config.password
|
5
|
+
raise "Username and Password required"
|
6
|
+
end
|
7
|
+
|
8
|
+
init_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.method_list
|
12
|
+
@methods ||= generate_method_list
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def init_class
|
18
|
+
KashflowApi.api_methods.each do |method|
|
19
|
+
self.class.send(:define_method, method) do |argument = nil|
|
20
|
+
KashflowApi::ApiCall.new(method, argument).make_call
|
27
21
|
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.generate_method_list
|
26
|
+
KashflowApi.client.client.operations
|
28
27
|
end
|
28
|
+
end
|
29
29
|
end
|
@@ -6,8 +6,11 @@ module KashflowApi
|
|
6
6
|
@method_sym = method.to_sym
|
7
7
|
set_method(method)
|
8
8
|
build_xml(argument)
|
9
|
-
|
10
|
-
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
|
12
|
+
def make_call
|
13
|
+
KashflowApi.client.call(self)
|
11
14
|
end
|
12
15
|
|
13
16
|
private
|
@@ -48,60 +51,21 @@ module KashflowApi
|
|
48
51
|
<Password>#{KashflowApi.config.password}</Password>\n"
|
49
52
|
end
|
50
53
|
|
51
|
-
def make_call
|
52
|
-
KashflowApi.client.call(self)
|
53
|
-
end
|
54
|
-
|
55
54
|
def argument_xml(argument)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
out = "<InvoiceNumber>#{argument}</InvoiceNumber>"
|
71
|
-
end
|
72
|
-
elsif @action == "update" || @action == "insert"
|
73
|
-
if @object == "customer"
|
74
|
-
out = "<custr>#{argument.to_xml}</custr>"
|
75
|
-
elsif @object == "supplier"
|
76
|
-
if @action == "insert"
|
77
|
-
out = "<supl>#{argument.to_xml}</supl>"
|
78
|
-
else
|
79
|
-
out = "<sup>#{argument.to_xml}</sup>"
|
80
|
-
end
|
81
|
-
elsif @object == "receipt"
|
82
|
-
if @field == "Line"
|
83
|
-
out = "<ReceiptID>#{argument.receiptid}</ReceiptID><InvLine>#{argument.to_xml}</InvLine>"
|
84
|
-
elsif @field == "Number"
|
85
|
-
out = "<ReceiptNumber>#{argument.receiptnumber}</ReceiptNumber><InvLine>#{argument.to_xml}</InvLine>"
|
86
|
-
else
|
87
|
-
out = "<Inv>#{argument.to_xml}</Inv>"
|
88
|
-
end
|
89
|
-
elsif @object == "invoice"
|
90
|
-
if @field == "Line"
|
91
|
-
out = "<InvoiceID>#{argument.invoiceid}</InvoiceID><InvLine>#{argument.to_xml}</InvLine>"
|
92
|
-
elsif @field == "Number"
|
93
|
-
out = "<InvoiceNumber>#{argument.invoicenumber}</InvoiceNumber><InvLine>#{argument.to_xml}</InvLine>"
|
94
|
-
else
|
95
|
-
out = "<Inv>#{argument.to_xml}</Inv>"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
elsif @action == "delete"
|
99
|
-
if @object == "customer"
|
100
|
-
out = "<CustomerID>#{argument}</CustomerID>"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
out
|
55
|
+
case @object
|
56
|
+
when "customer" || "customers"
|
57
|
+
return KashflowApi::Customer.build_arguments(@action, @object, @field, argument)
|
58
|
+
when "invoice"
|
59
|
+
return KashflowApi::Invoice.build_arguments(@action, @object, @field, argument)
|
60
|
+
when "quote"
|
61
|
+
return KashflowApi::Quote.build_arguments(@action, @object, @field, argument)
|
62
|
+
when "receipt"
|
63
|
+
return KashflowApi::Receipt.build_arguments(@action, @object, @field, argument)
|
64
|
+
when "supplier"
|
65
|
+
return KashflowApi::Supplier.build_arguments(@action, @object, @field, argument)
|
66
|
+
else
|
67
|
+
return ""
|
68
|
+
end
|
105
69
|
end
|
106
70
|
end
|
107
71
|
end
|
data/lib/kashflow_api/client.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
module KashflowApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
result = @client.call(api_call.method_sym, xml: api_call.xml)
|
14
|
-
raise "Incorrect username or password" if result.to_hash.first.last[:status_detail] == "Incorrect username or password"
|
15
|
-
raise "Your IP Address is not in the access list!" if result.to_hash.first.last[:status_detail] =~ /The IP address of .*? is not in the access list/
|
16
|
-
#raise api_call.xml if result.to_hash.first.last[:status] == "NO"
|
17
|
-
raise "Kashflow Error: #{result.to_hash.first.last[:status_detail]}" if result.to_hash.first.last[:status] == "NO"
|
18
|
-
return result
|
19
|
-
end
|
20
|
-
|
21
|
-
def client
|
22
|
-
@client
|
23
|
-
end
|
2
|
+
class Client
|
3
|
+
include Expects
|
4
|
+
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
expects config, KashflowApi::Config
|
9
|
+
|
10
|
+
@config = config
|
11
|
+
@url = "https://securedwebapp.com/api/service.asmx?WSDL"
|
12
|
+
@client = Savon.client(wsdl: @url, log: @config.loggers)
|
24
13
|
end
|
14
|
+
|
15
|
+
def call(api_call)
|
16
|
+
result = @client.call(api_call.method_sym, xml: api_call.xml)
|
17
|
+
handle_errors(result.to_hash)
|
18
|
+
return result
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_errors(hash)
|
22
|
+
raise "Incorrect username or password" if hash.first.last[:status_detail] == "Incorrect username or password"
|
23
|
+
raise "Your IP Address is not in the access list!" if hash.first.last[:status_detail] =~ /The IP address of .*? is not in the access list/
|
24
|
+
raise "Kashflow Error: #{result.to_hash.first.last[:status_detail]}" if hash.first.last[:status] == "NO"
|
25
|
+
end
|
26
|
+
end
|
25
27
|
end
|
@@ -1,86 +1,43 @@
|
|
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
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def destroy
|
45
|
-
KashflowApi.api.delete_customer(self.customer_id)
|
46
|
-
end
|
47
|
-
|
48
|
-
def balance
|
49
|
-
KashflowApi::CustomerBalance.new(self)
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_xml
|
53
|
-
xml = []
|
54
|
-
id_line = ""
|
55
|
-
@hash.keys.each do |key|
|
56
|
-
if key == :customer_id
|
57
|
-
id_line = "<CustomerID>#{@hash[key]}</CustomerID>" unless @hash[key] == "0"
|
58
|
-
else
|
59
|
-
key_name = key.to_s.split('_').map{|e| e.capitalize}.join
|
60
|
-
xml.push("<#{key_name}>#{@hash[key]}</#{key_name}>")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
[id_line, xml.join].join
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def blank_object_hash
|
69
|
-
{"Code" => "", "Name" => "", "Contact" => "", "Telephone" => "", "Mobile" => "", "Fax" => "", "Email" => "", "Address1" => "", "Address2" => "",
|
70
|
-
"Address3" => "", "Address4" => "", "Postcode" => "", "Website" => "", "Notes" => "", "ExtraText1" => "", "ExtraText2" => "",
|
71
|
-
"ExtraText3" => "", "ExtraText4" => "", "ExtraText5" => "", "ExtraText6" => "", "ExtraText7" => "", "ExtraText8" => "", "ExtraText9" => "",
|
72
|
-
"ExtraText10" => "", "ExtraText11" => "", "ExtraText12" => "", "ExtraText13" => "", "ExtraText14" => "", "ExtraText15" => "",
|
73
|
-
"ExtraText16" => "", "ExtraText17" => "", "ExtraText18" => "", "ExtraText19" => "", "ExtraText20" => "", "ContactTitle" => "",
|
74
|
-
"ContactFirstName" => "", "ContactLastName" => "", "CustHasDeliveryAddress" => "0", "DeliveryAddress1" => "",
|
75
|
-
"DeliveryAddress2" => "", "DeliveryAddress3" => "", "DeliveryAddress4" => "", "DeliveryPostcode" => ""}.merge(KashflowApi::Customer.find("").hash)
|
76
|
-
end
|
77
|
-
|
78
|
-
def update_customer
|
79
|
-
KashflowApi.api.update_customer(self)
|
80
|
-
end
|
81
|
-
|
82
|
-
def insert_customer
|
83
|
-
KashflowApi.api.insert_customer(self)
|
84
|
-
end
|
2
|
+
class Customer < KashflowApi::SoapObject
|
3
|
+
|
4
|
+
Keys = [
|
5
|
+
"Code", "Name", "Contact", "Telephone", "Mobile", "Fax", "Email", "Address1", "Address2", "Address3", "Address4", "Postcode",
|
6
|
+
"Website", "Notes", "ExtraText1", "ExtraText2", "ExtraText3", "ExtraText4", "ExtraText5", "ExtraText6", "ExtraText7", "ExtraText8",
|
7
|
+
"ExtraText9", "ExtraText10", "ExtraText11", "ExtraText12", "ExtraText13", "ExtraText14", "ExtraText15", "ExtraText16", "ExtraText17",
|
8
|
+
"ExtraText18", "ExtraText19", "ExtraText20", "ContactTitle", "ContactFirstName", "ContactLastName", ["CustHasDeliveryAddresss", "0"],
|
9
|
+
"DeliveryAddress1", "DeliveryAddress2", "DeliveryAddress3", "DeliveryAddress4", "DeliveryPostcode"
|
10
|
+
]
|
11
|
+
|
12
|
+
Finds = [ "code", "id", "email", "postcode" ]
|
13
|
+
|
14
|
+
KFObject = { singular: "customer", plural: "customers" }
|
15
|
+
|
16
|
+
XMLKey = "CustomerID"
|
17
|
+
|
18
|
+
define_methods
|
19
|
+
|
20
|
+
def self.build_arguments(action, object, field, argument)
|
21
|
+
if action == "get"
|
22
|
+
expects argument, String
|
23
|
+
return "<Customer#{field}>#{argument}</Customer#{field}>" if object == "customer"
|
24
|
+
return "<#{field}>#{argument}</#{field}>" if object == "customers"
|
25
|
+
elsif action == "update" || action == "insert"
|
26
|
+
expects argument, KashflowApi::Customer
|
27
|
+
return "<custr>#{argument.to_xml}</custr>" if object == "customer"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def save
|
32
|
+
if @hash[:customer_id] == "0"
|
33
|
+
insert_customer
|
34
|
+
else
|
35
|
+
update_customer
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def balance
|
40
|
+
KashflowApi::CustomerBalance.new(self)
|
85
41
|
end
|
86
|
-
end
|
42
|
+
end
|
43
|
+
end
|