clicksign-ruby-sdk 0.1.7 → 0.1.8
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/REVISION +1 -1
- data/lib/clicksign/client.rb +9 -2
- data/lib/clicksign/configuration.rb +1 -1
- data/lib/clicksign/error_handler.rb +3 -1
- data/lib/clicksign/json_api/atomic_results_parser.rb +2 -1
- data/lib/clicksign/json_api/bulk_operations_client.rb +2 -1
- data/lib/clicksign/json_api/parser.rb +2 -1
- data/lib/clicksign/resource.rb +1 -1
- data/lib/clicksign/resources/folder.rb +3 -1
- data/lib/clicksign/resources/membership.rb +15 -0
- data/lib/clicksign/resources/notarial/requirement.rb +5 -0
- data/lib/clicksign/retry_backoff.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8730a44f32966cd0d6978150f4c5c5e821de5c168b94f4e69ced112cef211cc
|
|
4
|
+
data.tar.gz: afe6780086fe195e7559470d86674d83b8927c725e96213f1bb930a43808af54
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c939a985f4caf49b47d15b2b6637550e20083cf217f077bf0d50c042946b693db885bb8ccad98abc1bfb48a7465d5ebc8ed9c47eef4aac8f32a078c9560fcb12
|
|
7
|
+
data.tar.gz: 80ee966ee546d6b401c7e427afa7bd7b881b64fb342e18e068469bb24f8b043220b1edc3d853bb3b348e1fac95c4e68284bf14a8a8ef1ac4325b25d176ce7f84
|
data/REVISION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.8
|
data/lib/clicksign/client.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Clicksign
|
|
|
14
14
|
}.freeze
|
|
15
15
|
|
|
16
16
|
def initialize(api_key:, base_url:, open_timeout: 2, read_timeout: 10,
|
|
17
|
-
write_timeout: 10, max_retries:
|
|
17
|
+
write_timeout: 10, max_retries: 3)
|
|
18
18
|
@api_key = api_key
|
|
19
19
|
@base_url = base_url
|
|
20
20
|
@open_timeout = open_timeout
|
|
@@ -42,6 +42,13 @@ module Clicksign
|
|
|
42
42
|
execute_with_retry(request, uri)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def put(path, body:)
|
|
46
|
+
uri = build_uri(path)
|
|
47
|
+
request = Net::HTTP::Put.new(uri, headers)
|
|
48
|
+
request.body = body.to_json
|
|
49
|
+
execute_with_retry(request, uri)
|
|
50
|
+
end
|
|
51
|
+
|
|
45
52
|
def delete(path, body: nil)
|
|
46
53
|
uri = build_uri(path)
|
|
47
54
|
request = Net::HTTP::Delete.new(uri, headers)
|
|
@@ -70,7 +77,7 @@ module Clicksign
|
|
|
70
77
|
Clicksign::ServerError => e
|
|
71
78
|
raise unless e.retryable? && attempts <= @max_retries
|
|
72
79
|
|
|
73
|
-
delay = RetryBackoff.
|
|
80
|
+
delay = RetryBackoff.retry_delay(attempts, e.response_headers)
|
|
74
81
|
publish_retry(request, uri, attempts, e, delay)
|
|
75
82
|
sleep(delay)
|
|
76
83
|
retry
|
|
@@ -50,7 +50,9 @@ module Clicksign
|
|
|
50
50
|
errors = body['errors']
|
|
51
51
|
return response.message unless errors.is_a?(Array)
|
|
52
52
|
|
|
53
|
-
result = errors.filter_map
|
|
53
|
+
result = errors.filter_map do |e|
|
|
54
|
+
e.is_a?(Hash) && (e['detail'] || e['title'])
|
|
55
|
+
end.join(', ')
|
|
54
56
|
result.empty? ? response.message : result
|
|
55
57
|
end
|
|
56
58
|
end
|
|
@@ -24,6 +24,7 @@ module Clicksign
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def build_operation_result(slot:, index:, op:, envelope_id:)
|
|
27
|
+
slot ||= {}
|
|
27
28
|
errors = slot['errors']
|
|
28
29
|
requirement = build_requirement(slot['data'], envelope_id: envelope_id)
|
|
29
30
|
|
|
@@ -54,7 +55,7 @@ module Clicksign
|
|
|
54
55
|
def format_errors(errors)
|
|
55
56
|
return 'Validation failed' unless errors.is_a?(Array)
|
|
56
57
|
|
|
57
|
-
errors.filter_map { |e| e['detail'] || e['title'] }.join(', ')
|
|
58
|
+
errors.filter_map { |e| e.is_a?(Hash) && (e['detail'] || e['title']) }.join(', ')
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
end
|
|
@@ -43,7 +43,8 @@ module Clicksign
|
|
|
43
43
|
begin
|
|
44
44
|
attempts += 1
|
|
45
45
|
execute_once(request, uri, attempt: attempts)
|
|
46
|
-
rescue Clicksign::TimeoutError
|
|
46
|
+
rescue Clicksign::TimeoutError, Clicksign::RateLimitError,
|
|
47
|
+
Clicksign::ServerError => e
|
|
47
48
|
raise unless e.retryable? && attempts <= @max_retries
|
|
48
49
|
|
|
49
50
|
delay = RetryBackoff.delay(attempts)
|
|
@@ -10,7 +10,8 @@ module Clicksign
|
|
|
10
10
|
data = case raw_data
|
|
11
11
|
when Array then raw_data.map { |item| build(item) }
|
|
12
12
|
when Hash then [build(raw_data)]
|
|
13
|
-
|
|
13
|
+
when nil then []
|
|
14
|
+
else raise Error, "Unexpected JSON:API data type: #{raw_data.class}"
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
included = Array(raw['included'])
|
data/lib/clicksign/resource.rb
CHANGED
|
@@ -13,6 +13,21 @@ module Clicksign
|
|
|
13
13
|
)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def update(**attributes)
|
|
17
|
+
raw = self.class.client.put(
|
|
18
|
+
"#{base_path}/#{@id}",
|
|
19
|
+
body: JsonApi::Serializer.dump(
|
|
20
|
+
type: self.class.resource_type, id: @id, attributes: attributes,
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
parsed = JsonApi::Parser.parse(raw)
|
|
24
|
+
data = parsed[:data].first
|
|
25
|
+
raise NotFoundError, 'API returned null data' if data.nil?
|
|
26
|
+
|
|
27
|
+
load_data(data, parent_id: @_parent_id)
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
|
|
16
31
|
def user_id
|
|
17
32
|
relationships.dig('user', 'data', 'id')
|
|
18
33
|
end
|
|
@@ -42,6 +42,11 @@ module Clicksign
|
|
|
42
42
|
end
|
|
43
43
|
private_class_method :list_related
|
|
44
44
|
|
|
45
|
+
def update(**)
|
|
46
|
+
raise NotImplementedError,
|
|
47
|
+
'Requirement does not support update (API does not provide this endpoint)'
|
|
48
|
+
end
|
|
49
|
+
|
|
45
50
|
def base_path
|
|
46
51
|
eid = @_parent_id || envelope_id
|
|
47
52
|
if eid.nil?
|
|
@@ -18,5 +18,22 @@ module Clicksign
|
|
|
18
18
|
|
|
19
19
|
rng.rand(max)
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
def parse_retry_after(headers)
|
|
23
|
+
return nil unless headers.is_a?(Hash)
|
|
24
|
+
|
|
25
|
+
raw = headers['retry-after'] || headers['Retry-After']
|
|
26
|
+
return nil if raw.nil? || raw.to_s.strip.empty?
|
|
27
|
+
|
|
28
|
+
Float(raw.to_s.strip)
|
|
29
|
+
rescue ArgumentError, TypeError
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def retry_delay(attempt, headers = nil, rng: Random)
|
|
34
|
+
jitter = delay(attempt, rng: rng)
|
|
35
|
+
retry_after = parse_retry_after(headers)
|
|
36
|
+
retry_after ? [jitter, retry_after].max : jitter
|
|
37
|
+
end
|
|
21
38
|
end
|
|
22
39
|
end
|