easybill-rest-client 2.0.2

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 (87) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +152 -0
  4. data/README.md +8 -0
  5. data/Rakefile +4 -0
  6. data/config.json +5 -0
  7. data/easybill-rest-client.gemspec +29 -0
  8. data/lib/easybill-rest-client.rb +15 -0
  9. data/lib/easybill_rest_client/.document_address.rb.swp +0 -0
  10. data/lib/easybill_rest_client/.document_item.rb.swp +0 -0
  11. data/lib/easybill_rest_client/.document_payment.rb.swp +0 -0
  12. data/lib/easybill_rest_client/.document_recurring_options.rb.swp +0 -0
  13. data/lib/easybill_rest_client/.easybill_error.rb.swp +0 -0
  14. data/lib/easybill_rest_client/.log_formatter.rb.swp +0 -0
  15. data/lib/easybill_rest_client/.request_builder.rb.swp +0 -0
  16. data/lib/easybill_rest_client/.too_many_requests_error.rb.swp +0 -0
  17. data/lib/easybill_rest_client/api_client.rb +61 -0
  18. data/lib/easybill_rest_client/client.rb +39 -0
  19. data/lib/easybill_rest_client/customer.rb +70 -0
  20. data/lib/easybill_rest_client/customer_api.rb +15 -0
  21. data/lib/easybill_rest_client/document.rb +53 -0
  22. data/lib/easybill_rest_client/document_address.rb +19 -0
  23. data/lib/easybill_rest_client/document_api.rb +31 -0
  24. data/lib/easybill_rest_client/document_item.rb +34 -0
  25. data/lib/easybill_rest_client/document_payment.rb +15 -0
  26. data/lib/easybill_rest_client/document_payment_api.rb +15 -0
  27. data/lib/easybill_rest_client/document_recurring_options.rb +23 -0
  28. data/lib/easybill_rest_client/document_service_date.rb +12 -0
  29. data/lib/easybill_rest_client/generic_api.rb +39 -0
  30. data/lib/easybill_rest_client/pdf.rb +21 -0
  31. data/lib/easybill_rest_client/post_box.rb +24 -0
  32. data/lib/easybill_rest_client/post_box_api.rb +15 -0
  33. data/lib/easybill_rest_client/request.rb +107 -0
  34. data/lib/easybill_rest_client/request_logger.rb +24 -0
  35. data/lib/easybill_rest_client/response.rb +36 -0
  36. data/lib/easybill_rest_client/retry_on.rb +46 -0
  37. data/lib/easybill_rest_client/version.rb +5 -0
  38. data/log/.gitkeep +0 -0
  39. data/log/test.log +5723 -0
  40. data/script/.generate.swo +0 -0
  41. data/spec/.spec_helper.rb.swp +0 -0
  42. data/spec/fixtures/vcr/EasybillRestClient_CustomerApi/_customers_get/.returns_customers.yml.swo +0 -0
  43. data/spec/fixtures/vcr/EasybillRestClient_CustomerApi/_customers_get/.returns_customers.yml.swp +0 -0
  44. data/spec/fixtures/vcr/EasybillRestClient_CustomerApi/a_list_of_customers/gets_all_customers.yml +84 -0
  45. data/spec/fixtures/vcr/EasybillRestClient_CustomerApi/a_list_of_customers/gets_customers_matching_a_filter.yml +72 -0
  46. data/spec/fixtures/vcr/EasybillRestClient_CustomerApi/creates_updates_and_deletes_customer.yml +377 -0
  47. data/spec/fixtures/vcr/EasybillRestClient_Document/_all/returns_documents.yml +44 -0
  48. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_cancel/cancels_a_document.yml +212 -0
  49. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_create/creates_a_document.yml +53 -0
  50. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_delete/deletes_a_document.yml +174 -0
  51. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_find/returns_a_document.yml +57 -0
  52. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_find_all/paid_and_unpaid_documents_exist/returns_only_unpaid_documents.yml +795 -0
  53. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_find_all/returns_documents.yml +58 -0
  54. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_find_all/returns_documents_by_number.yml +58 -0
  55. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_finish/marks_a_drafted_document_as_finished.yml +212 -0
  56. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_get_pdf/returns_a_PDF.yml +3889 -0
  57. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_send_email/passes_on_additional_params.yml +63 -0
  58. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_send_email/sends_an_email.yml +63 -0
  59. data/spec/fixtures/vcr/EasybillRestClient_DocumentApi/_update/updates_a_document.yml +107 -0
  60. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_create/creates_a_document_payment.yml +195 -0
  61. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_delete/deletes_a_document_payment.yml +168 -0
  62. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_document_payments_get/returns_a_document_s_payments.yml +460 -0
  63. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_document_payments_post/creates_a_document_payment.yml +47 -0
  64. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_find/returns_a_document_payment.yml +66 -0
  65. data/spec/fixtures/vcr/EasybillRestClient_DocumentPaymentApi/_find_all/returns_document_payments.yml +66 -0
  66. data/spec/fixtures/vcr/EasybillRestClient_PostBoxApi/_delete/deletes_a_post_box.yml +174 -0
  67. data/spec/fixtures/vcr/EasybillRestClient_PostBoxApi/_find/returns_a_post_box.yml +72 -0
  68. data/spec/fixtures/vcr/EasybillRestClient_PostBoxApi/_find_all/returns_post_boxes.yml +73 -0
  69. data/spec/fixtures/vcr/EasybillRestClient_PostBoxApi/_post_boxes_get/returns_post_boxes.yml +52 -0
  70. data/spec/integration/.customer_api_spec.rb.swn +0 -0
  71. data/spec/integration/.customer_api_spec.rb.swo +0 -0
  72. data/spec/integration/customer_api_spec.rb +47 -0
  73. data/spec/integration/easybill_rest_client/document_api_spec.rb +129 -0
  74. data/spec/integration/easybill_rest_client/document_payment_api_spec.rb +55 -0
  75. data/spec/integration/easybill_rest_client/post_box_api_spec.rb +31 -0
  76. data/spec/lib/easybill_rest_client/.api_client_spec.rb.swp +0 -0
  77. data/spec/lib/easybill_rest_client/easybill_rest_api/.generic_api_spec.rb.swp +0 -0
  78. data/spec/lib/easybill_rest_client/generic_api_spec.rb +55 -0
  79. data/spec/lib/easybill_rest_client/pdf_spec.rb +29 -0
  80. data/spec/lib/easybill_rest_client/request_logger_spec.rb +14 -0
  81. data/spec/lib/easybill_rest_client/request_spec.rb +32 -0
  82. data/spec/lib/easybill_rest_client/retry_on_spec.rb +37 -0
  83. data/spec/spec_helper.rb +33 -0
  84. data/spec/support/.setup_api_client.rb.swo +0 -0
  85. data/spec/support/setup_client.rb +12 -0
  86. data/swagger.json +3964 -0
  87. metadata +257 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 92b006244a9142506053278b0b9c56fbb96e6b3cf58856cfd8a5296b08e7dbd1
