kashflow_api 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +2 -0
  5. data/README.markdown +29 -7
  6. data/kashflow_api.gemspec +1 -1
  7. data/lib/kashflow_api.rb +35 -24
  8. data/lib/kashflow_api/api.rb +25 -25
  9. data/lib/kashflow_api/api_call.rb +19 -55
  10. data/lib/kashflow_api/client.rb +24 -22
  11. data/lib/kashflow_api/models/customer.rb +41 -84
  12. data/lib/kashflow_api/models/invoice.rb +38 -36
  13. data/lib/kashflow_api/models/line.rb +46 -40
  14. data/lib/kashflow_api/models/nominal_code.rb +9 -8
  15. data/lib/kashflow_api/models/quote.rb +15 -11
  16. data/lib/kashflow_api/models/receipt.rb +35 -37
  17. data/lib/kashflow_api/models/supplier.rb +41 -58
  18. data/lib/kashflow_api/soap_object.rb +72 -30
  19. data/lib/kashflow_api/version.rb +1 -1
  20. data/{spec → spec-old}/kashflow_api_customer_balance_spec.rb +0 -0
  21. data/{spec → spec-old}/kashflow_api_customer_spec.rb +0 -0
  22. data/{spec → spec-old}/kashflow_api_nominal_codes_spec.rb +0 -0
  23. data/{spec → spec-old}/kashflow_api_quote_spec.rb +0 -0
  24. data/{spec → spec-old}/kashflow_api_receipt_spec.rb +0 -0
  25. data/{spec → spec-old}/kashflow_api_spec.rb +0 -0
  26. data/{spec → spec-old}/kashflow_api_supplier_spec.rb +0 -0
  27. data/spec-old/spec_helper.rb +21 -0
  28. data/{spec → spec-old}/test_data.example.yml +0 -0
  29. data/spec/core/api_call_spec.rb +25 -0
  30. data/spec/core/api_spec.rb +31 -0
  31. data/spec/core/client_spec.rb +23 -0
  32. data/spec/core/kashflow_api_spec.rb +14 -0
  33. data/spec/core/soap_object_spec.rb +25 -0
  34. data/spec/objects/customer_spec.rb +11 -0
  35. data/spec/objects/inherited_methods_spec.rb +45 -0
  36. data/spec/objects/invoice_spec.rb +6 -0
  37. data/spec/objects/line_spec.rb +5 -0
  38. data/spec/objects/nominal_code_spec.rb +5 -0
  39. data/spec/objects/quote_spec.rb +10 -0
  40. data/spec/objects/receipt_spec.rb +6 -0
  41. data/spec/objects/supplier_spec.rb +6 -0
  42. data/spec/spec_helper.rb +60 -15
  43. data/spec/support/macros.rb +53 -0
  44. metadata +49 -27
@@ -1,3 +1,3 @@
1
1
  module KashflowApi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'yaml'
