easy_compliance 1.0.1 → 1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +4 -3
- data/README.md +19 -2
- data/lib/easy_compliance/client.rb +24 -6
- data/lib/easy_compliance/result.rb +1 -0
- data/lib/easy_compliance/version.rb +1 -1
- data/lib/easy_compliance.rb +1 -1
- data/spec/easy_compliance/client_spec.rb +87 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a18dc5645db8718da9f22831fcf6f458d74763536dfe8edaccf3f4439ae91b95
|
4
|
+
data.tar.gz: 9db9644054a7c647e2e0801bb958b6208943088d9012bf6e3f9be8600da7ef46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795a143c9b365c3f38d1794fb41f200ce0c6b9f5e5722061d31a6b27b7e9b577fb2bb747e9c8c03f26b21f68cde42ebc94ba4a3151c7c443734701c1c0a56286
|
7
|
+
data.tar.gz: c687ec1583a5ba413e09072adb60f206326921ce6ade5bb32a3e361aa7e5ba4fcb24bb96f786a57544b7419923ffb332526ac45dbe02e17555fc0c482fcf3cf0
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.2] - 2021-11-01
|
10
|
+
### Fixed
|
11
|
+
- Fixed leaking `OpenSSL::OpenSSLErrors`, they are now wrapped
|
12
|
+
|
9
13
|
## [1.0.1] - 2021-10-25
|
10
14
|
### Fixed
|
11
15
|
- Removed `bin/console` and `bin/setup` from gem executables [#1]
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easy_compliance (1.0.
|
4
|
+
easy_compliance (1.0.2)
|
5
5
|
excon
|
6
6
|
|
7
7
|
GEM
|
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
byebug (11.1.3)
|
11
11
|
diff-lcs (1.4.4)
|
12
|
-
excon (0.
|
12
|
+
excon (0.93.1)
|
13
13
|
rake (13.0.3)
|
14
14
|
rspec (3.10.0)
|
15
15
|
rspec-core (~> 3.10.0)
|
@@ -27,6 +27,7 @@ GEM
|
|
27
27
|
|
28
28
|
PLATFORMS
|
29
29
|
x86_64-darwin-19
|
30
|
+
x86_64-darwin-20
|
30
31
|
|
31
32
|
DEPENDENCIES
|
32
33
|
bundler
|
@@ -36,4 +37,4 @@ DEPENDENCIES
|
|
36
37
|
rspec
|
37
38
|
|
38
39
|
BUNDLED WITH
|
39
|
-
2.2.
|
40
|
+
2.2.25
|
data/README.md
CHANGED
@@ -9,13 +9,20 @@ Ruby toolkit for https://www.easycompliance.de
|
|
9
9
|
Use `EasyCompliance::Ref` to build refs for the records.
|
10
10
|
|
11
11
|
### Keeping data in sync
|
12
|
+
When a request fails EasyCompliance will consider the request idempotent and by default retries 3 times with a delay of 5 seconds in between.
|
13
|
+
You can adjust this to fit your needs.
|
12
14
|
|
13
15
|
```ruby
|
14
16
|
# config/initializers/easy_compliance.rb
|
17
|
+
# required
|
15
18
|
EasyCompliance.api_key = 'my_key'
|
16
19
|
EasyCompliance.api_url = 'https://example.com'
|
17
20
|
EasyCompliance.app_name = 'my_app'
|
18
21
|
|
22
|
+
# optional
|
23
|
+
EasyCompliance.retry_limit = 3 # Max number of retries (this is the default)
|
24
|
+
EasyCompliance.retry_interval = 5 # Delay between retries in seconds (this is the default)
|
25
|
+
|
19
26
|
# app/models/my_record.rb
|
20
27
|
class MyRecord < ActiveRecord::Base
|
21
28
|
after_save do
|
@@ -26,8 +33,18 @@ end
|
|
26
33
|
# app/jobs/compliance_job.rb
|
27
34
|
class ComplianceJob
|
28
35
|
def perform(record, value)
|
29
|
-
production_env?
|
30
|
-
|
36
|
+
return unless production_env?
|
37
|
+
|
38
|
+
check = EasyCompliance::Client.submit(record: record, value: value)
|
39
|
+
check.hit? # true/false
|
40
|
+
|
41
|
+
check.status # http response status e.g. 200
|
42
|
+
check.body # http response body
|
31
43
|
end
|
32
44
|
end
|
33
45
|
```
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
`EasyCompliance` is licensed under the [Apache 2.0 license](LICENSE.txt) and
|
50
|
+
Copyright 2021,2022 [betterplace / gut.org gAG](https://gut.org).
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'excon'
|
2
|
+
require 'openssl'
|
2
3
|
|
3
4
|
module EasyCompliance
|
4
5
|
# client for https://easycompliance.de/schnittstellen/api/
|
@@ -28,20 +29,37 @@ module EasyCompliance
|
|
28
29
|
end
|
29
30
|
|
30
31
|
HEADERS = {
|
31
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
32
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
32
33
|
}
|
33
34
|
|
34
35
|
# @return [ EasyCompliance::Result ]
|
35
36
|
def post(**body)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
body[:api_key] = EasyCompliance.api_key or raise Error, 'must set api_key'
|
38
|
+
res = Excon.post(
|
39
|
+
api_url,
|
40
|
+
body: URI.encode_www_form(body),
|
41
|
+
headers: HEADERS,
|
42
|
+
idempotent: true,
|
43
|
+
retry_limit: retry_limit,
|
44
|
+
retry_interval: retry_interval
|
45
|
+
)
|
40
46
|
res.status < 300 or raise Error, "#{res.status}: #{res.body}"
|
41
47
|
|
42
48
|
EasyCompliance::Result.new(status: res.status, body: res.body)
|
43
|
-
rescue Excon::Error => e
|
49
|
+
rescue Excon::Error, OpenSSL::OpenSSLError => e
|
44
50
|
raise Error, "Network error: #{e.class.name} - #{e.message}"
|
45
51
|
end
|
52
|
+
|
53
|
+
def retry_limit
|
54
|
+
EasyCompliance.retry_limit || 3
|
55
|
+
end
|
56
|
+
|
57
|
+
def retry_interval
|
58
|
+
EasyCompliance.retry_interval || 5
|
59
|
+
end
|
60
|
+
|
61
|
+
def api_url
|
62
|
+
EasyCompliance.api_url || raise(Error, 'must set api_url')
|
63
|
+
end
|
46
64
|
end
|
47
65
|
end
|
data/lib/easy_compliance.rb
CHANGED
@@ -5,12 +5,21 @@ describe EasyCompliance::Client do
|
|
5
5
|
before do
|
6
6
|
EasyCompliance.api_key = 'key'
|
7
7
|
EasyCompliance.api_url = 'url'
|
8
|
+
EasyCompliance.retry_limit = nil
|
9
|
+
EasyCompliance.retry_interval = nil
|
8
10
|
end
|
9
11
|
|
10
12
|
describe '#post' do
|
11
13
|
it 'posts to the API URL and returns an EasyCompliance::Result' do
|
12
14
|
expect(Excon).to receive(:post)
|
13
|
-
.with(
|
15
|
+
.with(
|
16
|
+
'url',
|
17
|
+
body: 'method=2&api_key=key',
|
18
|
+
headers: anything,
|
19
|
+
idempotent: true,
|
20
|
+
retry_limit: 3,
|
21
|
+
retry_interval: 5
|
22
|
+
)
|
14
23
|
.and_return(double(body: '{}', status: 200))
|
15
24
|
result = client.post(method: 2)
|
16
25
|
expect(result).to be_an EasyCompliance::Result
|
@@ -19,18 +28,46 @@ describe EasyCompliance::Client do
|
|
19
28
|
|
20
29
|
it 'raises if the API returned a bad status code' do
|
21
30
|
expect(Excon).to receive(:post)
|
22
|
-
.with(
|
31
|
+
.with(
|
32
|
+
'url',
|
33
|
+
body: 'method=2&api_key=key',
|
34
|
+
headers: anything,
|
35
|
+
idempotent: true,
|
36
|
+
retry_limit: 3,
|
37
|
+
retry_interval: 5
|
38
|
+
)
|
23
39
|
.and_return(double(body: '{}', status: 500))
|
24
40
|
expect { client.post(method: 2) }.to raise_error(client::Error, /500/)
|
25
41
|
end
|
26
42
|
|
27
43
|
it 'raises if the connection failed' do
|
28
44
|
expect(Excon).to receive(:post)
|
29
|
-
.with(
|
45
|
+
.with(
|
46
|
+
'url',
|
47
|
+
body: 'method=2&api_key=key',
|
48
|
+
headers: anything,
|
49
|
+
idempotent: true,
|
50
|
+
retry_limit: 3,
|
51
|
+
retry_interval: 5
|
52
|
+
)
|
30
53
|
.and_raise(Excon::Errors::SocketError.new)
|
31
54
|
expect { client.post(method: 2) }.to raise_error(client::Error, /Socket/)
|
32
55
|
end
|
33
56
|
|
57
|
+
it 'raises if there is any OpenSSL::OpenSSLError' do
|
58
|
+
expect(Excon).to receive(:post)
|
59
|
+
.with(
|
60
|
+
'url',
|
61
|
+
body: 'method=2&api_key=key',
|
62
|
+
headers: anything,
|
63
|
+
idempotent: true,
|
64
|
+
retry_limit: 3,
|
65
|
+
retry_interval: 5
|
66
|
+
)
|
67
|
+
.and_raise(OpenSSL::SSL::SSLErrorWaitReadable.new)
|
68
|
+
expect { client.post(method: 2) }.to raise_error(client::Error, /SSLError/)
|
69
|
+
end
|
70
|
+
|
34
71
|
it 'raises if api_key is not set' do
|
35
72
|
EasyCompliance.api_key = nil
|
36
73
|
expect { client.post(method: 2) }.to raise_error(client::Error, /api_key/)
|
@@ -40,5 +77,52 @@ describe EasyCompliance::Client do
|
|
40
77
|
EasyCompliance.api_url = nil
|
41
78
|
expect { client.post(method: 2) }.to raise_error(client::Error, /api_url/)
|
42
79
|
end
|
80
|
+
|
81
|
+
it 'uses a default value of 3 for retry_limit unless it is set' do
|
82
|
+
expect(Excon).to receive(:post).with(
|
83
|
+
'url',
|
84
|
+
body: 'method=2&api_key=key',
|
85
|
+
headers: anything,
|
86
|
+
idempotent: true,
|
87
|
+
retry_limit: 3,
|
88
|
+
retry_interval: 5
|
89
|
+
).and_return(double(body: '{}', status: 200))
|
90
|
+
client.post(method: 2)
|
91
|
+
|
92
|
+
EasyCompliance.retry_limit = 0
|
93
|
+
expect(Excon).to receive(:post).with(
|
94
|
+
'url',
|
95
|
+
body: 'method=2&api_key=key',
|
96
|
+
headers: anything,
|
97
|
+
idempotent: true,
|
98
|
+
retry_limit: 0,
|
99
|
+
retry_interval: 5
|
100
|
+
).and_return(double(body: '{}', status: 200))
|
101
|
+
client.post(method: 2)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'uses a default value of 5 for retry_interval unless it is set' do
|
105
|
+
EasyCompliance.retry_interval = nil
|
106
|
+
expect(Excon).to receive(:post).with(
|
107
|
+
'url',
|
108
|
+
body: 'method=2&api_key=key',
|
109
|
+
headers: anything,
|
110
|
+
idempotent: true,
|
111
|
+
retry_limit: 3,
|
112
|
+
retry_interval: 5
|
113
|
+
).and_return(double(body: '{}', status: 200))
|
114
|
+
client.post(method: 2)
|
115
|
+
|
116
|
+
EasyCompliance.retry_interval = 0
|
117
|
+
expect(Excon).to receive(:post).with(
|
118
|
+
'url',
|
119
|
+
body: 'method=2&api_key=key',
|
120
|
+
headers: anything,
|
121
|
+
idempotent: true,
|
122
|
+
retry_limit: 3,
|
123
|
+
retry_interval: 0
|
124
|
+
).and_return(double(body: '{}', status: 200))
|
125
|
+
client.post(method: 2)
|
126
|
+
end
|
43
127
|
end
|
44
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_compliance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace development team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.2.
|
130
|
+
rubygems_version: 3.2.25
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Ruby toolkit for https://www.easycompliance.de
|