jortt 4.1.0 → 6.1.0
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.
- checksums.yaml +5 -5
- data/.github/workflows/rspec.yml +27 -0
- data/.ruby-version +1 -1
- data/README.md +75 -133
- data/Rakefile +0 -1
- data/jortt.gemspec +7 -7
- data/lib/jortt/client/customers.rb +71 -42
- data/lib/jortt/client/error.rb +33 -0
- data/lib/jortt/client/invoices.rb +55 -31
- data/lib/jortt/client/ledger_accounts.rb +27 -0
- data/lib/jortt/client/version.rb +1 -2
- data/lib/jortt/client.rb +65 -16
- data/lib/jortt.rb +0 -1
- data/spec/fixtures/vcr_cassettes/Jortt/_client/1_1_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_customers/1_1_1_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_invoices/1_1_2_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_ledger_accounts/1_1_3_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/faulty_payload/shows_a_nice_error.yml +413 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/valid_payload/creates_the_customer.yml +505 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_delete/deletes_the_customer.yml +505 -0
- 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
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/query/returns_the_queried_customers.yml +464 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/without_params/returns_customers.yml +415 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_show/returns_the_customer.yml +464 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_update/updates_the_customer.yml +603 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_vat_percentages/returns_the_vat_percentages.yml +330 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_create/creates_the_invoice.yml +170 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_credit/credits_the_invoice.yml +374 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_download/returns_the_invoice_download_link.yml +168 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/invoice_status/returns_those_invoices.yml +776 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/query/returns_the_queried_invoices.yml +315 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_show/returns_the_invoice.yml +421 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_LedgerAccounts/_index/returns_invoices.yml +118 -0
- data/spec/jortt/client/customers_spec.rb +109 -20
- data/spec/jortt/client/invoices_spec.rb +118 -20
- data/spec/jortt/client/ledger_accounts_spec.rb +19 -0
- data/spec/jortt/client_spec.rb +5 -27
- data/spec/jortt_spec.rb +2 -3
- data/spec/spec_helper.rb +18 -4
- metadata +85 -41
- data/.rubocop.yml +0 -26
- data/.travis.yml +0 -7
- data/lib/jortt/client/invoice.rb +0 -50
- data/spec/jortt/client/invoice_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cfce1585dc32518fb10a2d0bdb712186bb0a2746ba1367454e88601411516697
|
4
|
+
data.tar.gz: bc9d0972988bcaf7d74bd4c3bc2719bbe792cb873cbb294df5226a8bc7163eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
1
|
+
3.0.0
|
data/README.md
CHANGED
@@ -1,141 +1,85 @@
|
|
1
1
|
# Jortt REST API client
|
2
2
|
|
3
|
-
[
|
6
|
-
[](https://codeclimate.com/github/jorttbv/jortt-ruby)
|
3
|
+
[](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
|
9
4
|
[](https://codecov.io/github/jorttbv/jortt-ruby?branch=master)
|
12
|
-
[
|
7
|
+
[](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
|
-
|
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
|
-
|
26
|
+
All customers (`jortt.customers.index(page: 2)`) returns:
|
31
27
|
```ruby
|
32
28
|
[{
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
47
|
+
Get invoices by ID (`jortt.invoices.get('934d59dd-76f6-4716-9e0f-82a618e1be21')`) returns:
|
66
48
|
```ruby
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
"
|
71
|
-
|
72
|
-
|
73
|
-
"
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
"
|
78
|
-
|
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
|
-
"
|
127
|
-
"
|
128
|
-
"
|
129
|
-
|
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: "
|
147
|
-
|
148
|
-
|
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
|
-
{
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
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', '
|
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', '~>
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
34
|
spec.add_development_dependency 'codecov', '~> 0.1'
|
34
|
-
spec.add_development_dependency 'rake', '~>
|
35
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
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', '~>
|
38
|
-
spec.add_development_dependency '
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
#
|
38
|
+
# https://developer.jortt.nl/#create-customer
|
24
39
|
#
|
25
40
|
# @example
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
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
|
-
|
40
|
-
JSON.parse(response.body)
|
41
|
-
end
|
50
|
+
client.post('/customers', payload)
|
42
51
|
end
|
43
52
|
|
44
|
-
|
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.
|
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.
|
51
|
-
# # Roll your own response handler
|
52
|
-
# end
|
72
|
+
# client.customers.delete("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
|
53
73
|
#
|
54
|
-
|
55
|
-
|
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
|
-
# @
|
82
|
+
# @example
|
83
|
+
# client.customers.direct_debit_mandate("9afcd96e-caf8-40a1-96c9-1af16d0bc804")
|
58
84
|
#
|
59
|
-
|
60
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
#
|
38
|
+
# https://developer.jortt.nl/#create-and-optionally-send-an-invoice
|
24
39
|
#
|
25
40
|
# @example
|
26
|
-
#
|
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
|
-
#
|
32
|
-
# amount: 499,
|
33
|
-
#
|
34
|
-
# description: 'Your
|
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
|
-
|
39
|
-
JSON.parse(response.body)
|
40
|
-
end
|
50
|
+
client.post('/invoices', payload)
|
41
51
|
end
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|