jortt 4.1.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rspec.yml +27 -0
  3. data/.ruby-version +1 -1
  4. data/README.md +75 -133
  5. data/Rakefile +0 -1
  6. data/jortt.gemspec +7 -7
  7. data/lib/jortt/client/customers.rb +71 -42
  8. data/lib/jortt/client/error.rb +33 -0
  9. data/lib/jortt/client/invoices.rb +55 -31
  10. data/lib/jortt/client/ledger_accounts.rb +27 -0
  11. data/lib/jortt/client/version.rb +1 -2
  12. data/lib/jortt/client.rb +65 -16
  13. data/lib/jortt.rb +0 -1
  14. data/spec/fixtures/vcr_cassettes/Jortt/_client/1_1_1.yml +64 -0
  15. data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_customers/1_1_1_1.yml +64 -0
  16. data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_invoices/1_1_2_1.yml +64 -0
  17. data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_ledger_accounts/1_1_3_1.yml +64 -0
  18. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/faulty_payload/shows_a_nice_error.yml +413 -0
  19. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/valid_payload/creates_the_customer.yml +505 -0
  20. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_delete/deletes_the_customer.yml +505 -0
  21. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_direct_debit_mandate/sends_direct_debit_mandate_to_the_customer_or_responds_with_an_error_when_not_possible.yml +470 -0
  22. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/query/returns_the_queried_customers.yml +464 -0
  23. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/without_params/returns_customers.yml +415 -0
  24. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_show/returns_the_customer.yml +464 -0
  25. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_update/updates_the_customer.yml +603 -0
  26. data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_vat_percentages/returns_the_vat_percentages.yml +330 -0
  27. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_create/creates_the_invoice.yml +170 -0
  28. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_credit/credits_the_invoice.yml +374 -0
  29. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_download/returns_the_invoice_download_link.yml +168 -0
  30. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/invoice_status/returns_those_invoices.yml +776 -0
  31. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/query/returns_the_queried_invoices.yml +315 -0
  32. data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_show/returns_the_invoice.yml +421 -0
  33. data/spec/fixtures/vcr_cassettes/Jortt_Client_LedgerAccounts/_index/returns_invoices.yml +118 -0
  34. data/spec/jortt/client/customers_spec.rb +109 -20
  35. data/spec/jortt/client/invoices_spec.rb +118 -20
  36. data/spec/jortt/client/ledger_accounts_spec.rb +19 -0
  37. data/spec/jortt/client_spec.rb +5 -27
  38. data/spec/jortt_spec.rb +2 -3
  39. data/spec/spec_helper.rb +18 -4
  40. metadata +85 -41
  41. data/.rubocop.yml +0 -26
  42. data/.travis.yml +0 -7
  43. data/lib/jortt/client/invoice.rb +0 -50
  44. data/spec/jortt/client/invoice_spec.rb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9fb355ea7092b575b6bea7c989535898af0aea62
4
- data.tar.gz: 62f389c052bac3710d7abd9672f1c1b86cb2cfb7
2
+ SHA256:
3
+ metadata.gz: cfce1585dc32518fb10a2d0bdb712186bb0a2746ba1367454e88601411516697
4
+ data.tar.gz: bc9d0972988bcaf7d74bd4c3bc2719bbe792cb873cbb294df5226a8bc7163eaa
5
5
  SHA512:
6
- metadata.gz: cbcb1bfc7f77b82498ae2c08feb079a95e965b833774b836e77d6866ffe563cbc5637eaeade9e68a42ee7374b64996dc08f370ee312be48009c4d465d20805d9
7
- data.tar.gz: 94009c1f00dedb5bc269f6496ed20859f998ce0928f331f34dee9ddd78c664ede83279ca68417ca43a0ded29aee277775980df4ace69dd2cc82d1a962e6b857b
6
+ metadata.gz: 24934871450f27a253940c5757b09e9298f04c9e0d4f62e002db8ea65e4c267923d97e2af8ef10c537ecd68baabcc712287b47e1f22b6468ffdb70448b33b6af
7
+ data.tar.gz: 8df956433f4b19e82d188382e048f212272acd5d8efdac9eede3cd95da41f07bc77b9c2ae52cfbfef00c010f280649a546b6a0736fb2f5155dda967aaaea80b1
@@ -0,0 +1,27 @@
1
+ name: rspec
2
+
3
+ on:
4
+ [push]
5
+
6
+ env:
7
+ RACK_ENV: test
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ include:
15
+ - ruby-version: 3.0.0
16
+ - ruby-version: 2.7
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true
26
+ - name: Run tests
27
+ run: bundle exec rspec
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 3.0.0
data/README.md CHANGED
@@ -1,141 +1,85 @@
1
1
  # Jortt REST API client
2
2
 
3
- [![Inline docs](
4
- http://inch-ci.org/github/jorttbv/jortt-ruby.svg?branch=master&style=flat
5
- )](http://inch-ci.org/github/jorttbv/jortt-ruby)
6
- [![Code Climate](
7
- http://img.shields.io/codeclimate/github/jorttbv/jortt-ruby.svg?style=flat
8
- )](https://codeclimate.com/github/jorttbv/jortt-ruby)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
9
4
  [![Code Coverage](
10
5
  https://codecov.io/github/jorttbv/jortt-ruby/coverage.svg?branch=master
11
6
  )](https://codecov.io/github/jorttbv/jortt-ruby?branch=master)
12
- [![Build Status](
13
- http://img.shields.io/travis/jorttbv/jortt-ruby.svg?style=flat
14
- )](https://travis-ci.org/jorttbv/jortt-ruby)
7
+ [![rspec Actions Status](https://github.com/jorttbv/jortt-ruby/workflows/rspec/badge.svg)](https://github.com/jorttbv/jortt-ruby/actions)
15
8
 
16
9
  A Ruby interface to the [Jortt](https://www.jortt.nl/) REST API.
17
10
 
18
- ## Usage
11
+ Check https://developer.jortt.nl/ for more info.
12
+
13
+ > THIS VERSION IS FOR THE NEW OAUTH API. STILL ON THE LEGACY API? USE VERSION 4.x OF THIS GEM: [CLICK HERE](https://github.com/jorttbv/jortt-ruby/tree/v4.2.0)
14
+
15
+ > THIS VERSION ONLY WORKS FOR CLIENT CREDENTIALS CURRENTLY.
16
+
17
+ ## Usage examples
19
18
 
20
19
  To create a jortt client:
21
20
  ```ruby
22
- jortt = Jortt.client(
23
- app_name: "application-name-as-chosen-on-jortt.nl",
24
- api_key: "api-key-as-provided-by-jortt.nl"
25
- )
21
+ jortt = Jortt.client('<your-client-id>', '<your-client-secret>')
26
22
  ```
27
23
 
28
24
  ### Customers
29
25
 
30
- Searching customers (`jortt.customers.search('Jortt')`) returns:
26
+ All customers (`jortt.customers.index(page: 2)`) returns:
31
27
  ```ruby
32
28
  [{
33
- company_name: 'Jortt',
34
- address: {
35
- street: "Transistorstraat 71C",
36
- postal_code: "1322 CK",
37
- city: "Almere",
38
- country_code: "NL"
39
- }
40
- },
41
- company_name: 'ttroj',
42
- address: {
43
- street: "Jorttweg",
44
- ...
45
- }
29
+ "id": "f8fd3e4e-da1c-43a7-892f-1410ac13e38a",
30
+ "is_private": true,
31
+ "customer_name": "Jortt",
32
+ "address_street": "Rozengracht 75a",
33
+ ...
46
34
  }]
47
35
  ```
48
36
 
49
37
  Adding customers:
50
38
  ```ruby
51
39
  jortt.customers.create(
52
- company_name: "Jortt B.V.",
53
- attn: "Vibiemme", # Optional
54
- extra_information: "The best cofee maker!", # Optional
55
- address: {
56
- street: "Transistorstraat 71C",
57
- postal_code: "1322 CK",
58
- city: "Almere",
59
- country_code: "NL"
60
- }
40
+ "is_private": true,
41
+ "customer_name": "Jortt",
42
+ ...
61
43
  )
62
44
  ```
63
45
 
64
46
  ### Invoices
65
- Searching invoices (`jortt.invoices.search('201606-012')`) returns:
47
+ Get invoices by ID (`jortt.invoices.get('934d59dd-76f6-4716-9e0f-82a618e1be21')`) returns:
66
48
  ```ruby
67
- [
68
- {
69
- "invoice_id": "934d59dd-76f6-4716-9e0f-82a618e1be21",
70
- "recipient": {
71
- "company_name": "Zilverine B.V.",
72
- "attn": null,
73
- "address": {
74
- "street": "Cruquisweg 109F",
75
- "city": "Amsterdam",
76
- "postal_code": "1111SX",
77
- "country": {
78
- "code": "NL",
79
- "name": "Nederland"
80
- }
81
- },
82
- "email": "ben@jortt.nl",
83
- "customer_id": "e1c5e15b-e34e-423e-a291-4ed43226a190",
84
- "extra_information": null,
85
- "shift_vat": null,
86
- "vat_number": null,
87
- "payment_term": 30
88
- },
89
- "recipient_in_eu": true,
90
- "organization": {
91
- "company_name": "Jortt BV",
92
- "company_name_line_2": null,
93
- "address": {
94
- "street": "Straat 1",
95
- "city": "Amsterdam",
96
- "postal_code": "1000 AA",
97
- "country": {
98
- "code": "NL",
99
- "name": "Nederland"
100
- }
101
- },
102
- "phonenumber": null,
103
- "bank_information": {
104
- "bic": "RABONL2U",
105
- "iban": "NL50RABO0150000001",
106
- "in_the_name_of": "Jortt B.V.",
107
- "description": null
108
- },
109
- "coc_number": "unique number",
110
- "vat_number": "NL821898279B01",
111
- "profession": null,
112
- "healthcare_data": null,
113
- "free_of_vat": false,
114
- "finance_email": "Jortt BV <compleet@jortt.nl>"
115
- },
116
- "line_items": [
117
- {
118
- "description": "Scrum",
119
- "vat": "0.21",
120
- "amount": "-100.0",
121
- "total_amount_ex_vat": "-100.0",
122
- "currency": "EUR",
123
- "quantity": "1.0"
49
+ {
50
+ "invoice_id": "934d59dd-76f6-4716-9e0f-82a618e1be21",
51
+ "recipient": {
52
+ "company_name": "Zilverline B.V.",
53
+ "attn": null,
54
+ "address": {
55
+ "street": "Cruquisweg 109F",
56
+ "city": "Amsterdam",
57
+ "postal_code": "1111SX",
58
+ "country": {
59
+ "code": "NL",
60
+ "name": "Nederland"
124
61
  }
125
- ],
126
- "invoice_currency": null,
127
- "invoice_total": "-100.0",
128
- "invoice_total_incl_vat": "-121.0",
129
- "invoice_number": "201607-011",
130
- "invoice_status": "paid",
131
- "invoice_due_date": "2016-08-06",
132
- "invoice_date": "2016-07-07",
133
- "invoice_delivery_period": "2016-07-01",
134
- "invoice_remarks": null,
135
- "invoice_language": "nl",
136
- "invoice_reference": null
62
+ },
63
+ "email": "ben@jortt.nl",
64
+ "customer_id": "e1c5e15b-e34e-423e-a291-4ed43226a190",
65
+ "extra_information": null,
66
+ ...
137
67
  }
138
- ]
68
+ ...
69
+ }
70
+ ```
71
+
72
+
73
+ Searching invoices (`jortt.invoices.index(query: '202001-002')`) returns:
74
+ ```ruby
75
+ [{
76
+ "id": "f8fd3e4e-da1c-43a7-892f-1410ac13e38a",
77
+ "invoice_status": "draft",
78
+ "customer_id": "f8fd3e4e-da1c-43a7-892f-1410ac13e38a",
79
+ "invoice_number": "202001-002",
80
+ "invoice_date": "2020-02-23",
81
+ ...
82
+ }]
139
83
 
140
84
  ```
141
85
 
@@ -143,35 +87,31 @@ Searching invoices (`jortt.invoices.search('201606-012')`) returns:
143
87
  Adding invoices:
144
88
  ```ruby
145
89
  jortt.invoices.create(
146
- customer_id: "123456789", # Optional
147
- delivery_period: "31-12-1234", # Optional
148
- reference: "my-reference", # Optional
90
+ customer_id: "f8fd3e4e-da1c-43a7-892f-1410ac13e38a",
91
+ invoice_date: "2020-02-23",
92
+ delivery_period: "2020-02-01",
93
+ payment_term: 14,
94
+ net_amounts: true,
95
+ send_method: "email",
96
+ introduction: "example",
97
+ remarks: "example",
98
+ payment_method: "pay_later",
149
99
  line_items: [
150
- {vat: 21, amount: 1359.50, quantity: 1, description: "Scrum Training"}
151
- ]
152
- )
153
- ```
154
-
155
- Sending invoices:
156
- ```ruby
157
- jortt.invoice(:invoice_id).send_invoice(
158
- mail_data: {
159
- to: 'ben@jortt.nl', # optional
160
- subject: 'Thank you for your assignment', # optional
161
- body: 'I hereby send you the invoice', # optional
162
- },
163
- invoice_date: Date.today, # optional
164
- payment_term: 7, # optional
165
- language: 'nl', # optional
166
- send_method: 'email', # optional
100
+ {
101
+ description: "this is a description example",
102
+ units: "3.14",
103
+ amount_per_unit: {
104
+ value: "365.00",
105
+ currency: "EUR"
106
+ },
107
+ vat_percentage: "21",
108
+ ledger_account_id: "f8fd3e4e-da1c-43a7-892f-1410ac13e38a"
109
+ }
110
+ ],
111
+ reference: "123"
167
112
  )
168
113
  ```
169
114
 
170
-
171
- ## Documentation
172
-
173
- Check https://app.jortt.nl/api-documentatie for more info.
174
-
175
115
  ## Development
176
116
 
177
117
  ### Running tests
@@ -188,3 +128,5 @@ by `require 'jortt/client'` and do your stuff).
188
128
  Make a fix, commit and push. Make sure the build is green. Then bump the
189
129
  version (edit `lib/jortt/client/version.rb`). Now `rake release` and follow
190
130
  the instructions (you need a rubygems.org account and permissions ;-)).
131
+
132
+ Otherwise `gem build jortt.gemspec` and `gem push jortt-[version].gem`.
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'bundler/gem_tasks'
3
2
  require 'rspec/core/rake_task'
4
3
 
data/jortt.gemspec CHANGED
@@ -27,14 +27,14 @@ Gem::Specification.new do |spec|
27
27
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_runtime_dependency 'rest-client', '~> 1.6'
30
+ spec.add_runtime_dependency 'rest-client', ['>= 2.0', '< 2.2']
31
+ spec.add_runtime_dependency 'oauth2', '~> 1.4.4'
31
32
 
32
- spec.add_development_dependency 'bundler', '~> 1.0'
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
34
  spec.add_development_dependency 'codecov', '~> 0.1'
34
- spec.add_development_dependency 'rake', '~> 10.0'
35
- spec.add_development_dependency 'rspec', '~> 3.4'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.7'
36
37
  spec.add_development_dependency 'rspec-its', '~> 1.2'
37
- spec.add_development_dependency 'webmock', '~> 1.17'
38
- spec.add_development_dependency 'rubocop', '~> 0.24.1'
39
- spec.add_development_dependency 'rubocop-rspec', '~> 1.1'
38
+ spec.add_development_dependency 'webmock', '~> 3.3'
39
+ spec.add_development_dependency 'vcr', '~> 6.0'
40
40
  end
@@ -1,72 +1,101 @@
1
- # encoding: UTF-8
2
- require 'rest-client'
3
-
4
1
  module Jortt # :nodoc:
5
2
  class Client # :nodoc:
6
-
7
3
  ##
8
4
  # Exposes the operations available for a collection of customers.
9
5
  #
10
6
  # @see { Jortt::Client.customers }
11
7
  class Customers
8
+ attr_accessor :client
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Returns all customers using the GET /customers endpoint.
16
+ # https://developer.jortt.nl/#list-customers
17
+ #
18
+ # @example
19
+ # client.customers.index(query: 'Jane')
20
+ #
21
+ def index(query: nil)
22
+ client.paginated('/customers', query: query)
23
+ end
12
24
 
13
- def initialize(config)
14
- @resource = RestClient::Resource.new(
15
- "#{config.base_url}/customers",
16
- user: config.app_name,
17
- password: config.api_key,
18
- )
25
+ ##
26
+ # Returns a customer using the GET /customers/{customer_id} endpoint.
27
+ # https://developer.jortt.nl/#get-customer-by-id
28
+ #
29
+ # @example
30
+ # client.customers.show("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
31
+ #
32
+ def show(id)
33
+ client.get("/customers/#{id}")
19
34
  end
20
35
 
21
36
  ##
22
37
  # Creates a Customer using the POST /customers endpoint.
23
- # See https://app.jortt.nl/api-documentatie#klant-aanmaken
38
+ # https://developer.jortt.nl/#create-customer
24
39
  #
25
40
  # @example
26
- # Jortt::Client.customers.create(
27
- # company_name: "Jortt B.V.", # mandatory
28
- # attn: "Finance department", # optional
29
- # email: "support@jortt.nl", # optional
30
- # extra_information: "Our valued customer", # optional
31
- # address: {
32
- # street: "Street 100", # mandatory
33
- # postal_code: "1000 AA", # mandatory
34
- # city: "Amsterdam", # mandatory
35
- # country_code: "NL" # mandatory
36
- # }
41
+ # client.customers.create(
42
+ # is_private: false,
43
+ # customer_name: 'Nuka-Cola Corporation',
44
+ # address_street: 'Vault 11',
45
+ # address_postal_code: '1111AA',
46
+ # address_city: 'Mojave Wasteland'
37
47
  # )
48
+ #
38
49
  def create(payload)
39
- resource.post(JSON.generate('customer' => payload)) do |response|
40
- JSON.parse(response.body)
41
- end
50
+ client.post('/customers', payload)
42
51
  end
43
52
 
44
- # Performs a search on this resource, given a query.
53
+ ##
54
+ # Updates a Customer using the PUT /customers/{customer_id} endpoint.
55
+ # https://developer.jortt.nl/#update-customer
45
56
  #
46
57
  # @example
47
- # customers.search('Zilverline')
58
+ # client.customers.update(
59
+ # "9afcd96e-caf8-40a1-96c9-1af16d0bc804",
60
+ # { address_extra_information: 'foobar' }
61
+ # )
62
+ #
63
+ def update(id, payload)
64
+ client.put("/customers/#{id}", payload)
65
+ end
66
+
67
+ ##
68
+ # Deletes a Customer using the DELETE /customers/{customer_id} endpoint.
69
+ # https://developer.jortt.nl/#delete-a-customer
48
70
  #
49
71
  # @example
50
- # customers.search('Zilverline') do |response|
51
- # # Roll your own response handler
52
- # end
72
+ # client.customers.delete("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
53
73
  #
54
- # @param [ Hash ] query A hash containing the fields to search for.
55
- # @param [ Proc ] block A custom response handler.
74
+ def delete(id)
75
+ client.delete("/customers/#{id}")
76
+ end
77
+
78
+ ##
79
+ # Send direct debit authorization to a Customer using POST /customers/{customer_id}/direct_debit_mandate.
80
+ # https://developer.jortt.nl/#send-direct-debit-authorization-to-a-customer
56
81
  #
57
- # @return [ Array<Hash> ] By default, a JSON parsed response body.
82
+ # @example
83
+ # client.customers.direct_debit_mandate("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
58
84
  #
59
- # @since 1.0.0
60
- def search(query)
61
- resource.get(params: {query: query}) do |response|
62
- JSON.parse(response.body)
63
- end
85
+ def direct_debit_mandate(id)
86
+ client.post("/customers/#{id}/direct_debit_mandate")
64
87
  end
65
88
 
66
- private
67
-
68
- attr_reader :resource
69
-
89
+ ##
90
+ # Get vat percentages for a Customer using the GET /customers/{customer_id}/vat-percentages endpoint.
91
+ # https://developer.jortt.nl/#get-vat-percentages-for-a-customer-by-id
92
+ #
93
+ # @example
94
+ # client.customers.vat_percentages("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
95
+ #
96
+ def vat_percentages(id)
97
+ client.get("/customers/#{id}/vat-percentages")
98
+ end
70
99
  end
71
100
  end
72
101
  end
@@ -0,0 +1,33 @@
1
+ module Jortt # :nodoc:
2
+ class Client # :nodoc:
3
+ class Error < StandardError # :nodoc:
4
+ attr_reader :response, :code, :key, :message, :details
5
+
6
+ def self.from_response(response)
7
+ Error.new(
8
+ response.parsed.dig('error', 'code'),
9
+ response.parsed.dig('error', 'key'),
10
+ response.parsed.dig('error', 'message'),
11
+ response.parsed.dig('error', 'details')
12
+ )
13
+ end
14
+
15
+ def initialize(code, key, message, details)
16
+ @code = code
17
+ @key = key
18
+ @message = message
19
+ @details = details
20
+
21
+ super(error_message)
22
+ end
23
+
24
+ def error_message
25
+ [message].tap do |m|
26
+ details.each do |detail|
27
+ m << "#{detail['param']} #{detail['message']}"
28
+ end
29
+ end.join("\n")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,56 +1,80 @@
1
- # encoding: UTF-8
2
- require 'rest-client'
3
-
4
1
  module Jortt # :nodoc:
5
2
  class Client # :nodoc:
6
-
7
3
  ##
8
4
  # Exposes the operations available for a collection of invoices.
9
5
  #
10
6
  # @see { Jortt::Client.invoices }
11
7
  class Invoices
8
+ attr_accessor :client
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
12
13
 
13
- def initialize(config)
14
- @resource = RestClient::Resource.new(
15
- "#{config.base_url}/invoices",
16
- user: config.app_name,
17
- password: config.api_key,
18
- )
14
+ ##
15
+ # Returns all invoices using the GET /invoices endpoint.
16
+ # https://developer.jortt.nl/#list-invoices
17
+ #
18
+ # @example
19
+ # client.invoices.index(query: 'Jane')
20
+ #
21
+ def index(query: nil, invoice_status: nil)
22
+ client.paginated('/invoices', query: query, invoice_status: invoice_status)
23
+ end
24
+
25
+ ##
26
+ # Returns a invoice using the GET /invoices/{invoice_id} endpoint.
27
+ # https://developer.jortt.nl/#get-invoice-by-id
28
+ #
29
+ # @example
30
+ # client.invoices.show("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
31
+ #
32
+ def show(id)
33
+ client.get("/invoices/#{id}")
19
34
  end
20
35
 
21
36
  ##
22
37
  # Creates an Invoice using the POST /invoices endpoint.
23
- # See https://app.jortt.nl/api-documentatie#factuur-aanmaken
38
+ # https://developer.jortt.nl/#create-and-optionally-send-an-invoice
24
39
  #
25
40
  # @example
26
- # Jortt::Client.invoices.create(
27
- # customer_id: 'customer_id', # optional
28
- # delivery_period: '31-12-2015', # optional
29
- # reference: 'reference', # optional
41
+ # client.invoices.create(
30
42
  # line_items: [{
31
- # vat: 21, # mandatory, percentage
32
- # amount: 499, # mandatory, ex vat
33
- # quantity: 4, # mandatory
34
- # description: 'Your Thinkas' # mandatory
43
+ # vat_percentage: "21.0",
44
+ # amount: 499,
45
+ # number_of_units: "4",
46
+ # description: 'Your product'
35
47
  # }]
36
48
  # )
37
49
  def create(payload)
38
- resource.post(JSON.generate('invoice' => payload)) do |response|
39
- JSON.parse(response.body)
40
- end
50
+ client.post('/invoices', payload)
41
51
  end
42
52
 
43
- def search(query)
44
- resource["search"].get(params: {query: query}) do |response|
45
- JSON.parse(response.body)
46
- end
53
+ ##
54
+ # Credits an Invoice using the POST /invoices/{invoice_id}/credit endpoint.
55
+ # https://developer.jortt.nl/#create-and-optionally-send-an-invoice
56
+ #
57
+ # @example
58
+ # client.invoices.credit(
59
+ # "9afcd96e-caf8-40a1-96c9-1af16d0bc804",
60
+ # {
61
+ # send_method: 'email'
62
+ # }
63
+ # )
64
+ def credit(id, payload)
65
+ client.post("/invoices/#{id}/credit", payload)
47
66
  end
48
67
 
49
- private
50
-
51
- attr_reader :resource
52
-
68
+ ##
69
+ # Returns an invoice PDF download link using the GET /invoices/{invoice_id}/download endpoint.
70
+ # https://developer.jortt.nl/#download-invoice-pdf
71
+ #
72
+ # @example
73
+ # client.invoices.download("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
74
+ #
75
+ def download(id)
76
+ client.get("/invoices/#{id}/download")
77
+ end
53
78
  end
54
-
55
79
  end
56
80
  end
@@ -0,0 +1,27 @@
1
+ module Jortt # :nodoc:
2
+ class Client # :nodoc:
3
+ ##
4
+ # Exposes the operations available for a collection of customers.
5
+ #
6
+ # @see { Jortt::Client.customers }
7
+ class LedgerAccounts
8
+ attr_accessor :client
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Returns the list of Ledger Accounts that can be used to categorize Line Items on an Invoice
16
+ # for in your Profit and Loss report using the GET /ledger_accounts/invoices endpoint.
17
+ # https://developer.jortt.nl/#list-invoice-ledger-accounts
18
+ #
19
+ # @example
20
+ # client.ledger_accounts.index
21
+ #
22
+ def index
23
+ client.get('/ledger_accounts/invoices')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,7 +1,6 @@
1
- # encoding: UTF-8
2
1
  module Jortt
3
2
  # Define the version of +Jortt::Client+
4
3
  class Client
5
- VERSION = '4.1.0'
4
+ VERSION = '6.1.0'
6
5
  end
7
6
  end