assinafy 2.2.0 → 2.4.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.
@@ -14,7 +14,8 @@ module Assinafy
14
14
  #
15
15
  # @param params [Hash] documented `search` query; additional deployment-specific keys are forwarded
16
16
  # @param account_id_override [String, nil]
17
- # @return [Hash{Symbol=>Array,Hash}] `{ data: [...], meta: { ... } }`
17
+ # @return [Hash{Symbol=>Array,Hash}] `{ data: [...], meta: { ... } }`; `meta` is absent when the
18
+ # response carries no pagination headers
18
19
  # @raise [Assinafy::ApiError] on an unsuccessful API response
19
20
  # @raise [Assinafy::NetworkError] on transport or TLS failure
20
21
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -52,7 +53,8 @@ module Assinafy
52
53
  #
53
54
  # @param payload [Hash]
54
55
  # @option payload [String] :name required tag display name
55
- # @option payload [String, nil] :color optional 6-digit hex color, with or without `#`
56
+ # @option payload [String, nil] :color optional 6-digit hex color; a leading `#` is accepted and
57
+ # removed before sending
56
58
  # @param account_id_override [String, nil]
57
59
  # @return [Hash] the created tag object
58
60
  # @raise [Assinafy::ValidationError] if `:name` is missing or blank
@@ -93,7 +95,8 @@ module Assinafy
93
95
  # @param tag_id [String]
94
96
  # @param payload [Hash]
95
97
  # @option payload [String] :name optional new name
96
- # @option payload [String, nil] :color optional new color; nil clears it
98
+ # @option payload [String, nil] :color optional new 6-digit hex color (a leading `#` is removed);
99
+ # nil clears it
97
100
  # @param account_id_override [String, nil]
98
101
  # @return [Hash] the updated tag object
99
102
  # @raise [Assinafy::ValidationError] if the payload is empty or `:name` is blank
@@ -163,14 +166,19 @@ module Assinafy
163
166
  private
164
167
 
165
168
  def tag_payload(payload, require_name:)
166
- raw = require_payload(payload, 'Tag payload')
167
- body = body_params(raw)
168
- body['color'] = nil if explicit_nil_color?(raw)
169
+ body = nullable_body(require_payload(payload, 'Tag payload'), %w[color])
169
170
 
170
- validate_tag_name!(body, require_name: require_name)
171
- if body.key?('color') && !body['color'].nil?
171
+ if require_name || body.key?('name')
172
+ problem = require_name ? 'is required' : 'cannot be blank'
173
+ raise ValidationError.new("Tag name #{problem}") if body['name'].to_s.strip.empty?
174
+
175
+ require_string(body['name'], 'Tag name')
176
+ end
177
+ unless body['color'].nil?
172
178
  color = require_string(body['color'], 'Tag color')