5
+ require './lib/kashflow_api'
6
+
7
+ def default_config
8
+ KashflowApi.configure do |c|
9
+ c.username = yaml["username"]
10
+ c.password = yaml["password"]
11
+ c.loggers = false
12
+ end
13
+ end
14
+
15
+ def yaml
16
+ @yaml ||= YAML::load(File.open('spec/test_data.yml'))
17
+ end
18
+
19
+ def test_data(field)
20
+ @yaml[field]
21
+ end
File without changes
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe KashflowApi::ApiCall do
4
+ let(:config) do
5
+ KashflowApi.configure do |c|
6
+ c.username = "Foo"
7
+ c.password = "bar"
8
+ c.loggers = false
9
+ end
10
+ end
11
+
12
+ let(:example_customer) do
13
+ hash = {}
14
+ KashflowApi::Customer::Keys.each do |key|
15
+ hash[[*key].first] = "foo"
16
+ end
17
+ KashflowApi::Customer.new(hash)
18
+ end
19
+
20
+ it "should take a method and an argument" do
21
+ config
22
+
23
+ KashflowApi::ApiCall.new("foo_bar", "bar")
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ describe KashflowApi::Api do
2
+ let(:config) do
3
+ KashflowApi.blank
4
+
5
+ KashflowApi.configure do |c|
6
+ c.username = "foo"
7
+ c.password = "bar"
8
+ c.loggers = false
9
+ end
10
+ end
11
+
12
+ it "should require configuring" do
13
+ KashflowApi.blank
14
+
15
+ KashflowApi.api.should be_nil
16
+ end
17
+
18
+ it "should have a methods list" do
19
+ config
20
+
21
+ KashflowApi.api_methods.should be_a Array
22
+ KashflowApi::Api.methods.should be_a Array
23
+ KashflowApi::Api.methods.length.should >= 10
24
+ end
25
+
26
+ it "should define the methods on itself" do
27
+ a_method = KashflowApi.api_methods[10]
28
+
29
+ KashflowApi::Api.new().methods.include?(a_method).should be_true
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ describe KashflowApi::Client do
2
+ let(:config_object) do
3
+ config = KashflowApi::Config.new
4
+ config.username = "foo"
5
+ config.password = "foo"
6
+ config
7
+ end
8
+
9
+ let(:instance) do
10
+ KashflowApi::Client.new(config_object)
11
+ end
12
+
13
+ it "should take a config object" do
14
+ lambda { KashflowApi::Client.new("foo") }.should raise_exception
15
+ lambda { KashflowApi::Client.new(config_object) }.should_not raise_exception
16
+ end
17
+
18
+ it "should raise errors" do
19
+ lambda { instance.handle_errors([{stauts_detail: "Incorrect username or password"}]) }.should raise_exception
20
+ lambda { instance.handle_errors([{stauts_detail: "The IP address of 127.0.0.1 is not in the access list"}]) }.should raise_exception
21
+ lambda { instance.handle_errors([{status: "NO", stauts_detail: "There was a problem"}]) }.should raise_exception
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ #require 'spec_helper'
2
+
3
+ describe KashflowApi do
4
+ it "should accept a config block" do
5
+ KashflowApi.configure do |c|
6
+ c.username = "foo"
7
+ c.password = "bar"
8
+ end
9
+ end
10
+
11
+ it "should raise an exception if you don't provide a username and password" do
12
+ lambda { KashflowApi.configure do |c| end }.should raise_exception
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ describe KashflowApi::SoapObject do
2
+
3
+ let(:test_hash) do
4
+ { "CustomerID" => 1234, "Code" => "CUST01" }
5
+ end
6
+
7
+ let(:instance) do
8
+ KashflowApi::SoapObject.new(test_hash)
9
+ end
10
+
11
+ it "should take a hash" do
12
+ lambda { instance }.should_not raise_exception
13
+ lambda { KashflowApi::SoapObject.new("foo") }.should raise_exception
14
+ end
15
+
16
+ it "should create additional methods" do
17
+ instance.customerid = 12345
18
+ instance.customerid.should eq 12345
19
+ end
20
+
21
+ it "should have placed some classes into the soap_objects array" do
22
+ KashflowApi.soap_objects.should be_a Array
23
+ KashflowApi.soap_objects.first.should be_a Class
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ describe KashflowApi::Customer do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Customer)
5
+ it_should_have_arguments(KashflowApi::Customer, :get_customer, "foo", /CustomerCode/, :insert_customer, /custr/)
6
+
7
+ it "should make a call for all" do
8
+ results = KashflowApi::Customer.all
9
+ results.first.api_call.should be_a KashflowApi::ApiCall
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ describe "Inherited Methods" do
2
+ class SampleClass < KashflowApi::SoapObject
3
+ Keys = [ "Foo", "Bar", ["Widget", "hello"] ]
4
+
5
+ Finds = [ "foo", "bar" ]
6
+
7
+ KFObject = { singular: "foo", plural: "foos" }
8
+
9
+ XMLKey = "Foo"
10
+
11
+ define_methods
12
+ end
13
+
14
+ it "should define find_* methods" do
15
+ SampleClass.methods.include?(:find_by_bar).should be_true
16
+ end
17
+
18
+ it "should define find" do
19
+ SampleClass.methods.include?(:find).should be_true
20
+ end
21
+
22
+ it "should set the find_method" do
23
+ SampleClass.find_method.should eq :find_by_foo
24
+ SampleClass.send(SampleClass.find_method, "foo")
25
+ end
26
+
27
+ it "should find all" do
28
+ SampleClass.all.should be_a Array
29
+ end
30
+
31
+ it "should find by bar" do
32
+ SampleClass.find_by_bar("search")
33
+ end
34
+
35
+ it "should set defaults in hash" do
36
+ instance = SampleClass.new
37
+ instance.foo.should eq ""
38
+ instance.widget.should eq "hello"
39
+ end
40
+
41
+ it "should generate some HTML" do
42
+ instance = SampleClass.new
43
+ instance.to_xml.should be_a String
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ describe KashflowApi::Invoice do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Invoice)
5
+ it_should_have_arguments(KashflowApi::Invoice, :get_invoice, "100", /<InvoiceNumber>/, :insert_invoice, /<Inv>/)
6
+ end
@@ -0,0 +1,5 @@
1
+ describe KashflowApi::Line do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Line)
5
+ end
@@ -0,0 +1,5 @@
1
+ describe KashflowApi::NominalCode do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::NominalCode)
5
+ end
@@ -0,0 +1,10 @@
1
+ describe KashflowApi::Quote do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Quote)
5
+ it_should_have_arguments(KashflowApi::Quote, :get_quote_by_number, "100", /<QuoteNumber>/, :insert_quote, /<Inv>/)
6
+
7
+ it "should have overriden kfobjects from invoice" do
8
+ KashflowApi::Quote::KFObject[:singular].should eq "quote"
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ describe KashflowApi::Receipt do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Receipt)
5
+ it_should_have_arguments(KashflowApi::Receipt, :get_receipt, "100", /<ReceiptNumber>/, :insert_receipt, /<Inv>/)
6
+ end
@@ -0,0 +1,6 @@
1
+ describe KashflowApi::Supplier do
2
+ include ModelMacros
3
+
4
+ it_should_be_a_soap_model(KashflowApi::Supplier)
5
+ it_should_have_arguments(KashflowApi::Supplier, :get_supplier, "100", /<SupplierCode>/, :insert_supplier, /<supl>/)
6
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,21 +1,66 @@
1
1
  require 'simplecov'
