perfect_audit 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/README.md +2 -2
- data/lib/perfect_audit/api/repositories.rb +3 -3
- data/lib/perfect_audit/auth_token.rb +52 -0
- data/lib/perfect_audit/connection.rb +12 -4
- data/lib/perfect_audit/error.rb +12 -0
- data/lib/perfect_audit/response_parser.rb +0 -1
- data/lib/perfect_audit/version.rb +1 -1
- data/lib/perfect_audit.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af50a107a40785baccddff517b7757b7d1c6f2c035d15ccb9cabc8bde78d2397
|
4
|
+
data.tar.gz: 86776b33d5af0c4e5416530932d80465e814dff38e0b62e296e337a77efa9caa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0818afd972cd9f63e19945fb25d4d6c07a08dd9f1d12af6d8257af808504a0f503d4f599036fe6401d8e4f7c7b9b30fd9bb329e347b5f78fc2ae33b08fd196a7'
|
7
|
+
data.tar.gz: 5b38f1e894206d53182d1f7e2d7925ffc9af252dbadd37490ad435bcea58701dc5cf053736e299fdfb9598ed575a1487311619d25d23702851393cfe556338a7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -29,8 +29,8 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
``` ruby
|
31
31
|
PerfectAudit.configure do |config|
|
32
|
-
config.
|
33
|
-
config.
|
32
|
+
config.client_id = 'your_client_id'
|
33
|
+
config.client_secret = 'your_client_secret'
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
@@ -27,7 +27,7 @@ module PerfectAudit
|
|
27
27
|
is_public: public.to_s
|
28
28
|
})
|
29
29
|
|
30
|
-
PerfectAudit::Book.new(response_parser.parse(response.body.to_s))
|
30
|
+
PerfectAudit::Book.new(**response_parser.parse(response.body.to_s))
|
31
31
|
end
|
32
32
|
|
33
33
|
# Get all books from Perfect Audit for account
|
@@ -38,7 +38,7 @@ module PerfectAudit
|
|
38
38
|
response = connection.get(ALL_PATH)
|
39
39
|
|
40
40
|
response_parser.parse(response.body.to_s).map { |item|
|
41
|
-
PerfectAudit::Book.new(item)
|
41
|
+
PerfectAudit::Book.new(**item)
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
@@ -53,7 +53,7 @@ module PerfectAudit
|
|
53
53
|
pk: id.to_s
|
54
54
|
})
|
55
55
|
|
56
|
-
PerfectAudit::Book.new(response_parser.parse(response.body.to_s))
|
56
|
+
PerfectAudit::Book.new(**response_parser.parse(response.body.to_s))
|
57
57
|
end
|
58
58
|
|
59
59
|
# Delete book in Perfect Audit
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
module PerfectAudit
|
7
|
+
class AuthToken
|
8
|
+
extend Dry::Initializer
|
9
|
+
|
10
|
+
AUTH_PATH = 'https://auth.ocrolus.com/oauth/token'
|
11
|
+
|
12
|
+
option :client_id
|
13
|
+
option :client_secret
|
14
|
+
|
15
|
+
def get
|
16
|
+
request if expired?
|
17
|
+
|
18
|
+
@token
|
19
|
+
end
|
20
|
+
|
21
|
+
def expired?
|
22
|
+
@token.nil? || Time.now >= @expires_at
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def request
|
28
|
+
response = HTTP.post(AUTH_PATH, json: credentials)
|
29
|
+
|
30
|
+
raise AuthError if response.status.client_error?
|
31
|
+
raise ServerError if response.status.server_error?
|
32
|
+
|
33
|
+
parse(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def credentials
|
37
|
+
{
|
38
|
+
client_id: client_id,
|
39
|
+
client_secret: client_secret,
|
40
|
+
grant_type: 'client_credentials',
|
41
|
+
audience: 'https://api.ocrolus.com/'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse(response)
|
46
|
+
response = JSON.parse(response)
|
47
|
+
|
48
|
+
@token = response['access_token']
|
49
|
+
@expires_at = Time.now + response['expires_in']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -9,21 +9,29 @@ module PerfectAudit
|
|
9
9
|
|
10
10
|
BASE_PATH = 'https://api.ocrolus.com/v1/'
|
11
11
|
|
12
|
-
option :
|
13
|
-
option :
|
12
|
+
option :client_id
|
13
|
+
option :client_secret
|
14
14
|
|
15
15
|
def post(path, params = {})
|
16
|
-
HTTP.
|
16
|
+
HTTP.auth(auth).post(url(path), params)
|
17
17
|
end
|
18
18
|
|
19
19
|
def get(path, params = {})
|
20
|
-
HTTP.
|
20
|
+
HTTP.auth(auth).get(url(path), params)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def auth
|
26
|
+
"Bearer #{auth_token.get}"
|
27
|
+
end
|
28
|
+
|
25
29
|
def url(path)
|
26
30
|
URI.join(BASE_PATH, path)
|
27
31
|
end
|
32
|
+
|
33
|
+
def auth_token
|
34
|
+
@auth_token ||= AuthToken.new(client_id: client_id, client_secret: client_secret)
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
data/lib/perfect_audit/error.rb
CHANGED
@@ -13,4 +13,16 @@ module PerfectAudit
|
|
13
13
|
super + " [#{@code}]"
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
class AuthError < StandardError
|
18
|
+
def message
|
19
|
+
'Your credentials are invalid or have been revoked'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ServerError < StandardError
|
24
|
+
def message
|
25
|
+
'Ocrolus is unavailable. Please try again later.'
|
26
|
+
end
|
27
|
+
end
|
16
28
|
end
|
data/lib/perfect_audit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perfect_audit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-auto_inject
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- lib/perfect_audit/api/document.rb
|
248
248
|
- lib/perfect_audit/api/period.rb
|
249
249
|
- lib/perfect_audit/api/repositories.rb
|
250
|
+
- lib/perfect_audit/auth_token.rb
|
250
251
|
- lib/perfect_audit/connection.rb
|
251
252
|
- lib/perfect_audit/error.rb
|
252
253
|
- lib/perfect_audit/response_parser.rb
|