173
179
  raise ValidationError.new('Tag color must be a 6-digit hex color') unless color.match?(/\A#?[0-9a-f]{6}\z/i)
180
+
181
+ body['color'] = color.delete_prefix('#')
174
182
  end
175
183
 
176
184
  if !require_name && body.empty?
@@ -179,20 +187,6 @@ module Assinafy
179
187
 
180
188
  body
181
189
  end
182
-
183
- def validate_tag_name!(body, require_name:)
184
- has_name = body.key?('name')
185
- require_string(body['name'], 'Tag name') if has_name && !body['name'].to_s.strip.empty?
186
- blank = body['name'].to_s.strip.empty?
187
-
188
- raise ValidationError.new('Tag name is required') if require_name && (!has_name || blank)
189
- raise ValidationError.new('Tag name cannot be blank') if !require_name && has_name && blank
190
- end
191
-
192
- def explicit_nil_color?(payload)
193
- (payload.key?(:color) && payload[:color].nil?) ||
194
- (payload.key?('color') && payload['color'].nil?)
195
- end
196
190
  end
197
191
  end
198
192
  end
@@ -27,7 +27,7 @@ module Assinafy
27
27
  # # "name" => "sample-contract-one-page.pdf",
28
28
  # # "document_name" => "sample-contract-one-page.pdf",
29
29
  # # "message" => nil,
30
- # # "status" => "Ready",
30
+ # # "status" => "ready",
31
31
  # # "pages" => [{ "id" => "template-page-id", "number" => 1, "fields" => [] }],
32
32
  # # "roles" => [{ "id" => "role-id", "name" => "TemplateEditor" }],
33
33
  # # "tags" => [{ "id" => "tag-id-3", "name" => "HR" }],
@@ -65,7 +65,7 @@ module Assinafy
65
65
  # # "name" => "sample-contract-one-page.pdf",
66
66
  # # "document_name" => "sample-contract-one-page.pdf",
67
67
  # # "message" => nil,
68
- # # "status" => "Ready",
68
+ # # "status" => "ready",
69
69
  # # "pages" => [
70
70
  # # {
71
71
  # # "id" => "template-page-id", "number" => 1, "height" => 2100, "width" => 1275,
@@ -114,7 +114,7 @@ module Assinafy
114
114
  # # "name" => "contract.pdf",
115
115
  # # "document_name" => "contract.pdf",
116
116
  # # "message" => nil,
117
- # # "status" => "Uploaded",
117
+ # # "status" => "uploaded",
118
118
  # # "pages" => [],
119
119
  # # "roles" => [{ "id" => "role-id-2", "name" => "TemplateEditor",
120
120
  # # "assignment_type" => "Editor", "created_at" => "2026-07-20T15:57:19Z",
@@ -127,9 +127,8 @@ module Assinafy
127
127
  acc_id = account_id(account_id_override)
128
128
  options = require_payload(options, 'Template options')
129
129
  buffer, file_name = read_source(source, max_bytes: MAX_UPLOAD_BYTES)
130
- validate_pdf_source!(buffer, file_name, max_bytes: MAX_UPLOAD_BYTES)
130
+ validate_document_source!(buffer, file_name)
131
131
 
132
- # @type var payload: Hash[String | Symbol, untyped]
133
132
  payload = { file: file_part(buffer, file_name) }
134
133
  options.each { |key, value| payload[key.to_s] = value unless value.nil? }
135
134
 
@@ -159,7 +158,7 @@ module Assinafy
159
158
  # # "name" => "Renamed",
160
159
  # # "document_name" => "sample-contract-one-page.pdf",
161
160
  # # "message" => "Please sign",
162
- # # "status" => "Ready",
161
+ # # "status" => "ready",
163
162
  # # "created_at" => "2024-07-19T15:23:03Z",
164
163
  # # "updated_at" => "2024-07-19T16:00:00Z"
165
164
  # # # ... (full Template Object: pages, roles, tags; see docs for full shape)
@@ -37,12 +37,14 @@ module Assinafy
37
37
  # @raise [Assinafy::ApiError] on an unsuccessful API response
38
38
  # @raise [Assinafy::NetworkError] on transport or TLS failure
39
39
  # @raise [Assinafy::ValidationError] on invalid required input
40
+ # @note Not available to OAuth access tokens (403); OAuth apps read identity from
41
+ # {OAuthResource#userinfo}.
40
42
  # @see GET /users/self
41
43
  # @example Fetch the current user
42
44
  # # Request: GET /users/self
43
45
  # client.users.me
44
46
  #
45
- # # Current OpenAPI response (unwrapped data payload; the deployed API also adds is_password_set):
47
+ # # Current OpenAPI response (unwrapped data payload):
46
48
  # {
47
49
  # 'id' => 'user-id',
48
50
  # 'name' => 'Example User',
@@ -51,7 +53,6 @@ module Assinafy
51
53
  # 'government_id' => '',
52
54
  # 'is_email_verified' => true,
53
55
  # 'has_accepted_terms' => true,
54
- # 'is_password_set' => true,
55
56
  # 'created_at' => '2026-05-12T18:05:11Z',
56
57
  # 'to_be_deleted_at' => nil
57
58
  # }
@@ -96,6 +97,8 @@ module Assinafy
96
97
  # @raise [Assinafy::ApiError] on an unsuccessful API response
97
98
  # @raise [Assinafy::NetworkError] on transport or TLS failure
98
99
  # @raise [Assinafy::ValidationError] on invalid required input
100
+ # @note Not available to OAuth access tokens (403); OAuth apps read identity from
101
+ # {OAuthResource#userinfo}.
99
102
  # @see GET /users/self/stats
100
103
  # @example Fetch monthly cross-account KPIs
101
104
  # # Request: GET /users/self/stats?granularity=monthly
@@ -134,6 +137,7 @@ module Assinafy
134
137
  # @raise [Assinafy::ApiError] on an unsuccessful API response
135
138
  # @raise [Assinafy::NetworkError] on transport or TLS failure
136
139
  # @raise [Assinafy::ValidationError] on invalid required input
140
+ # @note Not available to third-party OAuth applications (403).
137
141
  # @see GET /users/self/notification-preferences
138
142
  # @example Fetch the current preferences
139
143
  # # Request: GET /users/self/notification-preferences
@@ -170,6 +174,7 @@ module Assinafy
170
174
  # @raise [Assinafy::ApiError] on an unsuccessful API response
171
175
  # @raise [Assinafy::NetworkError] on transport or TLS failure
172
176
  # @raise [Assinafy::ValidationError] on invalid required input
177
+ # @note Not available to third-party OAuth applications (403).
173
178
  # @see PUT /users/self/notification-preferences
174
179
  # @example Disable one notification
175
180
  # client.users.update_notification_preferences(SignerDeclined: false)
@@ -22,8 +22,12 @@ module Assinafy
22
22
  # `update` alias). Accounts with several endpoints should use
23
23
  # {#create_endpoint} / {#update_endpoint}.
24
24
  #
25
+ # `is_active` defaults to `true`, so a call that leaves it out reactivates an inactive endpoint
26
+ # and lifts a pause. The `url` is always required and must be HTTPS; to change the events of an
27
+ # older endpoint registered over HTTP, use {#update_endpoint}.
28
+ #
25
29
  # @param payload [Hash]
26
- # @option payload [String] :url endpoint that will receive events
30
+ # @option payload [String] :url HTTPS endpoint that will receive events
27
31
  # @option payload [String] :email contact email for delivery health
28
32
  # @option payload [Array<String>] :events event-type IDs (see {#list_event_types})
29
33
  # @option payload [Boolean] :is_active default `true` when omitted
@@ -71,11 +75,11 @@ module Assinafy
71
75
 
72
76
  alias update register
73
77
 
74
- # Fetch the account's oldest webhook endpoint. Returns `nil` on 404
75
- # (no endpoint configured yet).
78
+ # Fetch the account's oldest webhook endpoint. An account with nothing configured answers 200
79
+ # with `url`, `email` and `updated_at` set to nil.
76
80
  #
77
81
  # @param account_id_override [String, nil]
78
- # @return [Hash, nil] subscription object, or `nil` when none is configured (404)
82
+ # @return [Hash, nil] subscription object; `nil` only if the API answers 404
79
83
  # @raise [Assinafy::ApiError] on an unsuccessful API response
80
84
  # @raise [Assinafy::NetworkError] on transport or TLS failure
81
85
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -83,7 +87,7 @@ module Assinafy
83
87
  # @example Fetch the current subscription
84
88
  # client.webhooks.get
85
89
  # # GET /accounts/{account_id}/webhooks/subscriptions
86
- # # => unwrapped data payload returned (nil if no subscription exists):
90
+ # # => unwrapped data payload returned:
87
91
  # # {
88
92
  # # 'events' => ["document_ready", "signer_signed_document"],
89
93
  # # 'is_active' => false,
@@ -93,6 +97,9 @@ module Assinafy
93
97
  # # 'email' => "webhook@example.com",
94
98
  # # 'updated_at' => "2026-06-05T21:13:24Z"
95
99
  # # }
100
+ # # With nothing configured:
101
+ # # { 'events' => [], 'is_active' => false, 'is_held' => false, 'held_since' => nil,
102
+ # # 'url' => nil, 'email' => nil, 'updated_at' => nil }
96
103
  def get(account_id_override = nil)
97
104
  acc_id = account_id(account_id_override)
98
105
 
@@ -146,14 +153,11 @@ module Assinafy
146
153
  # # GET /webhooks/event-types
147
154
  # # => unwrapped data payload returned:
148
155
  # # [
149
- # # { 'id' => "document_uploaded", 'description' => "Document uploaded" },
150
- # # { 'id' => "document_metadata_ready", 'description' => "Document metadata ready" },
151
- # # { 'id' => "document_prepared", 'description' => "Document prepared" },
152
- # # { 'id' => "assignment_created", 'description' => "Assignment created" },
153
- # # { 'id' => "signature_requested", 'description' => "Signature requested" },
154
- # # { 'id' => "document_ready", 'description' => "All signers signed" },
155
- # # { 'id' => "signer_created", 'description' => "Signer created" },
156
- # # { 'id' => "signer_email_verified", 'description' => "Signer email verified" }
156
+ # # { 'id' => "document_uploaded", 'description' => "Triggered when a document is uploaded." },
157
+ # # { 'id' => "signature_requested", 'description' => "Triggered when a signature is requested." },
158
+ # # { 'id' => "signer_signed_document", 'description' => "Triggered when a signer signs a document." },
159
+ # # { 'id' => "document_ready",
160
+ # # 'description' => "Triggered when a document is certificated, after all signers have signed." }
157
161
  # # # ... (read list_event_types for the complete current catalogue)
158
162
  # # ]
159
163
  def list_event_types
@@ -173,27 +177,30 @@ module Assinafy
173
177
  # @raise [Assinafy::ValidationError] on invalid required input
174
178
  # @see GET /accounts/{account_id}/webhooks
175
179
  # @example List delivery attempts, filtered to undelivered
176
- # client.webhooks.list_dispatches(delivered: false, 'per-page': 20)
180
+ # client.webhooks.list_dispatches(delivered: false, per_page: 20)
177
181
  # # GET /accounts/{account_id}/webhooks?delivered=false&per-page=20
178
182
  # # => unwrapped data payload returned (pagination from x-pagination-* headers):
179
183
  # # {
180
184
  # # data: [
181
185
  # # {
182
- # # 'id' => "dispatch-id",
183
- # # event: "signature_requested",
184
- # # activity_id: 15431,
185
- # # endpoint: "https://example.com/webhook",
186
- # # payload: { 'id' => 15431, event: "signature_requested", object: {}, subject: {}, payload: {} },
187
- # # delivered: false,
188
- # # webhook_id: "webhook-id-placeholder",
189
- # # attempt: 2,
190
- # # kind: "scheduled",
191
- # # will_retry: false,
192
- # # http_status: 404,
193
- # # response_body: "{\"success\":false,...}",
194
- # # error: "Client error: `POST https://example.com/webhook` resulted in a 404 ...",
195
- # # 'created_at' => "2026-07-20T15:57:38Z",
196
- # # 'updated_at' => "2026-07-20T15:57:38Z"
186
+ # # 'id' => "dispatch-id",
187
+ # # 'event' => "signature_requested",
188
+ # # 'activity_id' => 15431,
189
+ # # 'endpoint_id' => "webhook-endpoint-id",
190
+ # # 'endpoint' => "https://example.com/webhook",
191
+ # # 'payload' => { 'id' => 15431, 'event' => "signature_requested", 'object' => {},
192
+ # # 'subject' => {}, 'payload' => {} },
193
+ # # 'delivered' => false,
194
+ # # 'webhook_id' => "webhook-id-placeholder",
195
+ # # 'attempt' => 2,
196
+ # # 'kind' => "scheduled",
197
+ # # 'will_retry' => false,
198
+ # # 'duration_ms' => 184,
199
+ # # 'http_status' => 404,
200
+ # # 'response_body' => "{\"success\":false,...}",
201
+ # # 'error' => "Client error: `POST https://example.com/webhook` resulted in a 404 ...",
202
+ # # 'created_at' => "2026-07-20T15:57:38Z",
203
+ # # 'updated_at' => "2026-07-20T15:57:38Z"
197
204
  # # }
198
205
  # # # ... (see docs for full dispatch shape)
199
206
  # # ],
@@ -221,22 +228,24 @@ module Assinafy
221
228
  # # POST /accounts/{account_id}/webhooks/dispatch-id/retry (no request body)
222
229
  # # => unwrapped data payload returned:
223
230
  # # {
224
- # # resource: "activity_dispatching_history",
225
- # # 'id' => "dispatch-id",
226
- # # event: "signature_requested",
227
- # # activity_id: 15431,
228
- # # endpoint: "https://example.com/webhook",
229
- # # payload: { 'id' => 15431, event: "signature_requested", object: {}, subject: {} },
230
- # # delivered: true,
231
- # # webhook_id: "webhook-id-placeholder",
232
- # # attempt: 1,
233
- # # kind: "manual",
234
- # # will_retry: false,
235
- # # http_status: 200,
236
- # # response_body: "OK",
237
- # # error: nil,
238
- # # 'created_at' => "2026-07-20T15:57:38Z",
239
- # # 'updated_at' => "2026-07-20T15:57:39Z"
231
+ # # 'resource' => "activity_dispatching_history",
232
+ # # 'id' => "dispatch-id",
233
+ # # 'event' => "signature_requested",
234
+ # # 'activity_id' => 15431,
235
+ # # 'endpoint_id' => "webhook-endpoint-id",
236
+ # # 'endpoint' => "https://example.com/webhook",
237
+ # # 'payload' => { 'id' => 15431, 'event' => "signature_requested", 'object' => {}, 'subject' => {} },
238
+ # # 'delivered' => true,
239
+ # # 'webhook_id' => "webhook-id-placeholder",
240
+ # # 'attempt' => 1,
241
+ # # 'kind' => "manual",
242
+ # # 'will_retry' => false,
243
+ # # 'duration_ms' => 184,
244
+ # # 'http_status' => 200,
245
+ # # 'response_body' => "OK",
246
+ # # 'error' => nil,
247
+ # # 'created_at' => "2026-07-20T15:57:38Z",
248
+ # # 'updated_at' => "2026-07-20T15:57:39Z"
240
249
  # # }
241
250
  def retry_dispatch(dispatch_id, account_id_override = nil)
242
251
  acc_id = account_id(account_id_override)
@@ -522,8 +531,7 @@ module Assinafy
522
531
  def webhook_body(payload, allowed, required)
523
532
  body = require_payload(payload, 'Webhook payload').transform_keys(&:to_sym)
524
533
 
525
- unknown = body.keys - allowed
526
- raise ValidationError.new("Unknown webhook fields: #{unknown.join(', ')}") unless unknown.empty?
534
+ reject_unknown_keys!(body, allowed, 'webhook fields')
527
535
 
528
536
  missing = required - body.keys
529
537
  raise ValidationError.new("Missing webhook fields: #{missing.join(', ')}") unless missing.empty?
@@ -79,7 +79,7 @@ module Assinafy
79
79
  return false unless secret && !secret.empty?
80
80
  return false unless signature && !signature.to_s.strip.empty?
81
81
 
82
- body = payload.is_a?(String) ? payload : payload.to_s
82
+ body = payload.to_s
83
83
  expected = OpenSSL::HMAC.hexdigest('SHA256', secret, body)
84
84
  provided = signature.to_s.strip
85
85
 
@@ -94,7 +94,7 @@ module Assinafy
94
94
  # @param payload [String]
95
95
  # @return [Hash, nil]
96
96
  def extract_event(payload)
97
- text = payload.is_a?(String) ? payload : payload.to_s
97
+ text = payload.to_s
98
98
  parsed = JSON.parse(text)
99
99
  parsed.is_a?(Hash) ? parsed : nil
100
100
  rescue JSON::ParserError
@@ -10,6 +10,16 @@ module Assinafy
10
10
  module Utils
11
11
  MAX_NORMALIZATION_DEPTH = 100
12
12
  EMAIL_PATTERN = /\A[^\s@]+@[^\s@]+\.[^\s@]+\z/
13
+ QUERY_KEY_MAP = {
14
+ 'access_token' => 'access-token',
15
+ 'per_page' => 'per-page',
16
+ 'signer_access_code' => 'signer-access-code'
17
+ }.freeze
18
+ BODY_KEY_MAP = {
19
+ 'signer_access_code' => 'signer-access-code',
20
+ 'verification_code' => 'verification-code'
21
+ }.freeze
22
+ private_constant :QUERY_KEY_MAP, :BODY_KEY_MAP
13
23
 
14
24
  class << self
15
25
  # Validate a spending ceiling without changing the caller's numeric representation.
@@ -52,9 +62,7 @@ module Assinafy
52
62
  return nil if value.nil?
53
63
  raise ValidationError.new('expires_at must be a String') unless value.is_a?(String)
54
64
 
55
- unless value.match?(/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?
56
- (?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)\z/x) &&
57
- DateTime.iso8601(value).to_time >= Time.now + 3600
65
+ unless value.match?(Validation::ZONED_ISO8601) && DateTime.iso8601(value).to_time >= Time.now + 3600
58
66
  raise ValidationError.new('expires_at must be an ISO 8601 timestamp at least one hour in the future')
59
67
  end
60
68
 
@@ -97,13 +105,13 @@ module Assinafy
97
105
  end
98
106
 
99
107
  # Build a query-string Hash, translating the Ruby-friendly snake_case
100
- # aliases in {query_key_map} to the hyphenated forms documented in the
108
+ # aliases (`per_page`, `access_token`, `signer_access_code`) to the hyphenated forms documented in the
101
109
  # Assinafy API (e.g. `per_page` → `per-page`).
102
110
  #
103
111
  # @param hash [Hash, nil]
104
112
  # @return [Hash{String=>Object}]
105
113
  def query_params(hash)
106
- normalize_keys(clean_params(hash), query_key_map)
114
+ normalize_keys(clean_params(hash), QUERY_KEY_MAP)
107
115
  end
108
116
 
109
117
  # Build a body Hash, translating documented hyphenated body keys
@@ -113,7 +121,7 @@ module Assinafy
113
121
  # @param hash [Hash, nil]
114
122
  # @return [Hash{String=>Object}]
115
123
  def body_params(hash)
116
- normalize_keys(clean_params(hash), body_key_map)
124
+ normalize_keys(clean_params(hash), BODY_KEY_MAP)
117
125
  end
118
126
 
119
127
  private
@@ -157,21 +165,6 @@ module Assinafy
157
165
  raw = key.to_s
158
166
  key_map.fetch(raw, raw)
159
167
  end
160
-
161
- def query_key_map
162
- {
163
- 'access_token' => 'access-token',
164
- 'per_page' => 'per-page',
165
- 'signer_access_code' => 'signer-access-code'
166
- }
167
- end
168
-
169
- def body_key_map
170
- {
171
- 'signer_access_code' => 'signer-access-code',
172
- 'verification_code' => 'verification-code'
173
- }
174
- end
175
168
  end
176
169
  end
177
170
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Assinafy
4
+ # Stateless argument checks shared by resources, class-level payload builders,
5
+ # the client and the OAuth helpers.
6
+ #
7
+ # @api private
8
+ module Validation
9
+ PATH_SEGMENT = /\A[A-Za-z0-9._~-]+\z/
10
+ ZONED_ISO8601 = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)\z/
11
+
12
+ module_function
13
+
14
+ def require_present(value, name)
15
+ return value unless value.nil? || value.to_s.strip.empty?
16
+
17
+ raise ValidationError.new("#{name} is required")
18
+ end
19
+
20
+ # A value is interpolated into a request path only when this holds, which
21
+ # keeps `.`, `..` and separators from changing the route.
22
+ def path_segment?(value)
23
+ value.is_a?(String) && PATH_SEGMENT.match?(value) && value != '.' && value != '..'
24
+ end
25
+
26
+ def require_id(value, name)
27
+ id = require_string(value, name)
28
+ return id if path_segment?(id)
29
+
30
+ raise ValidationError.new("#{name} contains invalid characters")
31
+ end
32
+
33
+ def require_string(value, name, max_length: nil)
34
+ string = require_present(value, name)
35
+ raise ValidationError.new("#{name} must be a String") unless string.is_a?(String)
36
+ if max_length && string.length > max_length
37
+ raise ValidationError.new("#{name} must be at most #{max_length} characters")
38
+ end
39
+
40
+ string
41
+ end
42
+
43
+ def require_boolean(value, name)
44
+ return value if [true, false].include?(value)
45
+
46
+ raise ValidationError.new("#{name} must be true or false")
47
+ end
48
+
49
+ def require_payload(payload, name = 'Payload')
50
+ raise ValidationError.new("#{name} must be a Hash") unless payload.is_a?(Hash)
51
+
52
+ payload
53
+ end
54
+
55
+ def require_array(value, name)
56
+ return value if value.is_a?(Array) && !value.empty?
57
+
58
+ raise ValidationError.new("#{name} must be a non-empty Array")
59
+ end
60
+
61
+ def require_one_of(value, allowed, name)
62
+ return value if allowed.include?(value)
63
+
64
+ raise ValidationError.new("#{name} must be one of: #{allowed.join(', ')}")
65
+ end
66
+
67
+ def require_integer(value, name, minimum, maximum = nil)
68
+ return value if value.is_a?(Integer) && value >= minimum && (maximum.nil? || value <= maximum)
69
+
70
+ range = maximum ? "between #{minimum} and #{maximum}" : "at least #{minimum}"
71
+ raise ValidationError.new("#{name} must be an Integer #{range}")
72
+ end
73
+
74
+ def reject_unknown_keys!(hash, allowed, name)
75
+ unknown = hash.keys - allowed
76
+ raise ValidationError.new("Unknown #{name}: #{unknown.join(', ')}") unless unknown.empty?
77
+ end
78
+ end
79
+ private_constant :Validation
80
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Assinafy
4
- VERSION = '2.2.0'
4
+ VERSION = '2.4.0'
5
5
  USER_AGENT = "Assinafy-Ruby-SDK/v#{VERSION}".freeze