2
+ require 'coveralls'
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
2
7
  SimpleCov.start
3
8
 
4
- require 'yaml'
5
- require './lib/kashflow_api'
9
+ require 'kashflow_api'
6
10
 
7
- def default_config
8
- KashflowApi.configure do |c|
9
- c.username = yaml["username"]
10
- c.password = yaml["password"]
11
- c.loggers = false
12
- end
13
- end
14
-
15
- def yaml
16
- @yaml ||= YAML::load(File.open('spec/test_data.yml'))
17
- end
11
+ require 'support/macros'
18
12
 
19
- def test_data(field)
20
- @yaml[field]
13
+ module KashflowApi
14
+ def self.blank
15
+ @api = nil
16
+ @client = nil
17
+ @config = nil
18
+ end
19
+
20
+ class Client
21
+ def call(api_call)
22
+ klass = Class.new do
23
+ def initialize(call)
24
+ @call = call
25
+ end
26
+
27
+ def hash
28
+ { envelope: { body: { get_customers_response: { get_customers_result: { customer: [ { api_call: @call } ] } } } } }
29
+ end
30
+ end
31
+ return klass.new(api_call)
32
+ end
33
+ end
34
+
35
+ class Api
36
+ def get_foos
37
+ klass = Class.new do
38
+ def hash
39
+ { envelope: { body: { get_foos_response: { get_foos_result: { foo: [] } } } } }
40
+ end
41
+ end
42
+
43
+ return klass.new
44
+ end
45
+
46
+ def get_foo(search)
47
+ klass = Class.new do
48
+ def hash
49
+ { envelope: { body: { get_foo_response: { get_foo_result: { foo: [] } } } } }
50
+ end
51
+ end
52
+
53
+ return klass.new
54
+ end
55
+
56
+ def get_foo_by_bar(search)
57
+ klass = Class.new do
58
+ def hash
59
+ { envelope: { body: { get_foo_by_bar_response: { get_foo_by_bar_result: { foo: [] } } } } }
60
+ end
61
+ end
62
+
63
+ return klass.new
64
+ end
65
+ end
21
66
  end
@@ -0,0 +1,53 @@
1
+ module ModelMacros
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ module ClassMethods
7
+ def it_should_be_a_soap_model(klass)
8
+ it "should have the correct constants" do
9
+ klass::Keys.should be_a Array
10
+ klass::Finds.should be_a Array
11
+ klass::KFObject.should be_a Hash
12
+ klass::XMLKey.should be_a String
13
+ end
14
+
15
+ it "should have a new object hash" do
16
+ klass.new.methods.include?(klass::Keys.first.downcase.to_sym).should be_true
17
+ end
18
+ end
19
+
20
+ def it_should_have_arguments(klass, get_method, get_argument, get_should_find, complex_method, complex_should_find)
21
+ it "should have the build_arguments method" do
22
+ klass.methods.include?(:build_arguments).should be_true
23
+ end
24
+
25
+ it "should have 2 branches to build_arguments" do
26
+ klass.build_arguments(:foo, :bar, :widget, "string")
27
+ klass.build_arguments(:foo, :bar, :widget, klass.new)
28
+ end
29
+
30
+ it "should be called by ApiCall" do
31
+ KashflowApi.configure do |c|
32
+ c.username = "foo"
33
+ c.password = "bar"
34
+ c.loggers = false
35
+ end
36
+
37
+ call = KashflowApi::ApiCall.new(get_method, get_argument)
38
+ call.xml.should =~ get_should_find
39
+ end
40
+
41
+ it "should be called by ApiCall" do
42
+ KashflowApi.configure do |c|
43
+ c.username = "foo"
44
+ c.password = "bar"
45
+ c.loggers = false
46
+ end
47
+
48
+ call = KashflowApi::ApiCall.new(complex_method, klass.new)
49
+ call.xml.should =~ complex_should_find
50
+ end
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kashflow_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam "Arcath" Laycock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-11 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: simplecov
28
+ name: savon
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: '2.3'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: savon
42
+ name: expects
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '2.3'
47
+ version: 0.0.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.3'
54
+ version: 0.0.3
55
55
  description: Provides an interface for the Kashflow API
56
56
  email:
57
57
  - gems@arcath.net
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - .travis.yml
63
64
  - Gemfile
64
65
  - README.markdown
65
66
  - Rakefile
@@ -79,15 +80,30 @@ files:
79
80
  - lib/kashflow_api/models/supplier.rb
80
81
  - lib/kashflow_api/soap_object.rb
81
82
  - lib/kashflow_api/version.rb
82
- - spec/kashflow_api_customer_balance_spec.rb
83
- - spec/kashflow_api_customer_spec.rb
84
- - spec/kashflow_api_nominal_codes_spec.rb
85
- - spec/kashflow_api_quote_spec.rb
86
- - spec/kashflow_api_receipt_spec.rb
87
- - spec/kashflow_api_spec.rb
88
- - spec/kashflow_api_supplier_spec.rb
83
+ - spec-old/kashflow_api_customer_balance_spec.rb
84
+ - spec-old/kashflow_api_customer_spec.rb
85
+ - spec-old/kashflow_api_nominal_codes_spec.rb
86
+ - spec-old/kashflow_api_quote_spec.rb
87
+ - spec-old/kashflow_api_receipt_spec.rb
88
+ - spec-old/kashflow_api_spec.rb
89
+ - spec-old/kashflow_api_supplier_spec.rb
90
+ - spec-old/spec_helper.rb
91
+ - spec-old/test_data.example.yml
92
+ - spec/core/api_call_spec.rb
93
+ - spec/core/api_spec.rb
94
+ - spec/core/client_spec.rb
95
+ - spec/core/kashflow_api_spec.rb
96
+ - spec/core/soap_object_spec.rb
97
+ - spec/objects/customer_spec.rb
98
+ - spec/objects/inherited_methods_spec.rb
99
+ - spec/objects/invoice_spec.rb
100
+ - spec/objects/line_spec.rb
101
+ - spec/objects/nominal_code_spec.rb
102
+ - spec/objects/quote_spec.rb
103
+ - spec/objects/receipt_spec.rb
104
+ - spec/objects/supplier_spec.rb
89
105
  - spec/spec_helper.rb
90
- - spec/test_data.example.yml
106
+ - spec/support/macros.rb
91
107
  homepage: http://ed-itsolutions.github.io/KashflowAPI
92
108
  licenses: []
93
109
  metadata: {}
@@ -112,13 +128,19 @@ signing_key:
112
128
  specification_version: 4
113
129
  summary: Provides an interface for the Kashflow API
114
130
  test_files:
115
- - spec/kashflow_api_customer_balance_spec.rb
116
- - spec/kashflow_api_customer_spec.rb
117
- - spec/kashflow_api_nominal_codes_spec.rb
118
- - spec/kashflow_api_quote_spec.rb
119
- - spec/kashflow_api_receipt_spec.rb
120
- - spec/kashflow_api_spec.rb
121
- - spec/kashflow_api_supplier_spec.rb
131
+ - spec/core/api_call_spec.rb
132
+ - spec/core/api_spec.rb
133
+ - spec/core/client_spec.rb
134
+ - spec/core/kashflow_api_spec.rb
135
+ - spec/core/soap_object_spec.rb
136
+ - spec/objects/customer_spec.rb
137
+ - spec/objects/inherited_methods_spec.rb
138
+ - spec/objects/invoice_spec.rb
139
+ - spec/objects/line_spec.rb
140
+ - spec/objects/nominal_code_spec.rb
141
+ - spec/objects/quote_spec.rb
142
+ - spec/objects/receipt_spec.rb
143
+ - spec/objects/supplier_spec.rb
122
144
  - spec/spec_helper.rb
123
- - spec/test_data.example.yml
145
+ - spec/support/macros.rb
124
146
  has_rdoc: