clearbooks 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS.md +31 -0
  3. data/CHANGELOG.md +0 -0
  4. data/COPYING.md +12 -0
  5. data/FAQ.md +8 -0
  6. data/Gemfile +105 -0
  7. data/LICENSE.md +14 -0
  8. data/MAINTAINERS.md +40 -0
  9. data/README.md +549 -0
  10. data/Rakefile +94 -0
  11. data/Thorfile +80 -0
  12. data/bin/clearbooks +28 -0
  13. data/clearbooks.gemspec +119 -0
  14. data/examples/demo.rb +8 -0
  15. data/lib/clearbooks.rb +92 -0
  16. data/lib/clearbooks/core_ext.rb +8 -0
  17. data/lib/clearbooks/core_ext/array.rb +51 -0
  18. data/lib/clearbooks/core_ext/hash.rb +47 -0
  19. data/lib/clearbooks/core_ext/io_binary_read.rb +20 -0
  20. data/lib/clearbooks/core_ext/string.rb +21 -0
  21. data/lib/clearbooks/error.rb +8 -0
  22. data/lib/clearbooks/error/errors.rb +228 -0
  23. data/lib/clearbooks/interface/rake/cucumber.rb +36 -0
  24. data/lib/clearbooks/interface/rake/default.rb +28 -0
  25. data/lib/clearbooks/interface/rake/documentation.rb +45 -0
  26. data/lib/clearbooks/interface/rake/guard.rb +13 -0
  27. data/lib/clearbooks/interface/rake/helpers.rb +27 -0
  28. data/lib/clearbooks/interface/rake/library.rb +126 -0
  29. data/lib/clearbooks/interface/rake/metric.rb +15 -0
  30. data/lib/clearbooks/interface/rake/rspec.rb +31 -0
  31. data/lib/clearbooks/interface/thor/info.thor +292 -0
  32. data/lib/clearbooks/interface/thor/mixin/config_choice.rb +27 -0
  33. data/lib/clearbooks/interface/thor/mixin/configuration.rb +28 -0
  34. data/lib/clearbooks/interface/thor/mixin/default.rb +30 -0
  35. data/lib/clearbooks/interface/thor/mixin/default_config.rb +31 -0
  36. data/lib/clearbooks/interface/thor/mixin/guess.rb +57 -0
  37. data/lib/clearbooks/interface/thor/mixin/shell.rb +225 -0
  38. data/lib/clearbooks/interface/thor/version.thor +34 -0
  39. data/lib/clearbooks/library/client.rb +257 -0
  40. data/lib/clearbooks/library/configuration.rb +34 -0
  41. data/lib/clearbooks/model/account_code.rb +65 -0
  42. data/lib/clearbooks/model/base.rb +67 -0
  43. data/lib/clearbooks/model/entity.rb +225 -0
  44. data/lib/clearbooks/model/invoice.rb +163 -0
  45. data/lib/clearbooks/model/item.rb +78 -0
  46. data/lib/clearbooks/model/journal.rb +74 -0
  47. data/lib/clearbooks/model/ledger.rb +52 -0
  48. data/lib/clearbooks/model/payment.rb +113 -0
  49. data/lib/clearbooks/model/project.rb +58 -0
  50. data/lib/clearbooks/version.rb +12 -0
  51. data/spec/clearbooks/clearbooks_spec.rb +27 -0
  52. data/spec/clearbooks/model/account_code_spec.rb +52 -0
  53. data/spec/clearbooks/model/entity_spec.rb +107 -0
  54. data/spec/clearbooks/model/invoice_spec.rb +109 -0
  55. data/spec/clearbooks/model/journal_spec.rb +77 -0
  56. data/spec/clearbooks/model/payment_spec.rb +103 -0
  57. data/spec/clearbooks/model/project_spec.rb +72 -0
  58. data/spec/fixtures/response/allocate_payment.xml +12 -0
  59. data/spec/fixtures/response/create_entity.xml +12 -0
  60. data/spec/fixtures/response/create_invoice.xml +11 -0
  61. data/spec/fixtures/response/create_journal.xml +12 -0
  62. data/spec/fixtures/response/create_payment.xml +12 -0
  63. data/spec/fixtures/response/create_project.xml +12 -0
  64. data/spec/fixtures/response/delete_entity.xml +12 -0
  65. data/spec/fixtures/response/delete_journal.xml +12 -0
  66. data/spec/fixtures/response/list_account_codes.xml +168 -0
  67. data/spec/fixtures/response/list_entities.xml +45 -0
  68. data/spec/fixtures/response/list_invoices.xml +56 -0
  69. data/spec/fixtures/response/list_projects.xml +16 -0
  70. data/spec/fixtures/response/no_api_key_fault.xml +8 -0
  71. data/spec/fixtures/response/well_formed_request.xml +10 -0
  72. data/spec/fixtures/response/wrong_api_key_fault.xml +8 -0
  73. data/spec/spec_helper.rb +26 -0
  74. metadata +212 -0
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System include
5
+ require 'savon'
6
+
7
+ # Custom include
8
+ require 'spec_helper'
9
+
10
+
11
+ module Clearbooks
12
+
13
+ describe Clearbooks do
14
+
15
+ before(:all) { savon.mock! }
16
+ after(:all) { savon.unmock! }
17
+
18
+ let(:message) { :any }
19
+
20
+ describe '::create_entity' do
21
+ let(:entity) do
22
+ Entity.new(company_name: 'DataLogic',
23
+ contact_name: 'Oleg Kukareka',
24
+ address1: 'Kiev',
25
+ country: 'UA',
26
+ postcode: '04073',
27
+ email: 'info@datalogic.co.uk',
28
+ website: 'https://datalogic.co.uk',
29
+ phone1: '01234 567890',
30
+ supplier: {
31
+ default_account_code: '1001001',
32
+ default_credit_terms: 30,
33
+ default_vat_rate: 0
34
+ })
35
+ end
36
+
37
+ let(:xml) { File.read('spec/fixtures/response/create_entity.xml') }
38
+
39
+ let(:response) do
40
+ savon.expects(:create_entity).with(message: message).returns(xml)
41
+ Clearbooks.create_entity(entity)
42
+ end
43
+
44
+ it 'creates a new entity' do
45
+ expect(response).to be_a Hash
46
+ expect(response[:entity_id]).to be_a Fixnum
47
+ expect(response[:entity_id]).to be > 0
48
+ end
49
+ end
50
+
51
+ describe '::list_entities' do
52
+ let(:xml) { File.read('spec/fixtures/response/list_entities.xml') }
53
+
54
+ let(:entities) do
55
+ savon.expects(:list_entities).with(message: message).returns(xml)
56
+ Clearbooks.list_entities
57
+ end
58
+
59
+ it 'returns list of entnties' do
60
+ expect(entities).to be_an Array
61
+ expect(entities.length).to eq 4
62
+ end
63
+
64
+ describe Entity do
65
+ let(:entity) {entities.last}
66
+
67
+ it 'is an Entity' do
68
+ expect(entity).to be_an Entity
69
+ end
70
+
71
+ it 'has proper attribute values' do
72
+ expect(entity.id).to eq 7
73
+ expect(entity.company_name).to eq 'DataLogic'
74
+ expect(entity.contact_name).to eq 'Oleg Kukareka'
75
+ expect(entity.address1).to eq 'Street 1'
76
+ expect(entity.town).to eq 'Kiev'
77
+ expect(entity.county).to eq 'Ukraine'
78
+ expect(entity.postcode).to eq '04073'
79
+ expect(entity.email).to eq 'info@datalogic.co.uk'
80
+ expect(entity.phone1).to eq '01234 567890'
81
+ expect(entity.building).to eq 'Building2'
82
+ expect(entity.address2).to eq 'Street2'
83
+ expect(entity.phone2).to eq '1234 567890'
84
+ expect(entity.fax).to eq '2345 67890'
85
+ expect(entity.website).to eq 'https://datalogic.co.uk'
86
+ expect(entity.external_id).to eq 3
87
+ expect(entity.statement_url).to eq 'https://secure.clearbooks.co.uk/s/58055:YGD2d9_WFz6GvKUv4V4anw'
88
+ expect(entity.supplier[:default_account_code]).to eq '30'
89
+ expect(entity.supplier[:default_vat_rate]).to eq '10'
90
+ expect(entity.supplier[:default_credit_terms]).to eq 30
91
+ expect(entity.customer).to be_nil
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '::delete_entity' do
97
+ let(:xml) { File.read('spec/fixtures/response/delete_entity.xml') }
98
+
99
+ it 'deletes an entity with given id' do
100
+ savon.expects(:delete_entity).with(message: message).returns(xml)
101
+ expect(Clearbooks.delete_entity(1)).to eq true
102
+ end
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System include
5
+ require 'savon'
6
+
7
+ # Custom include
8
+ require 'spec_helper'
9
+
10
+
11
+ module Clearbooks
12
+
13
+ describe Clearbooks do
14
+
15
+ before(:all) { savon.mock! }
16
+ after(:all) { savon.unmock! }
17
+
18
+ let(:message) { :any }
19
+
20
+ describe '::list_invoices' do
21
+ let(:response) { File.read('spec/fixtures/response/list_invoices.xml') }
22
+ let(:invoices) do
23
+ savon.expects(:list_invoices).with(message: message).returns(response)
24
+ Clearbooks.list_invoices
25
+ end
26
+
27
+ it 'returns invoice list' do
28
+ expect(invoices).to be_an Array
29
+ expect(invoices.count).to eq 3
30
+ end
31
+
32
+ describe Invoice do
33
+ let(:invoice) { invoices.last }
34
+
35
+ it 'is an Invoice' do
36
+ expect(invoice).to be_an Invoice
37
+ end
38
+
39
+ it 'has proper attribute values' do
40
+ expect(invoice.entity_id).to eq 1
41
+ expect(invoice.invoice_id).to eq 3
42
+ expect(invoice.invoice_prefix).to eq 'INV'
43
+ expect(invoice.invoice_number).to eq '3'
44
+ expect(invoice.reference).to eq 'ref1'
45
+ expect(invoice.date_created).to eq Date.parse '2015-04-27 00:00:00'
46
+ expect(invoice.date_due).to eq Date.parse '2015-05-27 00:00:00'
47
+ expect(invoice.date_accrual).to eq Date.parse '2015-04-27 00:00:00'
48
+ expect(invoice.credit_terms).to eq 30
49
+ expect(invoice.project).to eq 7
50
+ expect(invoice.status).to eq 'approved'
51
+ expect(invoice.statement_page).to eq 'https://secure.clearbooks.co.uk/accounting/sales/invoice_html/?source=statement'
52
+ expect(invoice.type).to eq 'S'
53
+ end
54
+
55
+ it 'has items' do
56
+ expect(invoice.items).to be_an Array
57
+ expect(invoice.items.count).to eq 3
58
+ end
59
+
60
+ describe Item do
61
+ let (:item) { invoice.items.last }
62
+
63
+ it 'is an Item' do
64
+ expect(item).to be_an Item
65
+ end
66
+
67
+ it 'has proper description' do
68
+ expect(item.description).to eq '232323'
69
+ end
70
+
71
+ it 'has proper attribute values' do
72
+ expect(item.unit_price).to eq 5
73
+ expect(item.vat).to eq '2'
74
+ expect(item.quantity).to eq 1
75
+ expect(item.type).to eq '1001001'
76
+ expect(item.vat_rate).to eq '0.00:Out'
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '::create_invoice' do
83
+ let(:items) { [Item.new(description: 'abcd', unit_price: 9.99,
84
+ quantity: 5, type: '1001001', vat: 0, vat_rate: '0.00:Out'),
85
+ Item.new(description: 'abcd', unit_price: 19.99,
86
+ quantity: 7, type: '1001001', vat: 0, vat_rate: '0.00:Out')] }
87
+ let(:invoice) { Invoice.new(date_created: Date.today,
88
+ credit_terms: 30,
89
+ entity_id: 1,
90
+ type: 'purchases',
91
+ items: items)}
92
+ let(:xml) { File.read('spec/fixtures/response/create_invoice.xml') }
93
+ let(:response) do
94
+ savon.expects(:create_invoice).with(message: message).returns(xml)
95
+ Clearbooks.create_invoice(invoice)
96
+ end
97
+
98
+ it 'creates a new invoice' do
99
+ expect(response).to be_a Hash
100
+ expect(response[:due]).to eq 50
101
+ expect(response[:invoice_id]).to eq 3
102
+ expect(response[:invoice_prefix]).to eq 'PUR'
103
+ expect(response[:invoice_number]).to eq '3'
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System include
5
+ require 'savon'
6
+
7
+ # Custom include
8
+ require 'spec_helper'
9
+
10
+
11
+ module Clearbooks
12
+
13
+ describe Clearbooks do
14
+
15
+ before(:all) { savon.mock! }
16
+ after(:all) { savon.unmock! }
17
+
18
+ let(:message) { :any }
19
+
20
+ let(:description) { 'Journal1' }
21
+ let(:accounting_date) { '2015-05-01 00:00:00' }
22
+ let(:entity) { 100 }
23
+ let(:project) { 200 }
24
+ let(:accounts) { ['4001001', '4001002'] }
25
+ let(:amounts) { [19.99, 29.99] }
26
+ let(:ledgers) do
27
+ [accounts, amounts].transpose.map do |data|
28
+ Ledger.new(account: data[0], amount: data[1].to_s)
29
+ end
30
+ end
31
+
32
+ let(:journal) { Journal.new(description: description,
33
+ accounting_date: accounting_date,
34
+ entity: entity, project: project,
35
+ ledgers: ledgers) }
36
+
37
+ describe Journal do
38
+ describe :initialize do
39
+ it 'initializes new journal' do
40
+ expect(journal.description).to eq description
41
+ expect(journal.accounting_date).to eq Date.parse accounting_date
42
+ expect(journal.entity).to eq entity
43
+ expect(journal.project).to eq project
44
+ expect(journal.ledgers.length).to eq ledgers.length
45
+ journal.ledgers.each_with_index do |ledger, i|
46
+ expect(ledger.account).to eq accounts[i]
47
+ expect(ledger.amount).to eq amounts[i]
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '::create_journal' do
54
+ let(:xml) { File.read('spec/fixtures/response/create_journal.xml') }
55
+
56
+ let(:response) do
57
+ savon.expects(:create_journal).with(message: message).returns(xml)
58
+ Clearbooks.create_journal(journal)
59
+ end
60
+
61
+ it 'creates new journal' do
62
+ expect(response).to be_a Hash
63
+ expect(response[:journal_id]).to be_a Fixnum
64
+ expect(response[:journal_id]).to be > 0
65
+ end
66
+ end
67
+
68
+ describe '::delete_journal' do
69
+ let(:xml) { File.read('spec/fixtures/response/delete_journal.xml') }
70
+
71
+ it 'deletes a journal with given id' do
72
+ savon.expects(:delete_journal).with(message: message).returns(xml)
73
+ expect(Clearbooks.delete_journal(8)).to eq true
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System include
5
+ require 'savon'
6
+
7
+ # Custom include
8
+ require 'spec_helper'
9
+
10
+
11
+ module Clearbooks
12
+
13
+ describe Clearbooks do
14
+
15
+ before(:all) { savon.mock! }
16
+ after(:all) { savon.unmock! }
17
+
18
+ let(:message) { :any }
19
+
20
+ let(:accounting_date) { '2015-05-01 00:00:00' }
21
+ let(:type) { 'sales' }
22
+ let(:description) { 'Description1'}
23
+ let(:amount) { 59.99 }
24
+ let(:entity_id) { 1 }
25
+ let(:payment_method) { 1 }
26
+ let(:bank_account) { '7502001' }
27
+ let(:invoices) do
28
+ [ {id: 1, amount: '9.99'}, {id:9, amount: '19.99'} ]
29
+ end
30
+
31
+ let(:payment) { Payment.new(accounting_date: accounting_date,
32
+ type: type,
33
+ description: description,
34
+ amount: amount.to_s,
35
+ entity_id: entity_id,
36
+ payment_method: payment_method,
37
+ bank_account: bank_account,
38
+ invoices: invoices) }
39
+
40
+ describe Payment do
41
+
42
+ describe :initialize do
43
+ it 'initializes a new payment' do
44
+ expect(payment.accounting_date).to eq Date.parse(accounting_date)
45
+ expect(payment.type).to eq type
46
+ expect(payment.description).to eq description
47
+ expect(payment.amount).to eq amount
48
+ expect(payment.entity_id).to eq entity_id
49
+ expect(payment.payment_method).to eq payment_method
50
+ expect(payment.bank_account).to eq bank_account
51
+ expect(payment.invoices.length).to eq invoices.length
52
+
53
+ payment.invoices.each_with_index do |inv, i|
54
+ expect(inv[:id]).to eq invoices[i][:id]
55
+ expect(inv[:amount]).to eq invoices[i][:amount]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '.create_payment' do
62
+ let(:xml) { File.read('spec/fixtures/response/create_payment.xml') }
63
+
64
+ let(:response) do
65
+ savon.expects(:create_payment).with(message: message).returns(xml)
66
+ Clearbooks.create_payment(payment)
67
+ end
68
+
69
+ it 'creates new payment' do
70
+ expect(response).to be_a Hash
71
+ expect(response[:payment_id]).to be_a Fixnum
72
+ expect(response[:payment_id]).to be > 0
73
+ end
74
+ end
75
+
76
+ describe '.allocate_payment' do
77
+ let(:xml) { File.read('spec/fixtures/response/allocate_payment.xml') }
78
+
79
+ let(:params) do
80
+ {
81
+ payment_id: 1,
82
+ entity_id: 1,
83
+ type: 'sales',
84
+ invoices: [
85
+ {id: 1, amount: 9.99},
86
+ {id: 2, amount: 19.99}
87
+ ]
88
+ }
89
+ end
90
+
91
+ let(:response) do
92
+ savon.expects(:allocate_payment).with(message: message).returns(xml)
93
+ Clearbooks.allocate_payment(params)
94
+ end
95
+
96
+ it 'allocates a payment against an invoice or set of invoices' do
97
+ expect(response).to be_a Hash
98
+ expect(response[:success]).to be true
99
+ expect(response[:msg]).to eq 'The payment has been allocated'
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System include
5
+ require 'savon'
6
+
7
+ # Custom include
8
+ require 'spec_helper'
9
+
10
+
11
+ module Clearbooks
12
+
13
+ describe Clearbooks do
14
+
15
+ before(:all) { savon.mock! }
16
+ after(:all) { savon.unmock! }
17
+
18
+ let(:message) { :any }
19
+
20
+ describe '::create_project' do
21
+ let(:project) do
22
+ Project.new(description: 'Project 1 description',
23
+ project_name: 'Project 1 name',
24
+ status: 'open')
25
+ end
26
+
27
+ let(:xml) { File.read('spec/fixtures/response/create_project.xml') }
28
+
29
+ let(:response) do
30
+ savon.expects(:create_project).with(message: message).returns(xml)
31
+ Clearbooks.create_project(project)
32
+ end
33
+
34
+ it 'creates a new project' do
35
+ expect(response).to be_a Hash
36
+ expect(response[:project_id]).to be_a Fixnum
37
+ expect(response[:project_id]).to be > 0
38
+ end
39
+ end
40
+
41
+ describe '::list_projects' do
42
+ let(:xml) { File.read('spec/fixtures/response/list_projects.xml') }
43
+
44
+ let(:projects) do
45
+ savon.expects(:list_projects).with(message: message).returns(xml)
46
+ Clearbooks.list_projects
47
+ end
48
+
49
+ it 'returns list of projects' do
50
+ expect(projects).to be_an Array
51
+ expect(projects.length).to eq 3
52
+ end
53
+
54
+ describe Project do
55
+ let(:project) {projects.last}
56
+
57
+ it 'is a Project' do
58
+ expect(project).to be_a Project
59
+ end
60
+
61
+ it 'has proper attribute values' do
62
+ expect(project.project_name).to eq 'Project 3 name'
63
+ expect(project.status).to eq 'open'
64
+ expect(project.description).to eq 'description3'
65
+ expect(project.id).to eq 3
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ end