economic-rest 0.6.2 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +98 -96
- data/README.md +89 -3
- data/economic-rest.gemspec +7 -8
- data/lib/economic/accounting_year_repo.rb +2 -0
- data/lib/economic/attribute.rb +9 -0
- data/lib/economic/base_repo.rb +7 -12
- data/lib/economic/configuration.rb +7 -0
- data/lib/economic/credentials.rb +26 -0
- data/lib/economic/customer_contact_repo.rb +2 -0
- data/lib/economic/customer_repo.rb +2 -0
- data/lib/economic/invoice.rb +0 -25
- data/lib/economic/invoices/booked_repo.rb +1 -1
- data/lib/economic/invoices/drafts_repo.rb +2 -0
- data/lib/economic/invoices/repo.rb +1 -1
- data/lib/economic/line.rb +0 -21
- data/lib/economic/model.rb +99 -0
- data/lib/economic/models/accounting_year.rb +9 -0
- data/lib/economic/models/attention.rb +8 -0
- data/lib/economic/models/customer.rb +41 -0
- data/lib/economic/models/customer_group.rb +11 -0
- data/lib/economic/models/customers/contact.rb +19 -0
- data/lib/economic/models/invoice.rb +32 -0
- data/lib/economic/models/invoices/booked.rb +11 -0
- data/lib/economic/models/invoices/draft.rb +9 -0
- data/lib/economic/models/layout.rb +9 -0
- data/lib/economic/models/line.rb +21 -0
- data/lib/economic/models/note.rb +9 -0
- data/lib/economic/models/payment_term.rb +10 -0
- data/lib/economic/models/product.rb +22 -0
- data/lib/economic/models/recipient.rb +17 -0
- data/lib/economic/models/reference.rb +11 -0
- data/lib/economic/models/sales_person.rb +7 -0
- data/lib/economic/models/unit.rb +8 -0
- data/lib/economic/models/vat_zone.rb +10 -0
- data/lib/economic/models/vendor_reference.rb +7 -0
- data/lib/economic/nested_base_repo.rb +0 -5
- data/lib/economic/orders/repo.rb +1 -1
- data/lib/economic/relation.rb +17 -0
- data/lib/economic/repo.rb +127 -0
- data/lib/economic/repos/accounting_year.rb +6 -0
- data/lib/economic/repos/customer.rb +6 -0
- data/lib/economic/repos/customers/contact.rb +21 -0
- data/lib/economic/repos/invoices/booked.rb +19 -0
- data/lib/economic/repos/invoices/draft.rb +8 -0
- data/lib/economic/repos/invoices/drafts/line.rb +26 -0
- data/lib/economic/response/pagination.rb +16 -0
- data/lib/economic/response.rb +51 -0
- data/lib/economic/rest/version.rb +1 -1
- data/lib/economic/rest.rb +41 -6
- metadata +58 -40
- data/lib/economic/concerns/soap_methods.rb +0 -217
- data/lib/economic/soap_api.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e67b392301ec491022017a99c741e61e22b9e66f87c77d4fe251787b15171eb
|
4
|
+
data.tar.gz: 751e03e4de3bc1d6974234009fdd079823b0f062abe1dac71e1108720e307833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3906cc750544bdad9265b005c398e6daa3df32c358fa33038b45ee9c65ce5d7c0917f8c420c9ff4a81e7540174ab1bd18cdd4f479cfffd5327449e220f8ca026
|
7
|
+
data.tar.gz: ff01dd74f57a7ade5a70b28525d4a485bad4fc7c13dfef125ca1a6a19b4fcb76db892a0f225fe7261c02fb4bead654d70ee86ebff3872078992775c6679024b8
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
git_source(:
|
3
|
+
git_source(:github) { |_repo_name| "https://github.com/traels-it/economic-rest" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in economic-rest.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,148 +1,150 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
economic-rest (0.6.
|
5
|
-
activesupport
|
6
|
-
rest-client
|
7
|
-
savon
|
4
|
+
economic-rest (0.6.4)
|
5
|
+
activesupport (~> 7.0)
|
6
|
+
rest-client (~> 2.1)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activesupport (
|
13
|
-
|
11
|
+
activesupport (7.2.1.1)
|
12
|
+
base64
|
13
|
+
bigdecimal
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
14
17
|
i18n (>= 1.6, < 2)
|
18
|
+
logger (>= 1.4.2)
|
15
19
|
minitest (>= 5.1)
|
16
|
-
|
17
|
-
|
18
|
-
addressable (2.
|
19
|
-
public_suffix (>= 2.0.2, <
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
concurrent-ruby (1.1.9)
|
20
|
+
securerandom (>= 0.3)
|
21
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
22
|
+
addressable (2.8.7)
|
23
|
+
public_suffix (>= 2.0.2, < 7.0)
|
24
|
+
ast (2.4.2)
|
25
|
+
awesome_print (1.9.2)
|
26
|
+
base64 (0.2.0)
|
27
|
+
bigdecimal (3.1.8)
|
28
|
+
concurrent-ruby (1.3.4)
|
29
|
+
connection_pool (2.4.1)
|
27
30
|
coveralls (0.8.23)
|
28
31
|
json (>= 1.8, < 3)
|
29
32
|
simplecov (~> 0.16.1)
|
30
33
|
term-ansicolor (~> 1.3)
|
31
34
|
thor (>= 0.19.4, < 2.0)
|
32
35
|
tins (~> 1.6)
|
33
|
-
crack (0.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
dotenv (
|
39
|
-
|
40
|
-
|
41
|
-
hashdiff (0.3.8)
|
36
|
+
crack (1.0.0)
|
37
|
+
bigdecimal
|
38
|
+
rexml
|
39
|
+
docile (1.4.1)
|
40
|
+
domain_name (0.6.20240107)
|
41
|
+
dotenv (3.1.4)
|
42
|
+
drb (2.2.1)
|
43
|
+
hashdiff (1.1.1)
|
42
44
|
http-accept (1.7.0)
|
43
|
-
http-cookie (1.0.
|
45
|
+
http-cookie (1.0.7)
|
44
46
|
domain_name (~> 0.5)
|
45
|
-
|
46
|
-
rack
|
47
|
-
socksify
|
48
|
-
i18n (1.8.10)
|
47
|
+
i18n (1.14.6)
|
49
48
|
concurrent-ruby (~> 1.0)
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
json (2.7.2)
|
50
|
+
language_server-protocol (3.17.0.3)
|
51
|
+
lint_roller (1.1.0)
|
52
|
+
logger (1.6.1)
|
53
|
+
m (1.6.2)
|
53
54
|
method_source (>= 0.6.7)
|
54
55
|
rake (>= 0.9.2.2)
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
method_source (1.1.0)
|
57
|
+
mime-types (3.6.0)
|
58
|
+
logger
|
58
59
|
mime-types-data (~> 3.2015)
|
59
|
-
mime-types-data (3.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
metaclass (~> 0.0.1)
|
60
|
+
mime-types-data (3.2024.1001)
|
61
|
+
minitest (5.25.1)
|
62
|
+
mocha (2.4.5)
|
63
|
+
ruby2_keywords (>= 0.0.5)
|
64
64
|
netrc (0.11.0)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rack (2.2.3)
|
75
|
-
rainbow (3.0.0)
|
76
|
-
rake (10.5.0)
|
65
|
+
parallel (1.26.3)
|
66
|
+
parser (3.3.5.0)
|
67
|
+
ast (~> 2.4.1)
|
68
|
+
racc
|
69
|
+
public_suffix (6.0.1)
|
70
|
+
racc (1.8.1)
|
71
|
+
rainbow (3.1.1)
|
72
|
+
rake (13.2.1)
|
73
|
+
regexp_parser (2.9.2)
|
77
74
|
rest-client (2.1.0)
|
78
75
|
http-accept (>= 1.7.0, < 2.0)
|
79
76
|
http-cookie (>= 1.0.2, < 2.0)
|
80
77
|
mime-types (>= 1.16, < 4.0)
|
81
78
|
netrc (~> 0.8)
|
82
|
-
|
83
|
-
|
79
|
+
rexml (3.3.8)
|
80
|
+
rubocop (1.66.1)
|
81
|
+
json (~> 2.3)
|
82
|
+
language_server-protocol (>= 3.17.0)
|
84
83
|
parallel (~> 1.10)
|
85
|
-
parser (>= 2
|
84
|
+
parser (>= 3.3.0.2)
|
86
85
|
rainbow (>= 2.2.2, < 4.0)
|
86
|
+
regexp_parser (>= 2.4, < 3.0)
|
87
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
87
88
|
ruby-progressbar (~> 1.7)
|
88
|
-
unicode-display_width (>=
|
89
|
-
rubocop-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
httpi (~> 2.3)
|
98
|
-
nokogiri (>= 1.8.1)
|
99
|
-
nori (~> 2.4)
|
100
|
-
wasabi (~> 3.4)
|
89
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
90
|
+
rubocop-ast (1.32.3)
|
91
|
+
parser (>= 3.3.1.0)
|
92
|
+
rubocop-performance (1.22.1)
|
93
|
+
rubocop (>= 1.48.1, < 2.0)
|
94
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
95
|
+
ruby-progressbar (1.13.0)
|
96
|
+
ruby2_keywords (0.0.5)
|
97
|
+
securerandom (0.3.1)
|
101
98
|
simplecov (0.16.1)
|
102
99
|
docile (~> 1.1)
|
103
100
|
json (>= 1.8, < 3)
|
104
101
|
simplecov-html (~> 0.10.0)
|
105
102
|
simplecov-html (0.10.2)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
rubocop
|
110
|
-
|
103
|
+
standard (1.41.0)
|
104
|
+
language_server-protocol (~> 3.17.0.2)
|
105
|
+
lint_roller (~> 1.0)
|
106
|
+
rubocop (~> 1.66.0)
|
107
|
+
standard-custom (~> 1.0.0)
|
108
|
+
standard-performance (~> 1.5)
|
109
|
+
standard-custom (1.0.2)
|
110
|
+
lint_roller (~> 1.0)
|
111
|
+
rubocop (~> 1.50)
|
112
|
+
standard-performance (1.5.0)
|
113
|
+
lint_roller (~> 1.1)
|
114
|
+
rubocop-performance (~> 1.22.0)
|
115
|
+
sync (0.5.0)
|
116
|
+
term-ansicolor (1.11.2)
|
111
117
|
tins (~> 1.0)
|
112
|
-
thor (
|
113
|
-
tins (1.
|
114
|
-
|
118
|
+
thor (1.3.2)
|
119
|
+
tins (1.36.1)
|
120
|
+
bigdecimal
|
121
|
+
sync
|
122
|
+
tzinfo (2.0.6)
|
115
123
|
concurrent-ruby (~> 1.0)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
unicode-display_width (1.6.0)
|
120
|
-
wasabi (3.6.1)
|
121
|
-
addressable
|
122
|
-
httpi (~> 2.0)
|
123
|
-
nokogiri (>= 1.4.2)
|
124
|
-
webmock (3.5.1)
|
125
|
-
addressable (>= 2.3.6)
|
124
|
+
unicode-display_width (2.6.0)
|
125
|
+
webmock (3.24.0)
|
126
|
+
addressable (>= 2.8.0)
|
126
127
|
crack (>= 0.3.2)
|
127
|
-
hashdiff
|
128
|
-
zeitwerk (2.4.2)
|
128
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
129
129
|
|
130
130
|
PLATFORMS
|
131
|
-
|
131
|
+
arm64-darwin-21
|
132
|
+
arm64-darwin-22
|
133
|
+
arm64-darwin-23
|
132
134
|
|
133
135
|
DEPENDENCIES
|
134
136
|
awesome_print
|
135
|
-
bundler (~>
|
137
|
+
bundler (~> 2.4)
|
136
138
|
coveralls
|
137
139
|
dotenv
|
138
140
|
economic-rest!
|
139
141
|
m
|
140
|
-
minitest (~> 5.
|
142
|
+
minitest (~> 5.25)
|
141
143
|
mocha
|
142
|
-
rake (~>
|
144
|
+
rake (~> 13.2)
|
143
145
|
simplecov
|
144
146
|
standard
|
145
|
-
webmock (~> 3.
|
147
|
+
webmock (~> 3.24)
|
146
148
|
|
147
149
|
BUNDLED WITH
|
148
|
-
2.
|
150
|
+
2.5.21
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/bitbucket/traels/economic-rest/badge.svg?branch=master)](https://coveralls.io/bitbucket/traels/economic-rest?branch=master)
|
6
6
|
|
7
7
|
Ruby wrapper for the e-conomic REST API, that aims at making working with the API bearable.
|
8
|
-
E-conomic is a web-based accounting system. For their marketing speak, see http://www.e-conomic.co.uk/about/. More details about their API at http://www.e-conomic.co.uk/integration/integration-partner
|
8
|
+
E-conomic is a web-based accounting system. For their marketing speak, see http://www.e-conomic.co.uk/about/. More details about their API at http://www.e-conomic.co.uk/integration/integration-partner/.
|
9
9
|
The documentation can be found at https://restdocs.e-conomic.com
|
10
10
|
|
11
11
|
|
@@ -27,6 +27,90 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
+
The gem started out with an architecture, that was a bit too hard to work with. Going forward this will change significantly. As of now the changes are not breaking, but the old way will be deprecated as the new architecture is implemented. No further development will be made for the old architecture, instead we aim to incrementally become feature complete using the new architecture.
|
31
|
+
Once all the old models and repos have been converted to the new architecture, a date will be set for when they will be removed.
|
32
|
+
|
33
|
+
### New architecure
|
34
|
+
#### Repos
|
35
|
+
The gem maps the API endpoint using classes called `Repos`.
|
36
|
+
All the end points dealing with one resource will be accessible through one repo, for instance all the actions under `/customers` will be accessible through `Economic::Repos::Customer`:
|
37
|
+
|
38
|
+
| HTTP method | Endpoint | Repo method |
|
39
|
+
| -------- | -------- | --------- |
|
40
|
+
| GET | `/customers` | `repo.all` |
|
41
|
+
| POST | `/customers` | `repo.create(customer_instance)` |
|
42
|
+
| GET | `/customers/:customerNumber` | `repo.find(id_or_object_responding_to_id)` |
|
43
|
+
| PUT | `/customers/:customerNumber` | `repo.update(customer_instance_with_updated_data)` |
|
44
|
+
| PATCH | `/customers/:customerNumber` | *Special case - not yet implemented* |
|
45
|
+
| DELETE | `/customers/:customerNumber` | `repo.destroy(id_or_object_responding_to_id)` |
|
46
|
+
|
47
|
+
##### `repo.all`
|
48
|
+
Returns *all* the records for the repo. If there are more than 1.000, it handles the pagination automatically and returns the records in a single array.
|
49
|
+
`all` can take a filter text if you are not interested in every single record. The allowed filtering operators are:
|
50
|
+
|
51
|
+
| Operator | Syntax |
|
52
|
+
| -------- | --------- |
|
53
|
+
| Equals | `$eq:` |
|
54
|
+
| Not equals | `$ne:` |
|
55
|
+
| Greater than | `$gt:` |
|
56
|
+
| Greater than or equal | `$gte:` |
|
57
|
+
| Less than | `$lt:` |
|
58
|
+
| Less than or equal | `$lte:` |
|
59
|
+
| Substring match | `$like:` |
|
60
|
+
| And also | `$and:` |
|
61
|
+
| Or else | `$or:` |
|
62
|
+
| In | `$in:` |
|
63
|
+
| Not In | `$nin:` |
|
64
|
+
|
65
|
+
For more details see https://restdocs.e-conomic.com/#specifying-operator-affinity
|
66
|
+
|
67
|
+
For now the attribute names must be in lower camelcase when filtering:
|
68
|
+
```
|
69
|
+
Economic::Repos::Customer.all(filter: "corporateIdentificationNumber$eq:22001884")
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Credentials
|
73
|
+
|
74
|
+
Repos require credentials to know which e-conomic account to connect to. These can be suuplied in two ways:
|
75
|
+
1. Setting a global set of credentials through `Economic::Configuration` will apply to any repo you initialize:
|
76
|
+
```
|
77
|
+
Economic::Configuration.app_secret_token = "Demo"
|
78
|
+
Economic::Configuration.agreement_grant_token = "Demo"
|
79
|
+
|
80
|
+
repo = Economic::Repo::Customer.new
|
81
|
+
repo.credentials => #<data Economic::Credentials app_secret_token="Demo", agreement_grant_token="Demo">
|
82
|
+
```
|
83
|
+
2. Supplying a set of credentials when initializing a repo, sets them for that instance only:
|
84
|
+
```
|
85
|
+
credentials = Economic::Credentials.new(app_secret_token: "secret", agreement_grant_token: "grant")
|
86
|
+
|
87
|
+
repo = Economic::Repo::Customer.new(credentials: credentials)
|
88
|
+
repo.credentials => #<data Economic::Credentials app_secret_token="secret", agreement_grant_token="grant">
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Nested repos
|
92
|
+
Some endpoints are nested under other endpoints, e.g. `/customers/:customerNumber/contacts`. This requires the id of the customer, whose contacts you want to manipulate. Therefore the repo must be initialized with an id or model:
|
93
|
+
```
|
94
|
+
customer = Economic::Models::Customer.new(id: 12)
|
95
|
+
repo = Economic::Repos::Customers::Contact.new(customer).new
|
96
|
+
repo.all => All instances of Economic::Models::Customers::Contact belonging to the customer
|
97
|
+
```
|
98
|
+
|
99
|
+
#### Error handling
|
100
|
+
An error is raised when the response from e-conomic has one of the following error codes:
|
101
|
+
|
102
|
+
| Error Code | Error class |
|
103
|
+
| -------- | --------- |
|
104
|
+
| 400 | Economic::BadRequestError |
|
105
|
+
| 401 | Economic::UnauthorizedError |
|
106
|
+
| 403 | Economic::ForbiddedError |
|
107
|
+
| 404 | Economic::NotFoundError |
|
108
|
+
| 500 | Economic::InternalError |
|
109
|
+
|
110
|
+
The error message is the response body from e-conomic.
|
111
|
+
|
112
|
+
### Old architecture
|
113
|
+
|
30
114
|
```ruby
|
31
115
|
require 'economic/rest'
|
32
116
|
|
@@ -71,7 +155,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
71
155
|
|
72
156
|
## Contributing
|
73
157
|
|
74
|
-
Bug reports and pull requests are welcome on GitHub at https://
|
158
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/traels-it/economic-rest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
75
159
|
|
76
160
|
## License
|
77
161
|
|
@@ -79,4 +163,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
79
163
|
|
80
164
|
## Code of Conduct
|
81
165
|
|
82
|
-
Everyone interacting in the Economic::Rest project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
166
|
+
Everyone interacting in the Economic::Rest project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/traels-it/economic-rest/blob/main/CODE_OF_CONDUCT.md).
|
167
|
+
|
168
|
+
|
data/economic-rest.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Ruby wrapper for the e-conomic REST API, that aims at making working with the API bearable.
|
12
12
|
E-conomic is a web-based accounting system. For their marketing speak, see http://www.e-conomic.co.uk/about/. More details about their API at http://www.e-conomic.co.uk/integration/integration-partner/.
|
13
13
|
The documentation can be found at https://restdocs.e-conomic.com'
|
14
|
-
spec.homepage = "https://
|
14
|
+
spec.homepage = "https://github.com/traels-it/economic-rest"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
@@ -23,19 +23,18 @@ The documentation can be found at https://restdocs.e-conomic.com'
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.4"
|
27
27
|
spec.add_development_dependency "m"
|
28
|
-
spec.add_development_dependency "minitest", "~> 5.
|
29
|
-
spec.add_development_dependency "rake", "~>
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.25"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.2"
|
30
30
|
spec.add_development_dependency "simplecov"
|
31
|
-
spec.add_development_dependency "webmock", "~> 3.
|
31
|
+
spec.add_development_dependency "webmock", "~> 3.24"
|
32
32
|
spec.add_development_dependency "dotenv"
|
33
33
|
spec.add_development_dependency "standard"
|
34
34
|
spec.add_development_dependency "awesome_print"
|
35
35
|
spec.add_development_dependency "mocha"
|
36
36
|
spec.add_development_dependency "coveralls"
|
37
37
|
|
38
|
-
spec.add_dependency "
|
39
|
-
spec.add_dependency "
|
40
|
-
spec.add_dependency "activesupport"
|
38
|
+
spec.add_dependency "rest-client", "~> 2.1"
|
39
|
+
spec.add_dependency "activesupport", "~> 7.0"
|
41
40
|
end
|
data/lib/economic/base_repo.rb
CHANGED
@@ -22,11 +22,6 @@ module Economic
|
|
22
22
|
modelize_response(response)
|
23
23
|
end
|
24
24
|
|
25
|
-
def send(model, url: endpoint_url)
|
26
|
-
warn "use #{self}.save(). #{self}.send() is deprecated"
|
27
|
-
save(model, url: endpoint_url)
|
28
|
-
end
|
29
|
-
|
30
25
|
def all(filter_text: "", url: endpoint_url)
|
31
26
|
pagination = {}
|
32
27
|
pageindex = 0
|
@@ -72,14 +67,14 @@ module Economic
|
|
72
67
|
response = send_request(method: :delete, url: url)
|
73
68
|
|
74
69
|
success_codes = [200, 204]
|
75
|
-
|
70
|
+
true if success_codes.include?(response.code)
|
76
71
|
end
|
77
72
|
|
78
|
-
def send_request(method:, url:, payload: "", &
|
73
|
+
def send_request(method:, url:, payload: "", &)
|
79
74
|
if payload.strip.empty?
|
80
|
-
RestClient::Request.execute(method: method, url: url, headers: headers, &
|
75
|
+
RestClient::Request.execute(method: method, url: url, headers: headers, &)
|
81
76
|
else
|
82
|
-
RestClient::Request.execute(method: method, url: url, payload: payload, headers: headers, &
|
77
|
+
RestClient::Request.execute(method: method, url: url, payload: payload, headers: headers, &)
|
83
78
|
end
|
84
79
|
rescue => e
|
85
80
|
warn "#{e} #{e.response}" if e.respond_to?(:response)
|
@@ -95,7 +90,7 @@ module Economic
|
|
95
90
|
.gsub(":", "_4_")
|
96
91
|
.gsub("&", "_5_")
|
97
92
|
.gsub("/", "_6_")
|
98
|
-
.gsub(
|
93
|
+
.gsub("\\", "_7_")
|
99
94
|
.gsub(" ", "_9_")
|
100
95
|
.gsub("?", "_10_")
|
101
96
|
.gsub(".", "_11_")
|
@@ -131,7 +126,7 @@ module Economic
|
|
131
126
|
end
|
132
127
|
|
133
128
|
def headers
|
134
|
-
{
|
129
|
+
{"X-AppSecretToken": Session.app_secret_token, "X-AgreementGrantToken": Session.agreement_grant_token, "Content-Type": "application/json"}
|
135
130
|
end
|
136
131
|
|
137
132
|
def fetch(url: endpoint_url, pageindex: 0, filter_text: "")
|
@@ -143,7 +138,7 @@ module Economic
|
|
143
138
|
end
|
144
139
|
|
145
140
|
def kebab(string)
|
146
|
-
string.gsub(
|
141
|
+
string.gsub("::", "/")
|
147
142
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
148
143
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
149
144
|
.tr("_", "-")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Economic
|
2
|
+
class Credentials < Data.define(:app_secret_token, :agreement_grant_token)
|
3
|
+
class << self
|
4
|
+
def fetch!
|
5
|
+
credentials = new(
|
6
|
+
app_secret_token: Economic::Configuration.app_secret_token,
|
7
|
+
agreement_grant_token: Economic::Configuration.agreement_grant_token
|
8
|
+
)
|
9
|
+
|
10
|
+
raise MissingCredentialsError if credentials.missing?
|
11
|
+
|
12
|
+
credentials
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def missing?
|
17
|
+
app_secret_token.nil? || agreement_grant_token.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MissingCredentialsError < StandardError
|
22
|
+
def message
|
23
|
+
"Credentials missing! Initialize the resource with a set of credentials or set them on Economic::Configuration"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/economic/invoice.rb
CHANGED
@@ -28,31 +28,6 @@ module Economic
|
|
28
28
|
relation :references, fields: [:other]
|
29
29
|
relation :lines, fields: [:lineNumber, :description, :sortKey, :quantity, :unitNetPrice, :discountPercentage, :unitCostPrice, :marginInBaseCurrency, :marginPercentage, :totalNetAmount], multiple: true
|
30
30
|
|
31
|
-
def self.build_from_soap_api(data)
|
32
|
-
# TODO: Add all the options
|
33
|
-
hash = {
|
34
|
-
"currency" => data[:currency_handle][:code],
|
35
|
-
"date" => data[:date].to_date,
|
36
|
-
"dueDate" => data[:due_date].to_date,
|
37
|
-
"exchangeRate" => data[:exchange_rate],
|
38
|
-
"grossAmount" => data[:gross_amount],
|
39
|
-
# where is grossAmountInBaseCurrency?
|
40
|
-
"lines" => repo.find_lines(data[:handle][:id]),
|
41
|
-
"marginInBaseCurrency" => data[:margin],
|
42
|
-
"marginPercentage" => data[:margin_as_percent],
|
43
|
-
"netAmount" => data[:net_amount],
|
44
|
-
"roundingAmount" => data[:rounding_amount],
|
45
|
-
"vatAmount" => data[:vat_amount],
|
46
|
-
"draftInvoiceNumber" => data[:handle][:id], # TODO: What about id?
|
47
|
-
"customer" => {"customerNumber" => data[:debtor_handle][:id].to_i},
|
48
|
-
"layout" => {"layoutNumber" => data[:layout_handle][:id].to_i},
|
49
|
-
"paymentTerms" => {"paymentTermsNumber" => data[:term_of_payment_handle][:id].to_i},
|
50
|
-
"references" => {"other" => data[:other_reference]},
|
51
|
-
}
|
52
|
-
|
53
|
-
new(hash)
|
54
|
-
end
|
55
|
-
|
56
31
|
def self.repo
|
57
32
|
Economic::Invoices::DraftsRepo
|
58
33
|
end
|
@@ -2,7 +2,7 @@ module Economic
|
|
2
2
|
module Invoices
|
3
3
|
class BookedRepo < Economic::Invoices::Repo
|
4
4
|
class << self
|
5
|
-
def
|
5
|
+
def save(invoice, book_with_number: nil)
|
6
6
|
response = send_request(method: :post, url: endpoint_url, payload: payload(invoice, book_with_number: book_with_number))
|
7
7
|
|
8
8
|
entry_hash = JSON.parse(response.body)
|
data/lib/economic/line.rb
CHANGED
@@ -15,26 +15,5 @@ module Economic
|
|
15
15
|
relation :unit, fields: []
|
16
16
|
relation :delivery, fields: []
|
17
17
|
relation :departmentalDistribution, fields: []
|
18
|
-
|
19
|
-
def self.build_from_soap_api(data)
|
20
|
-
# This is not instantiated with the hash, as lines are never pulled out by themselves, but always as part of
|
21
|
-
# a invoice or order
|
22
|
-
{
|
23
|
-
"lineNumber" => data[:number].to_i,
|
24
|
-
"description" => data[:description],
|
25
|
-
"quantity" => data[:quantity].to_f,
|
26
|
-
"unitNetPrice" => data[:unit_net_price].to_f,
|
27
|
-
"discountPercentage" => data[:discount_as_percent].to_f,
|
28
|
-
"unitCostPrice" => data[:unit_cost_price].to_f,
|
29
|
-
"totalNetAmount" => data[:total_net_amount].to_f,
|
30
|
-
"marginPercentage" => data[:margin_as_percent].to_f,
|
31
|
-
"marginInBaseCurrency" => data[:total_margin].to_f,
|
32
|
-
"product" => {"productNumber" => data[:product_handle][:number]},
|
33
|
-
# Unmapped values in soap
|
34
|
-
# delivery_date
|
35
|
-
# :accrual_start_date => nil,
|
36
|
-
# :accrual_end_date => nil
|
37
|
-
}
|
38
|
-
end
|
39
18
|
end
|
40
19
|
end
|