clearbooks 0.16.3 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 540a736e7bc2040a84a2a925faef7060ece6f179
4
- data.tar.gz: 6b74558286b48bea1b1e7864e35ce83a8996c684
3
+ metadata.gz: 1af8b71d438200221b895de81c10918c5117b585
4
+ data.tar.gz: b048420193610f53fc13a4a15fb380c001a1fe5f
5
5
  SHA512:
6
- metadata.gz: 6d8fdc185c2d7fac8b79113c40f4a17282f556f9a62e60fe00b633eae0f2f25f7c20799838ffb05c23961df875d7a57da60bc1a20039348f887faa07b3ea99cb
7
- data.tar.gz: c85174c759dc0de9031108c2972407148ffb2c8b38b129b55c943c4d315547c83c1988c1f41d509777344b25293f38cabd889a1dfa64722c066b2d8e812288de
6
+ metadata.gz: eaac89d853482b6ef0ccbf848ec664814e69b87c3ef3d634623acaef5758283978c33ad6520ddeaa6619d2ae6eda690bf003746f2703969434e66cddea2758ab
7
+ data.tar.gz: 887c194c5d7ff22c6c35d48c199262685c7c72a0ec11e76bfdd457a70c0c0b28674568ecb941bccc6e14f09e15697649dfdd1f074030ed3cdf96beece20c5b2f
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Clearbooks
2
- Version 0.16.3
2
+ Version 0.18.1
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/clearbooks.svg)](http://badge.fury.io/rb/clearbooks)
5
5
  [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://img.shields.io/badge/license-MIT-brightgreen.svg)
@@ -191,6 +191,24 @@ Clearbooks.create_invoice Clearbooks::Invoice.new(
191
191
  ```
192
192
  Reference: https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
193
193
 
194
+ ### Clearbooks.void_invoice
195
+
196
+ Example:
197
+
198
+ ```ruby
199
+ Clearbooks.void_invoice(
200
+ 'purchases', # 'purchases' or 'sales'
201
+ 10 # Invoice id
202
+ ) # Clearbooks.void_invoice
203
+
204
+ # returns a Hash:
205
+
206
+ {
207
+ :@success => true,
208
+ :@msg => 'Some status message'
209
+ }
210
+ ```
211
+
194
212
  ## Managing entities
195
213
  ### Clearbooks.list_entities
196
214
 
@@ -226,6 +244,24 @@ Clearbooks.create_entity Clearbooks::Entity.new(
226
244
  ```
227
245
  Full list of options: https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
228
246
 
247
+ ### Clearbooks.update_entity
248
+
249
+ Example:
250
+
251
+ ```ruby
252
+ Clearbooks.update_entity Clearbooks::Entity.new(
253
+ id: 10,
254
+ company_name: 'Company',
255
+ contact_name: 'John Doe',
256
+ supplier: {
257
+ default_account_code: '1001001', # See Clearbooks.list_account_codes
258
+ default_credit_terms: 30,
259
+ default_vat_rate: 0
260
+ }
261
+ ) # Clearbooks::Entity.new
262
+ ```
263
+ Full list of options: https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
264
+
229
265
  ### Clearbooks.delete_entity
230
266
 
231
267
  Example:
@@ -450,7 +486,7 @@ Here is a current listing of all tasks:
450
486
 
451
487
 
452
488
  ```
453
- rake build # Build clearbooks-0.16.3.gem into the pkg directory
489
+ rake build # Build clearbooks-0.18.1.gem into the pkg directory
454
490
  rake cucumber:pretty # Run Cucumber features
455
491
  rake cucumber:progress # Run Cucumber features
456
492
  rake default # Show the default task when executing rake without arguments
@@ -458,8 +494,8 @@ rake docs:generate # Generate Yardoc documentation for this project
458
494
  rake docs:graph # Generate Yard Graphs for this project
459
495
  rake guard:default # Execute Ruby Guard
460
496
  rake help # Shows the usage help screen
461
- rake install # Build and install clearbooks-0.16.3.gem into system gems
462
- rake install:local # Build and install clearbooks-0.16.3.gem into system gems without network access
497
+ rake install # Build and install clearbooks-0.18.1.gem into system gems
498
+ rake install:local # Build and install clearbooks-0.18.1.gem into system gems without network access
463
499
  rake man:build # Build the manual pages
464
500
  rake man:clean # Clean up from the built man pages
465
501
  rake measurement:benchmark # When executing rake tasks measure elapsed time, used with other tasks
@@ -470,7 +506,7 @@ rake readme # Generate proper README file from templates
470
506
  rake readme:all # Generate proper README file from templates
471
507
  rake readme:subdirs # Builds generates readme files in all sub-directories
472
508
  rake readme:topdir # Generate top level README file from template
473
- rake release # Create tag v0.16.3 and build and push clearbooks-0.16.3.gem to Rubygems
509
+ rake release # Create tag v0.18.1 and build and push clearbooks-0.18.1.gem to Rubygems
474
510
  rake spec # RSpec Core Tasks
475
511
  rake todo # Look for TODO and FIXME tags in the code
476
512
  rake version # Git Tag number of this repo
@@ -496,7 +532,7 @@ thor :docs:generate # Generate Yardoc documentation for this project
496
532
  thor :docs:graph # Generate Yard Graphs for this project
497
533
  thor :guard:default # Execute Ruby Guard
498
534
  thor :help # Shows the usage help screen
499
- thor :install # Build and install clearbooks-0.16.3 .gem into system gems
535
+ thor :install # Build and install clearbooks-0.18.1 .gem into system gems
500
536
  thor :man:build # Build the manual pages
501
537
  thor :man:clean # Clean up from the built man pages
502
538
  thor :measurement:benchmark # When executing rake tasks measure elapsed time, used with other tasks
@@ -547,3 +583,4 @@ some basic assistance in finding the right person in charge of this section of t
547
583
  Please refer to the COPYING.md and LICENSE.md file.
548
584
  Unless otherwise stated in those files all remains protected and copyrighted by Bjoern Rennhak
549
585
  (bjoern AT greylon DOT com).
586
+
@@ -42,6 +42,16 @@ class Hash
42
42
  end
43
43
  end # }}}
44
44
 
45
+ # @fn def camelize_keys {{{
46
+ # @brief Converts keys to camel case
47
+ def camelize_keys
48
+ self.inject(Hash.new) do |h, (k, v)|
49
+ kk = k.to_s.camelize :lower
50
+ kk = kk.to_sym if k.is_a? Symbol
51
+ h[kk] = v
52
+ h
53
+ end
54
+ end # }}}
45
55
  end
46
56
 
47
57
 
@@ -19,31 +19,50 @@ module Clearbooks
19
19
 
20
20
  extend Savon::Model
21
21
 
22
- client wsdl: Clearbooks.config.wsdl,
23
- log: Clearbooks.config.log,
24
- logger: Clearbooks.config.logger,
25
- soap_header: { 'tns:authenticate' => '', attributes!: {'tns:authenticate' => { apiKey: Clearbooks.config.api_key } } }
22
+ client wsdl: Clearbooks.config.wsdl,
23
+ log: Clearbooks.config.log,
24
+ logger: Clearbooks.config.logger,
25
+ log_level: Clearbooks.config.log_level,
26
+ soap_header: {'tns:authenticate' => '',
27
+ attributes!: {'tns:authenticate' =>
28
+ {apiKey: Clearbooks.config.api_key}}}
26
29
 
27
- operations :create_invoice, :list_invoices, :create_entity, :list_entities, :delete_entity,
28
- :create_project, :list_projects, :list_account_codes, :create_journal,
29
- :delete_journal, :create_payment, :allocate_payment
30
+ operations :create_invoice,
31
+ :list_invoices,
32
+ :void_invoice,
30
33
 
34
+ :create_entity,
35
+ :list_entities,
36
+ :delete_entity,
37
+ :update_entity,
31
38
 
32
- # @fn def list_invoices {{{
33
- # @brief Get list of invoices from Clearbooks API
34
- #
35
- # @param [Hash] query Hash of options to filter invoices. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/listinvoices/
36
- #
37
- # @return [Array, Invoice] An array or invoices.
38
- #
39
- # @example Clearbooks.list_invoices
40
- #
39
+ :create_project,
40
+ :list_projects,
41
+
42
+ :list_account_codes,
43
+
44
+ :create_journal,
45
+ :delete_journal,
46
+ :create_payment,
47
+ :allocate_payment
48
+
49
+ # @fn def list_invoices {{{
50
+ # @brief Get list of invoices from Clearbooks API.
51
+ # @param [Hash] query Hash of options to filter invoices. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/listinvoices/
52
+ # @return [Array, Invoice] An array or invoices.
53
+ # @example
54
+ # Clearbooks.list_invoices
41
55
  def list_invoices query = {}
42
- defaults = { ledger: :sales }
43
- query = defaults.merge(query)
44
- response = super message: {query: '', attributes!: {query: query}}
45
- response = response.to_hash
46
- Invoice.build response[:list_invoices_response][:create_invoices_return][:invoice]
56
+ defaults = { ledger: :sales }
57
+ attributes = defaults.merge(query)
58
+ entity_id = attributes.delete :entity_id
59
+ invoice_id = attributes.delete :id
60
+ children = {}
61
+ children[:entityId] = {'xsd:integer' => entity_id} if entity_id
62
+ children[:id] = {'xsd:integer' => invoice_id} if invoice_id
63
+ response = super message: {query: children, attributes!: {query: attributes}}
64
+ response = response.to_hash
65
+ Invoice.build response[:list_invoices_response][:create_invoices_return].andand[:invoice]
47
66
  end # }}}
48
67
 
49
68
  # @fn def create_invoice {{{
@@ -75,21 +94,38 @@ module Clearbooks
75
94
  }
76
95
  end # }}}
77
96
 
78
- # @fn def create_entity {{{
79
- # @brief Creates entity via Clearbooks API
80
- #
81
- # @param [Entity] entity An entity to be created. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
82
- #
83
- # @return [Hash] [:entity_id] ID of the created entity.
84
- #
97
+ # @fn def void_invoice {{{
98
+ # @brief Voids invoice via Clearbooks API.
99
+ # Operation taken from WSDL schema https://secure.clearbooks.co.uk/api/wsdl/
100
+ # @param [String] ledger 'sales' or 'purchases'.
101
+ # @param [Fixnum] invoice_id Invoice id.
102
+ # @return [Hash] [:@success, :@msg] Boolean result of the operation and a short message describing an error (if any).
103
+ # @example
104
+ # Clearbooks.void_invoice 'purchases', 10
105
+ def void_invoice ledger, invoice_id
106
+ message = {
107
+ invoice: {
108
+ :@type => ledger,
109
+ :@id => invoice_id
110
+ }
111
+ }
112
+ response = super message: message
113
+ response = response.to_hash
114
+ response[:void_invoice_response][:void_success]
115
+ end
116
+
117
+ # @fn def create_entity {{{
118
+ # @brief Creates entity via Clearbooks API.
119
+ # @param [Entity] entity An entity to be created. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
120
+ # @return [Hash] [:entity_id] ID of the created entity.
85
121
  # @example
86
- # Clearbooks.create_entity Clearbooks::Entity.new(company_name: 'DataLogic',
87
- # contact_name: 'Oleg Kukareka',
88
- # address1: 'Kiev',
89
- # country: 'UA',
90
- # postcode: '04073',
91
- # email: 'info@datalogic.co.uk',
92
- # website: 'https://datalogic.co.uk',
122
+ # Clearbooks.create_entity Clearbooks::Entity.new(company_name: 'Example Inc.',
123
+ # contact_name: 'John Doe',
124
+ # address1: 'London',
125
+ # country: 'UK',
126
+ # postcode: '01100',
127
+ # email: 'info@example.com',
128
+ # website: 'http://example.com',
93
129
  # phone1: '01234 567890',
94
130
  # supplier: {
95
131
  # default_account_code: '1001001',
@@ -103,7 +139,33 @@ module Clearbooks
103
139
  { entity_id: response[:create_entity_response][:create_entity_return].to_i }
104
140
  end # }}}
105
141
 
106
- # @fn def list_entities {{{
142
+ # @fn def update_entity {{{
143
+ # @brief Updates entity via Clearbooks API.
144
+ # Operation taken from WSDL schema https://secure.clearbooks.co.uk/api/wsdl/
145
+ # @param [Entity] entity An entity to be updated. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
146
+ # @return [Hash] [:entity_id] ID of the updated entity.
147
+ # @example
148
+ # Clearbooks.create_entity Clearbooks::Entity.new(id: 10,
149
+ # company_name: 'Example Inc.',
150
+ # contact_name: 'John Doe',
151
+ # address1: 'London',
152
+ # country: 'UK',
153
+ # postcode: '01100',
154
+ # email: 'info@example.com',
155
+ # website: 'http://example.com',
156
+ # phone1: '01234 567890',
157
+ # supplier: {
158
+ # default_account_code: '1001001',
159
+ # default_credit_terms: 30,
160
+ # default_vat_rate: 0
161
+ # })
162
+ def update_entity entity
163
+ response = super message: {entityId: entity.id}.merge(entity.to_savon)
164
+ response = response.to_hash
165
+ { entity_id: response[:update_entity_response][:update_entity_return].to_i }
166
+ end # }}}
167
+
168
+ # @fn def list_entities {{{
107
169
  # @brief Get list of entities from Clearbooks API.
108
170
  # @param [Hash] query Hash of options to filter entities. See the list of available options in official docs: https://www.clearbooks.co.uk/support/api/docs/soap/list-entities/
109
171
  # @return [Array, Entity] An array or entities.
@@ -2,6 +2,8 @@
2
2
 
3
3
  # System include
4
4
  require 'yaml'
5
+ require 'andand'
6
+ require 'logger'
5
7
 
6
8
 
7
9
  # @module Clearbooks
@@ -11,8 +13,7 @@ module Clearbooks
11
13
  # @class Configuration
12
14
  # @brief Handles configurations of clearbooks gem such as api keys
13
15
  class Configuration
14
-
15
- attr_accessor :api_key, :wsdl, :log, :logger
16
+ attr_accessor :api_key, :wsdl, :log, :logger, :log_level
16
17
 
17
18
  # @fn def initialize
18
19
  # @brief Constructor for Clearbooks::Configuration class objects
@@ -20,10 +21,11 @@ module Clearbooks
20
21
  defaults = YAML.load_file(DEFAULT_CONFIG) rescue nil
21
22
  defaults ||= YAML.load_file(File.expand_path("~/#{DEFAULT_CONFIG}")) rescue Hash.new
22
23
 
23
- @api_key = ENV['CLEARBOOKS_API_KEY'] || defaults['api_key']
24
- @wsdl = defaults['wsdl'] || 'https://secure.clearbooks.co.uk/api/wsdl/'
25
- @logger = Logger.new(STDOUT) if @log = defaults['log']
26
-
24
+ @api_key = ENV['CLEARBOOKS_API_KEY'] || defaults['api_key']
25
+ @wsdl = defaults['wsdl'] || 'https://secure.clearbooks.co.uk/api/wsdl/'
26
+ @log = defaults['log'] || false
27
+ @logger = Logger.new(STDOUT)
28
+ @log_level = defaults['log_level'].andand.to_sym || :info
27
29
  self
28
30
  end # }}}
29
31
 
@@ -20,10 +20,12 @@ module Clearbooks
20
20
  #
21
21
  # @note Still returns an array when called with a hash representing a single item.
22
22
  def build data
23
- unless data.is_a? Array
24
- [ create(data) ]
23
+ if data.nil?
24
+ Array.new
25
+ elsif data.is_a? Array
26
+ data.map { |d| create(d) }
25
27
  else
26
- return data.map { |d| create(d) }
28
+ [ create(data) ]
27
29
  end
28
30
  end # }}}
29
31
 
@@ -56,7 +58,7 @@ module Clearbooks
56
58
  if date.nil? || date.is_a?(Date)
57
59
  date
58
60
  else
59
- DateTime.strptime date, '%Y-%m-%d %H:%M:%S'
61
+ DateTime.strptime(date, '%Y-%m-%d %H:%M:%S').to_date rescue Date.strptime(date, '%Y-%m-%d')
60
62
  end
61
63
  end # }}}
62
64
 
@@ -137,7 +137,7 @@ module Clearbooks
137
137
  # @param [Hash] data Entity attributes. For the list of available options see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
138
138
  #
139
139
  def initialize data
140
- @id = data.savon(:id).to_i
140
+ @id = Integer data.savon(:id) rescue nil
141
141
  @company_name = data.savon :company_name
142
142
  @contact_name = data.savon :contact_name
143
143
 
@@ -156,7 +156,7 @@ module Clearbooks
156
156
  @website = data.savon :website
157
157
 
158
158
  @statement_url = data.savon :statement_url
159
- @external_id = data.savon(:external_id).to_i
159
+ @external_id = data.savon :external_id
160
160
 
161
161
  @supplier = entity_extra data.savon :supplier
162
162
  @supplier = @supplier.from_savon if @supplier
@@ -211,7 +211,7 @@ module Clearbooks
211
211
  {
212
212
  :@default_account_code => extra[:default_account_code],
213
213
  :@default_vat_rate => extra[:default_vat_rate],
214
- :@default_credit_terms => extra[:default_credit_terms].to_i,
214
+ :@default_credit_terms => (Integer extra[:default_credit_terms] rescue nil),
215
215
  }.compact
216
216
  end
217
217
  end # }}}
@@ -13,7 +13,10 @@ module Clearbooks
13
13
 
14
14
  attr_reader :invoice_id, :date_created, :date_due, :date_accrual, :credit_terms, :description,
15
15
  :entity_id, :reference, :project, :status, :invoice_prefix,
16
- :invoice_number, :external_id, :statement_page, :date_modified, :items, :type, :bank_payment_id
16
+ :invoice_number, :external_id, :statement_page, :date_modified, :items, :type, :bank_payment_id,
17
+ :gross, :net, :vat, :paid, :balance, :external_id # FIXME add docs for new attributes
18
+
19
+ alias :id :invoice_id
17
20
 
18
21
  # @!attribute [r] invoice_id
19
22
  # @return [Fixnum] Invoice Id.
@@ -106,29 +109,36 @@ module Clearbooks
106
109
  #
107
110
  # @param [Hash] data Invoice attributes. For the list of available options see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
108
111
  def initialize data
109
- @invoice_id = data.savon(:invoice_id).to_i
112
+ @invoice_id = Integer data.savon(:invoice_id) rescue nil
110
113
 
111
- @date_created = parse_date data.savon(:date_created)
112
- @date_due = parse_date data.savon(:date_due)
114
+ @date_created = parse_date data.savon :date_created
115
+ @date_due = parse_date data.savon :date_due
113
116
 
114
- @credit_terms = data.savon(:credit_terms).to_i
117
+ @credit_terms = Integer data.savon(:credit_terms) rescue nil
115
118
  @description = data.savon :description
116
119
 
117
- @entity_id = data.savon(:entity_id).to_i
120
+ @entity_id = Integer data.savon(:entity_id) rescue nil
118
121
  @reference = data.savon :reference
119
- @project = data.savon(:project).to_i
122
+ @project = Integer data.savon(:project) rescue nil
120
123
  @status = data.savon :status
121
124
 
122
125
  @invoice_prefix = data.savon :invoice_prefix
123
126
  @invoice_number = data.savon :invoice_number
124
- @external_id = data.savon(:external_id).to_i
125
- @statement_page = data.savon :statement_page
127
+ @external_id = data.savon :external_id
128
+ @statement_page = CGI.unescapeHTML data.savon :statement_page rescue nil
129
+
130
+ @date_modified = parse_date data.savon :date_modified
131
+ @date_accrual = parse_date data.savon :date_accrual
126
132
 
127
- @date_modified = parse_date data.savon(:date_modified)
128
- @date_accrual = parse_date data.savon(:date_accrual)
133
+ @type = data.savon :type
134
+ @bank_payment_id = Integer data.savon(:bank_payment_id) rescue nil
129
135
 
130
- @type = data.savon(:type)
131
- @bank_payment_id = data.savon(:bank_payment_id).to_i
136
+ @gross = BigDecimal data.savon(:gross) rescue nil
137
+ @net = BigDecimal data.savon(:net) rescue nil
138
+ @vat = BigDecimal data.savon(:vat) rescue nil
139
+ @paid = BigDecimal data.savon(:paid) rescue nil
140
+ @balance = BigDecimal data.savon(:balance) rescue nil
141
+ @external_id = data.savon(:external_id)
132
142
 
133
143
  @items = Item.build( data[:items].is_a?(Array) ? data[:items] : data[:items][:item] )
134
144
  end # }}}
@@ -148,10 +158,11 @@ module Clearbooks
148
158
  :@creditTerms => @credit_terms,
149
159
  :@reference => @reference,
150
160
  :@project => @project,
161
+ :@external_id => @external_id,
151
162
 
152
163
  description: @description,
153
164
  items: { item: items.map(&:to_savon) }
154
- }
165
+ }.compact
155
166
  }
156
167
  end # }}}
157
168
 
@@ -66,9 +66,9 @@ module Clearbooks
66
66
  :@quantity => @quantity,
67
67
  :@type => @type,
68
68
  :@vat => @vat,
69
- :@vat_rate => @vat_rate,
69
+ :@vatRate => @vat_rate,
70
70
  :description => @description
71
- }
71
+ }.compact
72
72
  end # }}}
73
73
 
74
74
  end # of class Item
@@ -19,13 +19,13 @@ module Clearbooks
19
19
 
20
20
  describe '::create_entity' do
21
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',
22
+ Entity.new(company_name: 'Example Inc.',
23
+ contact_name: 'John Doe',
24
+ address1: 'London',
25
+ country: 'UL',
26
+ postcode: '01100',
27
+ email: 'info@example.com',
28
+ website: 'http://example.com',
29
29
  phone1: '01234 567890',
30
30
  supplier: {
31
31
  default_account_code: '1001001',
@@ -48,6 +48,38 @@ module Clearbooks
48
48
  end
49
49
  end
50
50
 
51
+ describe '::update_entity' do
52
+ let(:entity) do
53
+ Entity.new(id: 10,
54
+ company_name: 'Example Inc.',
55
+ contact_name: 'John Doe',
56
+ address1: 'London',
57
+ country: 'UK',
58
+ postcode: '01100',
59
+ email: 'info@example.com',
60
+ website: 'http://example.com',
61
+ phone1: '01234 567890',
62
+ supplier: {
63
+ default_account_code: '1001001',
64
+ default_credit_terms: 30,
65
+ default_vat_rate: 0
66
+ })
67
+ end
68
+
69
+ let(:xml) { File.read('spec/fixtures/response/update_entity.xml') }
70
+
71
+ let(:response) do
72
+ savon.expects(:update_entity).with(message: message).returns(xml)
73
+ Clearbooks.update_entity(entity)
74
+ end
75
+
76
+ it 'updates existing entity' do
77
+ expect(response).to be_a Hash
78
+ expect(response[:entity_id]).to be_a Fixnum
79
+ expect(response[:entity_id]).to be > 0
80
+ end
81
+ end
82
+
51
83
  describe '::list_entities' do
52
84
  let(:xml) { File.read('spec/fixtures/response/list_entities.xml') }
53
85
 
@@ -58,7 +90,7 @@ module Clearbooks
58
90
 
59
91
  it 'returns list of entnties' do
60
92
  expect(entities).to be_an Array
61
- expect(entities.length).to eq 4
93
+ expect(entities.length).to eq 2
62
94
  end
63
95
 
64
96
  describe Entity do
@@ -69,22 +101,22 @@ module Clearbooks
69
101
  end
70
102
 
71
103
  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'
104
+ expect(entity.id).to eq 6
105
+ expect(entity.company_name).to eq 'Example Inc.'
106
+ expect(entity.contact_name).to eq 'John Foo'
75
107
  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'
108
+ expect(entity.town).to eq 'London'
109
+ expect(entity.county).to eq 'United Kingdom'
110
+ expect(entity.postcode).to eq '01100'
111
+ expect(entity.email).to eq 'info@example.com'
80
112
  expect(entity.phone1).to eq '01234 567890'
81
113
  expect(entity.building).to eq 'Building2'
82
114
  expect(entity.address2).to eq 'Street2'
83
115
  expect(entity.phone2).to eq '1234 567890'
84
116
  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'
117
+ expect(entity.website).to eq 'http://example.com'
118
+ expect(entity.external_id).to eq '3'
119
+ expect(entity.statement_url).to eq 'https://secure.clearbooks.co.uk/'
88
120
  expect(entity.supplier[:default_account_code]).to eq '30'
89
121
  expect(entity.supplier[:default_vat_rate]).to eq '10'
90
122
  expect(entity.supplier[:default_credit_terms]).to eq 30
@@ -103,6 +103,20 @@ module Clearbooks
103
103
  expect(response[:invoice_number]).to eq '3'
104
104
  end
105
105
  end
106
+
107
+ describe '::void_invoice' do
108
+ let(:xml) { File.read('spec/fixtures/response/void_invoice.xml') }
109
+ let(:response) do
110
+ savon.expects(:void_invoice).with(message: message).returns(xml)
111
+ Clearbooks.void_invoice 'purchases', 10
112
+ end
113
+
114
+ it 'voids an invoice' do
115
+ expect(response).to be_a Hash
116
+ expect(response[:@success]).to eq 'true'
117
+ expect(response[:@msg]).to eq 'The invoice has been voided'
118
+ end
119
+ end
106
120
  end
107
121
  end
108
122
 
@@ -15,27 +15,11 @@
15
15
  <customer/>
16
16
  <bankAccount bankName="" name="" sortcode="" accountNumber=""/>
17
17
  </ns1:Entity>
18
- <ns1:Entity id="2" company_name="Doski LLC" contact_name="Mr John Foo" address1="1270 LONDON ROAD NORBURY"
19
- town="London" county="" postcode="SW164DH" email="john.foo@datalogic.ua" phone1="380672382496"
20
- building="DOSHI &amp; CO 1ST FLOOR WINDSOR HOUSE" address2="" phone2="" fax="" website=""
21
- date_modified="2015-04-27 17:39:23" external_id="" company_number="06889723"
22
- statement_url="https://secure.clearbooks.co.uk/s/58055:IVm_rJOxQvRyPODa-U77HQ">
23
- <supplier default_account_code="30" default_vat_rate="0" default_credit_terms="30"/>
24
- <bankAccount bankName="" name="" sortcode="" accountNumber=""/>
25
- </ns1:Entity>
26
- <ns1:Entity id="6" company_name="DataLogic" contact_name=" Oleg Kukareka" address1="Kiev" town="" county=""
27
- postcode="04073" email="info@datalogic.co.uk" phone1="01234 567890" building="" address2=""
28
- phone2="" fax="" website="https://datalogic.co.uk" date_modified="2015-04-28 15:59:17"
29
- external_id="0" company_number=""
30
- statement_url="https://secure.clearbooks.co.uk/s/58055:oGADQmCXvwNPIsBANlv9Xg">
31
- <supplier default_account_code="30" default_vat_rate="0" default_credit_terms="30"/>
32
- <bankAccount bankName="" name="" sortcode="" accountNumber=""/>
33
- </ns1:Entity>
34
- <ns1:Entity id="7" company_name="DataLogic" contact_name="Oleg Kukareka" address1="Street 1" town="Kiev" county="Ukraine"
35
- postcode="04073" email="info@datalogic.co.uk" phone1="01234 567890" building="Building2" address2="Street2"
36
- phone2="1234 567890" fax="2345 67890" website="https://datalogic.co.uk" date_modified="2015-04-28 16:10:57"
18
+ <ns1:Entity id="6" company_name="Example Inc." contact_name="John Foo" address1="Street 1" town="London" county="United Kingdom"
19
+ postcode="01100" email="info@example.com" phone1="01234 567890" building="Building2" address2="Street2"
20
+ phone2="1234 567890" fax="2345 67890" website="http://example.com" date_modified="2015-04-28 15:59:17"
37
21
  external_id="3" company_number=""
38
- statement_url="https://secure.clearbooks.co.uk/s/58055:YGD2d9_WFz6GvKUv4V4anw">
22
+ statement_url="https://secure.clearbooks.co.uk/">
39
23
  <supplier default_account_code="30" default_vat_rate="10" default_credit_terms="30"/>
40
24
  <bankAccount bankName="" name="" sortcode="" accountNumber=""/>
41
25
  </ns1:Entity>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3
+ xmlns:ns1="https://secure.clearbooks.co.uk/api/soap/">
4
+ <SOAP-ENV:Header>
5
+ <ns1:authenticate>true</ns1:authenticate>
6
+ </SOAP-ENV:Header>
7
+ <SOAP-ENV:Body>
8
+ <SOAP-ENV:updateEntityResponse>
9
+ <updateEntityReturn>6</updateEntityReturn>
10
+ </SOAP-ENV:updateEntityResponse>
11
+ </SOAP-ENV:Body>
12
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3
+ xmlns:ns1="https://secure.clearbooks.co.uk/api/soap/">
4
+ <SOAP-ENV:Header>
5
+ <ns1:authenticate>true</ns1:authenticate>
6
+ </SOAP-ENV:Header>
7
+ <SOAP-ENV:Body>
8
+ <SOAP-ENV:voidInvoiceResponse>
9
+ <voidSuccess success="true" msg="The invoice has been voided"/>
10
+ </SOAP-ENV:voidInvoiceResponse>
11
+ </SOAP-ENV:Body>
12
+ </SOAP-ENV:Envelope>
data/spec/spec_helper.rb CHANGED
@@ -21,6 +21,8 @@ RSpec.configure do |config|
21
21
  config.filter_run :focus
22
22
  config.order = 'random'
23
23
 
24
+ Clearbooks.config.api_key ||= ''
25
+
24
26
  end # of RSpec.configure
25
27
 
26
28
  # vim:ts=2:tw=100:wm=100:syntax=ruby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearbooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bjoern Rennhak
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-01 00:00:00.000000000 Z
12
+ date: 2015-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -146,6 +146,8 @@ files:
146
146
  - spec/fixtures/response/list_invoices.xml
147
147
  - spec/fixtures/response/list_projects.xml
148
148
  - spec/fixtures/response/no_api_key_fault.xml
149
+ - spec/fixtures/response/update_entity.xml
150
+ - spec/fixtures/response/void_invoice.xml
149
151
  - spec/fixtures/response/well_formed_request.xml
150
152
  - spec/fixtures/response/wrong_api_key_fault.xml
151
153
  - spec/spec_helper.rb
@@ -159,7 +161,7 @@ post_install_message: "
159
161
  | | ____| / | _ | __ ) / _ / _ | |/ / ___| \n | | | | | _| / _
160
162
  \ | |_) | _ | | | | | | | ' /___ \n | |___| |___| |___ / ___ | _ <| |_) |
161
163
  |_| | |_| | . ___) |\n ____|_____|_____/_/ __| _____/ ___/ ___/|_|_____/
162
- \n \n\n (c) 2015-05-01
164
+ \n \n\n (c) 2015-05-18
163
165
  00:00:00 UTC, All rights reserved\n Bjoern Rennhak, Greylon Ltd.\n\n Don't
164
166
  forget to get Clearbooks API key from http://clearbooks.co.uk\n and save it in
165
167
  ~/.clearbooks/config.yml:\n\n $ echo \"api_key: {your_api_key}\" >> ~/.clearbooks/config.yml\n\n
@@ -191,6 +193,7 @@ test_files:
191
193
  - spec/fixtures/response/list_invoices.xml
192
194
  - spec/fixtures/response/create_payment.xml
193
195
  - spec/fixtures/response/list_entities.xml
196
+ - spec/fixtures/response/update_entity.xml
194
197
  - spec/fixtures/response/no_api_key_fault.xml
195
198
  - spec/fixtures/response/create_entity.xml
196
199
  - spec/fixtures/response/create_project.xml
@@ -198,6 +201,7 @@ test_files:
198
201
  - spec/fixtures/response/delete_entity.xml
199
202
  - spec/fixtures/response/list_account_codes.xml
200
203
  - spec/fixtures/response/delete_journal.xml
204
+ - spec/fixtures/response/void_invoice.xml
201
205
  - spec/fixtures/response/wrong_api_key_fault.xml
202
206
  - spec/fixtures/response/create_journal.xml
203
207
  - spec/fixtures/response/allocate_payment.xml