ruconomic 0.9.12 → 0.9.13

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: 213c1cd50f2a4ec2abed8729c4e8fe8e82c3342a
4
- data.tar.gz: e98905303834acfd7c2aa0c284507f0571efe179
3
+ metadata.gz: f7cef861a618b0e6ac0caebb03a6f01ab6b8df45
4
+ data.tar.gz: df1d3875ce8cc8d9647dd347d7323b98c8ce76be
5
5
  SHA512:
6
- metadata.gz: c5c2bc669172acb021fc118780ada1a788544e1c8fb1eca83d2d1e0509717d087885b4d9b9af2d5f0453dc0cd2fffb377cbba7489bd6dc8af1f637291c210814
7
- data.tar.gz: 797388114ce6e57459f5cb9692a5c7c84a8f7c7345ed53e65514c54a8c94a88537ab57509acfb7b7a6dfe83e7498bb20bd90c3044f813413c2f6cd6713a089e7
6
+ metadata.gz: c3571616a5ac4954aa312eea60e611d761a30e33d9baa7215b27dec28ef16e4bc636f259db81f69bbb0b28c5f08fcbd3af376012d55f814f3e6e6e8ef7e75187
7
+ data.tar.gz: 7a27d759d3f6a6a7efc40106ba84c5aa3f1d46b41bf69044162740420ba477fe8046e76bc8d8da4ede73b1ab44aac4f605aff7ab7b705ca0d49794b702713ac9
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The ruconomic gem provides a lightweight, speedy and easy-to-use ruby wrapper for the [e-conomic](http://www.e-conomic.com) SOAP web service - it will build, parse and transport some XML and little else. For a more full SOAPedelic experience, have a look at [rconomic](https://github.com/lokalebasen/rconomic).
4
4
 
5
- This gem is intended to be a crowd source project. The [e-conomic webservice](https://api.e-conomic.com/secure/api1/EconomicWebService.asmx) implements ~1500 operations(!), and all those operations are mapped to ruby classes and methods under ```lib/ruconomic/api``` - but not fully implemented. As always, the best way to understand is to [browse the source](https://github.com/coherify/ruconomic/tree/master/lib/ruconomic/api).
5
+ This gem is intended to be a crowd source project. The [e-conomic webservice](https://api.e-conomic.com/secure/api1/EconomicWebService.asmx) implements ~1500 operations(!), and all those operations are mapped to ruby classes and methods under `lib/ruconomic/api` - but not fully implemented. As always, the best way to understand is to [browse the source](https://github.com/coherify/ruconomic/tree/master/lib/ruconomic/api).
6
6
 
7
7
  So, the idea is that we [add functionality](https://github.com/coherify/ruconomic#contributing) as needed.
8
8
 
@@ -71,7 +71,11 @@ end
71
71
 
72
72
  ## Documentation
73
73
 
74
- You can find the latest API documentation at [http://rdoc.info/github/coherify/ruconomic/index](http://rdoc.info/github/coherify/ruconomic/index) or generate your own copy with ```bundle install && bundle exec yardoc``` after cloning the repository.
74
+ You can find the latest API documentation at http://rdoc.info/github/coherify/ruconomic/index or generate your own copy with `bundle install && bundle exec yardoc` after cloning the repository.
75
+
76
+ ## Testing
77
+
78
+ Run the minitest suite with `bundle exec rake`
75
79
 
76
80
  ## Contributing
77
81
 
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ FileList["lib/tasks/*.rake"].each do |task|
4
+ import task
5
+ end
@@ -39,8 +39,7 @@ module Ruconomic
39
39
  end
40
40
  end
41
41
 
42
- response.to_hash[:cash_book_get_data_response] \
43
- [:cash_book_get_data_result]
42
+ response.fetch(:cash_book_get_data_response, :cash_book_get_data_result)
44
43
  end
45
44
 
46
45
  # Returns cash book data objects for a given set of cash book handles.
@@ -62,7 +61,7 @@ module Ruconomic
62
61
  def self.get_all
63
62
  response = invoke('CashBook_GetAll')
64
63
 
65
- response.to_hash[:cash_book_get_all_response][:cash_book_get_all_result]
64
+ response.fetch(:cash_book_get_all_response, :cash_book_get_all_result)
66
65
  end
67
66
 
68
67
  # Returns a handle for the cash book with the given number.
@@ -151,8 +150,7 @@ module Ruconomic
151
150
  end
152
151
  end
153
152
 
154
- response.to_hash[:cash_book_get_entries_response] \
155
- [:cash_book_get_entries_result]
153
+ response.fetch(:cash_book_get_entries_response, :cash_book_get_entries_result)
156
154
  end
157
155
 
158
156
  # Delete all entries from a cash book. Action that cannot be undone.
@@ -279,8 +279,7 @@ module Ruconomic
279
279
  end
280
280
  end
281
281
 
282
- response.to_hash[:current_invoice_get_text_line1_response] \
283
- [:current_invoice_get_text_line1_result]
282
+ response.fetch(:current_invoice_get_text_line1_response, :current_invoice_get_text_line1_result)
284
283
  end
285
284
 
286
285
  # Set the primary line of a current invoice.
@@ -296,7 +295,7 @@ module Ruconomic
296
295
  message.add 'value', text
297
296
  end
298
297
 
299
- response.to_hash[:current_invoice_set_text_line1]
298
+ response.fetch(:current_invoice_set_text_line1)
300
299
  end
301
300
 
302
301
  # Gets the secondary line of text of a current invoice.
@@ -324,7 +323,7 @@ module Ruconomic
324
323
  message.add 'value', text
325
324
  end
326
325
 
327
- response.to_hash[:current_invoice_set_text_line2]
326
+ response.fetch(:current_invoice_set_text_line2)
328
327
  end
329
328
 
330
329
  # Gets the other reference of a current invoice.
@@ -498,6 +497,7 @@ module Ruconomic
498
497
  data.add_optional('DebtorCountry', invoice_data.dig(:debtor_country))
499
498
  data.add_optional('DebtorEan', invoice_data.dig(:debtor_ean))
500
499
  data.add_handle('AttentionHandle', invoice_data.dig(:attention_handle, :id), 'Id')
500
+ data.add_handle('YourReferenceHandle', invoice_data.dig(:your_reference_handle, :id), 'Id')
501
501
  data.add('Date', invoice_data.dig(:date))
502
502
  data.add_handle('TermOfPaymentHandle', invoice_data.dig(:term_of_payment_handle, :id), 'Id')
503
503
  data.add('DueDate', invoice_data.dig(:due_date))
@@ -573,7 +573,7 @@ module Ruconomic
573
573
  end
574
574
  end
575
575
 
576
- response.to_hash[:current_invoice_get_data_response][:current_invoice_get_data_result]
576
+ response.fetch(:current_invoice_get_data_response, :current_invoice_get_data_result)
577
577
  end
578
578
 
579
579
  # Returns current invoice data objects for a given set of current invoice handles.
@@ -599,7 +599,7 @@ module Ruconomic
599
599
  end
600
600
  end
601
601
 
602
- response.to_hash[:current_invoice_create_response][:current_invoice_create_result][:id]
602
+ response.fetch(:current_invoice_create_response, :current_invoice_create_result, :id)
603
603
  end
604
604
 
605
605
  # Returns handles for all current invoices.
@@ -609,7 +609,7 @@ module Ruconomic
609
609
  def self.get_all
610
610
  response = invoke('CurrentInvoice_GetAll')
611
611
 
612
- response.to_hash[:current_invoice_get_all_response][:current_invoice_get_all_result]
612
+ response.fetch(:current_invoice_get_all_response, :current_invoice_get_all_result)
613
613
  end
614
614
 
615
615
  # Returns handles for the current invoices which have the given employee as OurReference.
@@ -682,7 +682,7 @@ module Ruconomic
682
682
  end
683
683
  end
684
684
 
685
- response.to_hash[:current_invoice_book_response][:current_invoice_book_result][:number]
685
+ response.fetch(:current_invoice_book_response, :current_invoice_book_result, :number)
686
686
  end
687
687
 
688
688
  # Books a current invoice.
@@ -709,7 +709,7 @@ module Ruconomic
709
709
  end
710
710
  end
711
711
 
712
- response.to_hash[:current_invoice_delete_response]
712
+ response.fetch(:current_invoice_delete_response)
713
713
  end
714
714
 
715
715
  # Gets handles for the lines of a current invoice.
@@ -1110,7 +1110,7 @@ module Ruconomic
1110
1110
  message.add 'value', due_date
1111
1111
  end
1112
1112
 
1113
- response.to_hash[:current_invoice_set_due_date_response]
1113
+ response.fetch(:current_invoice_set_due_date_response)
1114
1114
  end
1115
1115
 
1116
1116
  # Gets the currency of a current invoice.
@@ -307,8 +307,7 @@ module Ruconomic
307
307
  end
308
308
  end
309
309
 
310
- response.to_hash[:debtor_update_from_data_response] \
311
- [:debtor_update_from_data_result][:number]
310
+ response.fetch(:debtor_update_from_data_response, :debtor_update_from_data_result, :number)
312
311
  end
313
312
 
314
313
  # Returns a debtor data object for a given debtor.
@@ -323,7 +322,7 @@ module Ruconomic
323
322
  end
324
323
  end
325
324
 
326
- response.to_hash[:debtor_get_data_response][:debtor_get_data_result]
325
+ response.fetch(:debtor_get_data_response, :debtor_get_data_result)
327
326
  end
328
327
 
329
328
  # Returns debtor data objects for a given set of debtor handles.
@@ -828,7 +827,7 @@ module Ruconomic
828
827
  end
829
828
  end
830
829
 
831
- response.to_hash[:debtor_get_term_of_payment_response][:debtor_get_term_of_payment_result][:id]
830
+ response.fetch(:debtor_get_term_of_payment_response, :debtor_get_term_of_payment_result, :id)
832
831
  end
833
832
 
834
833
  # Sets the layout of a debtor. The value may be omitted.
@@ -855,7 +854,7 @@ module Ruconomic
855
854
  end
856
855
  end
857
856
 
858
- response.to_hash[:debtor_get_layout_response][:debtor_get_layout_result][:id]
857
+ response.fetch(:debtor_get_layout_response, :debtor_get_layout_result, :id)
859
858
  end
860
859
 
861
860
  # Gets a handle for the attention of a debtor.
@@ -971,7 +970,7 @@ module Ruconomic
971
970
  message.add 'vatZone', vat_zone
972
971
  end
973
972
 
974
- response.to_hash[:debtor_create_response][:debtor_create_result][:number]
973
+ response.fetch(:debtor_create_response, :debtor_create_result, :number)
975
974
  end
976
975
 
977
976
  # Return handles for all debtors
@@ -192,7 +192,7 @@ module Ruconomic
192
192
  def self.get_all
193
193
  response = invoke('Invoice_GetAll')
194
194
 
195
- response.to_hash[:invoice_get_all_response][:invoice_get_all_result]
195
+ response.fetch(:invoice_get_all_response, :invoice_get_all_result)
196
196
  end
197
197
 
198
198
  # Returns a handle for the invoice with the given number.
@@ -304,7 +304,7 @@ module Ruconomic
304
304
  end
305
305
  end
306
306
 
307
- response.to_hash[:invoice_get_pdf_response][:invoice_get_pdf_result]
307
+ response.fetch(:invoice_get_pdf_response, :invoice_get_pdf_result)
308
308
  end
309
309
 
310
310
  # Gets an OIO XML string representing an invoice.
@@ -331,7 +331,7 @@ module Ruconomic
331
331
  end
332
332
  end
333
333
 
334
- response.to_hash[:invoice_get_data_response][:invoice_get_data_result]
334
+ response.fetch(:invoice_get_data_response, :invoice_get_data_result)
335
335
  end
336
336
 
337
337
  # Returns invoice data objects for a given set of invoice handles.
@@ -3,6 +3,31 @@ module Ruconomic
3
3
  module InvoiceLine
4
4
  extend Ruconomic::WebService
5
5
 
6
+ def self.find_by_invoice_list(invoice_numbers)
7
+ response = invoke('InvoiceLine_FindByInvoiceList') do |message|
8
+ message.add 'invoiceHandles' do |handles|
9
+ invoice_numbers.each do |invoice_number|
10
+ handles.add 'InvoiceHandle' do |handle|
11
+ handle.add 'Number', invoice_number
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ result = response.to_hash.dig(
18
+ :invoice_line_find_by_invoice_list_response,
19
+ :invoice_line_find_by_invoice_list_result,
20
+ :invoice_line_handle
21
+ )
22
+
23
+ case result
24
+ when Array
25
+ result
26
+ when Hash
27
+ [result]
28
+ end
29
+ end
30
+
6
31
  # Returns an invoice line data object for a given invoice line.
7
32
  # Parameters: entityHandle: A handle for the invoice line.
8
33
  #
@@ -18,12 +43,31 @@ module Ruconomic
18
43
  # Returns invoice line data objects for a given set of invoice line handles.
19
44
  # Parameters: entityHandles: An array of the invoice line handles.
20
45
  #
21
- # @note TODO: This method was autogenerated from the WSDL - see https://github.com/coherify/ruconomic#contributing"
22
46
  # @see https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=InvoiceLine_GetDataArray
23
47
  # @return [Hash] The body content of the SOAP response.
24
- def self.get_data_array
48
+ def self.get_data_array(invoice_line_handles)
25
49
  response = invoke('InvoiceLine_GetDataArray') do |message|
26
- raise "TODO: This method was autogenerated from the WSDL - see https://github.com/coherify/ruconomic#contributing"
50
+ message.add 'entityHandles' do |handles|
51
+ invoice_line_handles.each do |invoice_line_handle|
52
+ handles.add 'InvoiceLineHandle' do |handle|
53
+ handle.add 'Id', invoice_line_handle.fetch(:id)
54
+ handle.add 'Number', invoice_line_handle.fetch(:number)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ result = response.to_hash.dig(
61
+ :invoice_line_get_data_array_response,
62
+ :invoice_line_get_data_array_result,
63
+ :invoice_line_data
64
+ )
65
+
66
+ case result
67
+ when Array
68
+ result
69
+ when Hash
70
+ [result]
27
71
  end
28
72
  end
29
73
 
@@ -4,6 +4,7 @@ require "ruconomic/soap/node"
4
4
  module Ruconomic
5
5
  module SOAP
6
6
  class Document < LibXML::XML::Document
7
+ class KeyError < StandardError; end
7
8
 
8
9
  def initialize(xml_version = "1.0")
9
10
  super(xml_version)
@@ -29,6 +30,25 @@ module Ruconomic
29
30
  h[:Envelope][:body]
30
31
  end
31
32
 
33
+ # Fetches a subnode as a hash. Errors if the path does not exist
34
+ # To be backwards compatible, it returns nil instead of error if the last part of the path is not found
35
+ def fetch(*path)
36
+ path.each.with_index.reduce(to_hash) do |hash, (key, index)|
37
+ case hash
38
+ when Hash
39
+ hash.fetch(key) do
40
+ if index == path.size - 1
41
+ nil
42
+ else
43
+ raise KeyError, "No such key path #{path.inspect} in document #{to_hash.inspect}"
44
+ end
45
+ end
46
+ else
47
+ raise KeyError, "Key path #{path.inspect} does not represent a hash in document #{to_hash.inspect}"
48
+ end
49
+ end
50
+ end
51
+
32
52
  # We want #string to return a Ruconomic::SOAP::Document and not a LibXML::XML::Document
33
53
  def self.string(value, options = {})
34
54
  document = Ruconomic::SOAP::Document.new
@@ -1,3 +1,3 @@
1
1
  module Ruconomic
2
- VERSION = "0.9.12"
2
+ VERSION = "0.9.13"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['test/**/test_*.rb']
5
+ end
6
+ desc "Run tests"
7
+
8
+ task default: :test
@@ -0,0 +1,52 @@
1
+ require "minitest/autorun"
2
+ require "ruconomic/soap/document"
3
+
4
+ module Ruconomic
5
+ module SOAP
6
+ describe Document do
7
+ describe "fetch" do
8
+ it "gets existing subnode" do
9
+ node = Node.new("foo")
10
+ node.add("bar", "baz")
11
+ document = Document.new
12
+ document << node
13
+
14
+ assert_equal("baz", document.fetch(:foo, :bar))
15
+ assert_equal({bar: "baz"}, document.fetch(:foo))
16
+ end
17
+
18
+ it "returns nil if it is the last path part that does not match" do
19
+ node = Node.new("foo")
20
+ node.add("bar", "baz")
21
+ document = Document.new
22
+ document << node
23
+
24
+ assert_nil(document.fetch(:bogus))
25
+ assert_nil(document.fetch(:foo, :bogus))
26
+ end
27
+
28
+ it "errors on missing key" do
29
+ node = Node.new("foo")
30
+ node.add("bar", "baz")
31
+ document = Document.new
32
+ document << node
33
+
34
+ assert_raises(Document::KeyError) do
35
+ document.fetch(:bogus, :foo)
36
+ end
37
+ end
38
+
39
+ it "errors on middle value not being a hash" do
40
+ node = Node.new("foo")
41
+ node.add("bar", "baz")
42
+ document = Document.new
43
+ document << node
44
+
45
+ assert_raises(Document::KeyError) do
46
+ document.fetch(:foo, :bar, :baz)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruconomic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tonni Tølbøll Lund Aagesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -189,7 +189,9 @@ files:
189
189
  - lib/ruconomic/soap/node.rb
190
190
  - lib/ruconomic/version.rb
191
191
  - lib/ruconomic/web_service.rb
192
+ - lib/tasks/test.rake
192
193
  - ruconomic.gemspec
194
+ - test/soap/test_document.rb
193
195
  homepage: https://github.com/coherify/ruconomic
194
196
  licenses:
195
197
  - MIT
@@ -210,9 +212,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
212
  version: '0'
211
213
  requirements: []
212
214
  rubyforge_project:
213
- rubygems_version: 2.6.6
215
+ rubygems_version: 2.5.2
214
216
  signing_key:
215
217
  specification_version: 4
216
218
  summary: Lightweight, speedy and easy-to-use ruby wrapper for the e-conomic.com SOAP
217
219
  web service
218
- test_files: []
220
+ test_files:
221
+ - test/soap/test_document.rb