6
6
  end
data/lib/assinafy.rb CHANGED
@@ -7,12 +7,12 @@ require 'stringio'
7
7
 
8
8
  require_relative 'assinafy/version'
9
9
  require_relative 'assinafy/errors'
10
+ require_relative 'assinafy/validation'
10
11
  require_relative 'assinafy/null_logger'
11
12
  require_relative 'assinafy/configuration'
12
13
  require_relative 'assinafy/utils'
13
14
  require_relative 'assinafy/oauth'
14
15
  require_relative 'assinafy/resources/base_resource'
15
- require_relative 'assinafy/resources/auth_resource'
16
16
  require_relative 'assinafy/resources/oauth_resource'
17
17
  require_relative 'assinafy/resources/account_resource'
18
18
  require_relative 'assinafy/resources/user_resource'
@@ -22,6 +22,7 @@ require_relative 'assinafy/resources/signer_resource'
22
22
  require_relative 'assinafy/resources/signer_document_resource'
23
23
  require_relative 'assinafy/resources/assignment_resource'
24
24
  require_relative 'assinafy/resources/envelope_resource'
25
+ require_relative 'assinafy/resources/scheduled_send_resource'
25
26
  require_relative 'assinafy/resources/webhook_resource'
26
27
  require_relative 'assinafy/resources/template_resource'
27
28
  require_relative 'assinafy/resources/field_resource'