4
+ data.tar.gz: a5ddb7245844485df70f46dd09d366790b957d97b6a413cb1bf0bf14be9f754f
5
+ SHA512:
6
+ metadata.gz: 190c9feb979a54ce7fcf84f4873956c9293a79a69ccaaac7e45df9b14b15427bb6605023c2b6ee3f2206195f96dbfe4afeddd68087cb1164b02b03f8c22b3594
7
+ data.tar.gz: 5bcc9802b9af857911cd7af7e92a4a4f20a2ff61092511297b06b9fb24289b1b1cba0b0f845b3e8604d48287df603161178efe5e17fcb7521e5abae7fc212471
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ gem 'rubocop-ci', git: 'https://github.com/ad2games/rubocop-ci'
data/Gemfile.lock ADDED
@@ -0,0 +1,152 @@
1
+ GIT
2
+ remote: https://github.com/ad2games/rubocop-ci
3
+ revision: 7a87c0c6579154915ad94e1ecfd7185b0c04d202
4
+ specs:
5
+ rubocop-ci (1.0.1)
6
+ brakeman-min (~> 4.0.1)
7
+ coffeelint (~> 1.16.0)
8
+ highline
9
+ rake
10
+ rubocop (~> 0.52.0)
11
+ rubocop-rspec (= 1.19.0)
12
+ scss_lint (~> 0.56.0)
13
+ slim_lint (~> 0.15.0)
14
+ terminal-table
15
+
16
+ PATH
17
+ remote: .
18
+ specs:
19
+ easybill-rest-client (2.0.2)
20
+ retryable (~> 2.0)
21
+ virtus (~> 1.0)
22
+
23
+ GEM
24
+ remote: https://rubygems.org/
25
+ specs:
26
+ addressable (2.5.2)
27
+ public_suffix (>= 2.0.2, < 4.0)
28
+ ast (2.4.0)
29
+ axiom-types (0.1.1)
30
+ descendants_tracker (~> 0.0.4)
31
+ ice_nine (~> 0.11.0)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ brakeman-min (4.0.1)
34
+ ruby2ruby (~> 2.4.0)
35
+ ruby_parser (~> 3.10.0)
36
+ safe_yaml (>= 1.0)
37
+ sexp_processor (~> 4.7)
38
+ coderay (1.1.2)
39
+ coercible (1.0.0)
40
+ descendants_tracker (~> 0.0.1)
41
+ coffee-script (2.4.1)
42
+ coffee-script-source
43
+ execjs
44
+ coffee-script-source (1.12.2)
45
+ coffeelint (1.16.1)
46
+ coffee-script
47
+ execjs
48
+ json
49
+ crack (0.4.3)
50
+ safe_yaml (~> 1.0.0)
51
+ descendants_tracker (0.0.4)
52
+ thread_safe (~> 0.3, >= 0.3.1)
53
+ diff-lcs (1.3)
54
+ equalizer (0.0.11)
55
+ execjs (2.7.0)
56
+ ffi (1.9.23)
57
+ hashdiff (0.3.7)
58
+ highline (1.7.10)
59
+ ice_nine (0.11.2)
60
+ json (2.1.0)
61
+ method_source (0.9.0)
62
+ parallel (1.12.1)
63
+ parser (2.5.1.0)
64
+ ast (~> 2.4.0)
65
+ powerpack (0.1.1)
66
+ pry (0.11.3)
67
+ coderay (~> 1.1.0)
68
+ method_source (~> 0.9.0)
69
+ public_suffix (3.0.2)
70
+ rainbow (3.0.0)
71
+ rake (12.3.1)
72
+ rb-fsevent (0.10.3)
73
+ rb-inotify (0.9.10)
74
+ ffi (>= 0.5.0, < 2)
75
+ retryable (2.0.4)
76
+ rspec (3.7.0)
77
+ rspec-core (~> 3.7.0)
78
+ rspec-expectations (~> 3.7.0)
79
+ rspec-mocks (~> 3.7.0)
80
+ rspec-core (3.7.1)
81
+ rspec-support (~> 3.7.0)
82
+ rspec-expectations (3.7.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.7.0)
85
+ rspec-mocks (3.7.0)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.7.0)
88
+ rspec-support (3.7.1)
89
+ rubocop (0.52.1)
90
+ parallel (~> 1.10)
91
+ parser (>= 2.4.0.2, < 3.0)
92
+ powerpack (~> 0.1)
93
+ rainbow (>= 2.2.2, < 4.0)
94
+ ruby-progressbar (~> 1.7)
95
+ unicode-display_width (~> 1.0, >= 1.0.1)
96
+ rubocop-rspec (1.19.0)
97
+ rubocop (>= 0.51.0)
98
+ ruby-progressbar (1.9.0)
99
+ ruby2ruby (2.4.1)
100
+ ruby_parser (~> 3.1)
101
+ sexp_processor (~> 4.6)
102
+ ruby_parser (3.10.1)
103
+ sexp_processor (~> 4.9)
104
+ safe_yaml (1.0.4)
105
+ sass (3.5.6)
106
+ sass-listen (~> 4.0.0)
107
+ sass-listen (4.0.0)
108
+ rb-fsevent (~> 0.9, >= 0.9.4)
109
+ rb-inotify (~> 0.9, >= 0.9.7)
110
+ scss_lint (0.56.0)
111
+ rake (>= 0.9, < 13)
112
+ sass (~> 3.5.3)
113
+ sexp_processor (4.11.0)
114
+ slim (3.0.9)
115
+ temple (>= 0.7.6, < 0.9)
116
+ tilt (>= 1.3.3, < 2.1)
117
+ slim_lint (0.15.1)
118
+ rake (>= 10, < 13)
119
+ rubocop (>= 0.50.0)
120
+ slim (~> 3.0)
121
+ sysexits (~> 1.1)
122
+ sysexits (1.2.0)
123
+ temple (0.8.0)
124
+ terminal-table (1.8.0)
125
+ unicode-display_width (~> 1.1, >= 1.1.1)
126
+ thread_safe (0.3.6)
127
+ tilt (2.0.8)
128
+ unicode-display_width (1.3.3)
129
+ vcr (3.0.3)
130
+ virtus (1.0.5)
131
+ axiom-types (~> 0.1)
132
+ coercible (~> 1.0)
133
+ descendants_tracker (~> 0.0, >= 0.0.3)
134
+ equalizer (~> 0.0, >= 0.0.9)
135
+ webmock (2.3.2)
136
+ addressable (>= 2.3.6)
137
+ crack (>= 0.3.2)
138
+ hashdiff
139
+
140
+ PLATFORMS
141
+ ruby
142
+
143
+ DEPENDENCIES
144
+ easybill-rest-client!
145
+ pry
146
+ rspec (~> 3.4)
147
+ rubocop-ci!
148
+ vcr (~> 3.0)
149
+ webmock (~> 2.1)
150
+
151
+ BUNDLED WITH
152
+ 1.16.2
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # easybill-rest-client [![Circle CI](https://circleci.com/gh/ad2games/easybill-rest-client/tree/master.svg?style=svg)](https://circleci.com/gh/ad2games/easybill-rest-client/tree/master)
2
+
3
+ A client library for the Easybill REST API
4
+
5
+ ## TODO
6
+
7
+ * Add more integration tests
8
+ * Add usage information
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop-ci'
data/config.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "gemName": "easybill-rest-client",
3
+ "moduleName": "EasybillRestClient",
4
+ "gemVersion": "1.0.0"
5
+ }
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'easybill_rest_client/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'easybill-rest-client'
8
+ s.version = EasybillRestClient::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['ad2games GmbH']
11
+ s.email = ['developers@ad2games.com']
12
+ s.homepage = 'http://ad2games.com'
13
+ s.summary = 'A ruby wrapper for the Easybill REST API'
14
+ s.description = 'A ruby wrapper for the Easybill REST API'
15
+ s.license = 'MIT'
16
+
17
+ s.add_runtime_dependency 'retryable', '~> 2.0'
18
+ s.add_runtime_dependency 'virtus', '~> 1.0'
19
+
20
+ s.add_development_dependency 'pry'
21
+ s.add_development_dependency 'rspec', '~> 3.4'
22
+ s.add_development_dependency 'vcr', '~> 3.0'
23
+ s.add_development_dependency 'webmock', '~> 2.1'
24
+
25
+ s.files = `find *`.split("\n").uniq.sort.reject(&:empty?)
26
+ s.test_files = `find spec/*`.split("\n")
27
+ s.executables = []
28
+ s.require_paths = %w[lib]
29
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'virtus'
4
+
5
+ require 'easybill_rest_client/customer'
6
+ require 'easybill_rest_client/document_address'
7
+ require 'easybill_rest_client/document_item'
8
+ require 'easybill_rest_client/document_recurring_options'
9
+ require 'easybill_rest_client/document_service_date'
10
+ require 'easybill_rest_client/document'
11
+ require 'easybill_rest_client/post_box'
12
+ require 'easybill_rest_client/document_payment'
13
+ require 'easybill_rest_client/pdf'
14
+
15
+ require 'easybill_rest_client/client'
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+ require 'net/http'
6
+ require 'securerandom'
7
+
8
+ require 'easybill_rest_client/request'
9
+ require 'easybill_rest_client/response'
10
+
11
+ module EasybillRestClient
12
+ class ApiClient
13
+ DEFAULT_RETRY_COOL_OFF_TIME = 15
14
+ DEFAULT_TRIES = 5
15
+ MAX_PAGE_SIZE = 1000
16
+
17
+ def initialize(options = {})
18
+ @api_key = options.fetch(:api_key)
19
+ @retry_cool_off_time = options.fetch(:retry_cool_off_time, DEFAULT_RETRY_COOL_OFF_TIME)
20
+ @tries = options.fetch(:tries, DEFAULT_TRIES)
21
+ @logger = options.fetch(:logger, Logger.new($stdout))
22
+ end
23
+
24
+ def request_collection(method, endpoint, params = {})
25
+ fetch_pages do |page|
26
+ request(method, endpoint, params.merge(page: page, limit: MAX_PAGE_SIZE))
27
+ end
28
+ end
29
+
30
+ def request(method, endpoint, params = {})
31
+ request = Request.new(
32
+ api_key: api_key,
33
+ method: method,
34
+ endpoint: endpoint,
35
+ params: params,
36
+ logger: logger,
37
+ tries: tries,
38
+ retry_cool_off_time: retry_cool_off_time
39
+ )
40
+ Response.new(request.run).body
41
+ end
42
+
43
+ private
44
+
45
+ def fetch_pages
46
+ Enumerator.new do |y|
47
+ page = 1
48
+ loop do
49
+ collection = yield(page)
50
+ collection[:items].each do |item|
51
+ y << item
52
+ end
53
+ break if collection[:page] >= collection[:pages]
54
+ page += 1
55
+ end
56
+ end.lazy
57
+ end
58
+
59
+ attr_reader :api_key, :retry_cool_off_time, :tries, :logger
60
+ end
61
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'easybill_rest_client/api_client'
4
+ require 'easybill_rest_client/customer_api'
5
+ require 'easybill_rest_client/document_api'
6
+ require 'easybill_rest_client/post_box_api'
7
+ require 'easybill_rest_client/document_payment_api'
8
+
9
+ module EasybillRestClient
10
+ class Client
11
+ def initialize(options = {})
12
+ @options = options
13
+ end
14
+
15
+ def customers
16
+ @customers ||= CustomerApi.new(api_client)
17
+ end
18
+
19
+ def documents
20
+ @documents ||= DocumentApi.new(api_client)
21
+ end
22
+
23
+ def post_boxes
24
+ @post_boxes ||= PostBoxApi.new(api_client)
25
+ end
26
+
27
+ def document_payments
28
+ @document_payments ||= DocumentPaymentApi.new(api_client)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :options
34
+
35
+ def api_client
36
+ @api_client ||= ApiClient.new(options)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class Customer
5
+ include Virtus.model
6
+ values do
7
+ attribute :id, Integer
8
+ end
9
+ attribute :acquire_options, String # a digit 1..8
10
+ attribute :bank_account, String
11
+ attribute :bank_account_owner, String
12
+ attribute :bank_bic, String
13
+ attribute :bank_code, String
14
+ attribute :bank_iban, String
15
+ attribute :bank_name, String
16
+ attribute :birth_date, String
17
+ attribute :cash_allowance, String
18
+ attribute :cash_allowance_days, String
19
+ attribute :cash_discount, String
20
+ attribute :cash_discount_type, String
21
+ attribute :city, String
22
+ attribute :company_name, String
23
+ attribute :country, String
24
+ attribute :delivery_city, String
25
+ attribute :delivery_company_name, String
26
+ attribute :delivery_country, String
27
+ attribute :delivery_first_name, String
28
+ attribute :delivery_last_name, String
29
+ attribute :delivery_personal, String
30
+ attribute :delivery_salutation, String
31
+ attribute :delivery_street, String
32
+ attribute :delivery_suffix_1, String
33
+ attribute :delivery_suffix_2, String
34
+ attribute :delivery_zip_code, String
35
+ attribute :emails, Array[String]
36
+ attribute :fax, String
37
+ attribute :first_name, String
38
+ attribute :grace_period, String
39
+ attribute :group_id, String
40
+ attribute :info_1, String
41
+ attribute :info_2, String
42
+ attribute :internet, String
43
+ attribute :last_name, String
44
+ attribute :mobile, String
45
+ attribute :note, String
46
+ attribute :number, String
47
+ attribute :payment_options, String
48
+ attribute :personal, Boolean
49
+ attribute :phone_1, String
50
+ attribute :phone_2, String
51
+ attribute :postbox, String
52
+ attribute :postbox_city, String
53
+ attribute :postbox_country, String
54
+ attribute :postbox_zip_code, String
55
+ attribute :sale_price_level, String
56
+ attribute :salutation, String
57
+ attribute :sepa_agreement, String
58
+ attribute :sepa_agreement_date, String
59
+ attribute :sepa_mandate_reference, String
60
+ attribute :since_date, String
61
+ attribute :street, String
62
+ attribute :suffix_1, String
63
+ attribute :suffix_2, String
64
+ attribute :tax_number, String
65
+ attribute :tax_options, String
66
+ attribute :title, String
67
+ attribute :vat_identifier, String
68
+ attribute :zip_code, String
69
+ end
70
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'easybill_rest_client/generic_api'
4
+
5
+ module EasybillRestClient
6
+ class CustomerApi < GenericApi
7
+ def resource_name
8
+ 'customers'
9
+ end
10
+
11
+ def resource_class
12
+ Customer
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class Document
5
+ include Virtus.model
6
+ values do
7
+ attribute :id, Integer
8
+ end
9
+ attribute :address, DocumentAddress
10
+ attribute :amount_net, Integer
11
+ attribute :amount, Integer
12
+ attribute :bank_debit_form, String
13
+ attribute :cancel_id, Integer
14
+ attribute :cash_allowance_days, Integer
15
+ attribute :cash_allowance, String
16
+ attribute :cash_allowance_text, String
17
+ attribute :contact_id, Integer
18
+ attribute :contact_label, String
19
+ attribute :contact_text, String
20
+ attribute :created_at, DateTime
21
+ attribute :currency, String
22
+ attribute :customer_id, Integer
23
+ attribute :discount, String
24
+ attribute :discount_type, String
25
+ attribute :document_date, Date
26
+ attribute :due_date, Date
27
+ attribute :edited_at, String
28
+ attribute :grace_period, Integer
29
+ attribute :is_archive, Boolean
30
+ attribute :is_draft, Boolean
31
+ attribute :items, [DocumentItem]
32
+ attribute :label_address, DocumentAddress
33
+ attribute :number, String
34
+ attribute :paid_amount, Integer
35
+ attribute :paid_at, Date
36
+ attribute :pdf_pages, Integer
37
+ attribute :pdf_template, String
38
+ attribute :project_id, String
39
+ attribute :recurring_options, DocumentRecurringOptions
40
+ attribute :ref_id, Integer
41
+ attribute :service_date, DocumentServiceDate
42
+ attribute :status, String # TODO: enum
43
+ attribute :text_prefix, String
44
+ attribute :text, String
45
+ attribute :title, String
46
+ attribute :type, String # .enum(
47
+ # 'INVOICE', 'RECURRING', 'CREDIT', 'OFFER', 'REMINDER', 'DUNNING',
48
+ # 'STORNO', 'DELIVERY', 'CHARGE', 'CHARGE_CONFIRM', 'LETTER', 'ORDER'
49
+ # )
50
+ attribute :use_shipping_address, Boolean
51
+ attribute :vat_option, String
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class DocumentAddress
5
+ include Virtus.model
6
+ attribute :salutation, String
7
+ attribute :personal, Boolean
8
+ attribute :title, String
9
+ attribute :first_name, String
10
+ attribute :last_name, String
11
+ attribute :suffix_1, String
12
+ attribute :suffix_2, String
13
+ attribute :company_name, String
14
+ attribute :street, String
15
+ attribute :zip_code, String
16
+ attribute :city, String
17
+ attribute :country, String
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'easybill_rest_client/generic_api'
4
+
5
+ module EasybillRestClient
6
+ class DocumentApi < GenericApi
7
+ def resource_name
8
+ 'documents'
9
+ end
10
+
11
+ def resource_class
12
+ Document
13
+ end
14
+
15
+ def get_pdf(document_id)
16
+ api_client.request(:get, "/#{resource_name}/#{document_id}/pdf")
17
+ end
18
+
19
+ def send_email(document_id, email_params = {})
20
+ api_client.request(:post, "/#{resource_name}/#{document_id}/send/email", email_params)
21
+ end
22
+
23
+ def finish(document_id)
24
+ build(api_client.request(:put, "/#{resource_name}/#{document_id}/done"))
25
+ end
26
+
27
+ def cancel(document_id)
28
+ build(api_client.request(:post, "/documents/#{document_id}/cancel"))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class DocumentItem
5
+ include Virtus.model
6
+ values do
7
+ attribute :id, Integer
8
+ end
9
+ attribute :number, String
10
+ attribute :description, String
11
+ attribute :quantity, Integer
12
+ attribute :unit, String
13
+ attribute :type, String # TODO: enum
14
+ attribute :position, Integer
15
+ attribute :single_price_net, Float
16
+ attribute :single_price_gross, Float # TODO: Should we round here?
17
+ attribute :vat_percent, Integer
18
+ attribute :discount, Integer
19
+ attribute :discount_type, String
20
+ attribute :position_id, Integer
21
+ attribute :total_price_net, Float
22
+ attribute :total_price_gross, Float # TODO: Should we round here?
23
+ attribute :total_vat, Integer
24
+ attribute :serial_number_id, String
25
+ attribute :serial_number, String
26
+ attribute :booking_account, String
27
+ attribute :export_cost_1, String
28
+ attribute :export_cost_2, String
29
+ attribute :cost_price_net, Integer
30
+ attribute :cost_price_total, Integer
31
+ attribute :cost_price_charge, Integer
32
+ attribute :cost_price_charge_type, String
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class DocumentPayment
5
+ include Virtus.model
6
+ values do
7
+ attribute :id, Integer
8
+ end
9
+ attribute :amount, Integer
10
+ attribute :document_id, Integer
11
+ attribute :notice, String
12
+ attribute :payment_at, Date
13
+ attribute :type, String
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'easybill_rest_client/generic_api'
4
+
5
+ module EasybillRestClient
6
+ class DocumentPaymentApi < GenericApi
7
+ def resource_name
8
+ 'document-payments'
9
+ end
10
+
11
+ def resource_class
12
+ DocumentPayment
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class DocumentRecurringOptions
5
+ include Virtus.model
6
+ attribute :end_date_or_count, String
7
+ attribute :frequency_special, String # TODO: enum
8
+ attribute :frequency, String
9
+ attribute :interval, Integer
10
+ attribute :is_draft, Boolean
11
+ attribute :is_notify, Boolean
12
+ attribute :is_paid, Boolean
13
+ attribute :is_sepa, Boolean
14
+ attribute :is_sign, Boolean
15
+ attribute :next_date, Date
16
+ attribute :send_as, String # TODO: enum
17
+ attribute :sepa_local_instrument, String # TODO: enum
18
+ attribute :sepa_reference, String
19
+ attribute :sepa_remittance_information, String
20
+ attribute :sepa_sequence_type, String # TODO: enum
21
+ attribute :status, String # TODO: enum
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasybillRestClient
4
+ class DocumentServiceDate
5
+ include Virtus.model
6
+ attribute :type, String # TODO: enum
7
+ attribute :date, Date
8
+ attribute :date_from, Date
9
+ attribute :date_to, Date
10
+ attribute :text, String
11
+ end
12
+ end