Module: Assinafy::Utils
- Defined in:
- lib/assinafy/utils.rb,
sig/assinafy.rbs
Overview
Small, stateless helpers shared across resources. Intentionally private by convention — callers should reach for these via the resource methods, not directly.
Constant Summary collapse
- MAX_NORMALIZATION_DEPTH =
100
Class Method Summary collapse
-
.body_params(hash) ⇒ Hash{String=>Object}
Build a body Hash, translating documented hyphenated body keys (
signer-access-code,verification-code) while passing everything else through as-is. -
.clean_params(hash) ⇒ Hash
Drop nil values (but keep
false). -
.handle_assinafy_response(body) ⇒ Object
Unwrap an Assinafy envelope — a Hash with a numeric
statusand an optionaldatakey. -
.query_params(hash) ⇒ Hash{String=>Object}
Build a query-string Hash, translating the Ruby-friendly snake_case aliases in Utils.query_key_map to the hyphenated forms documented in the Assinafy API (e.g.
per_page→per-page).
Class Method Details
.body_params(hash) ⇒ Hash{String=>Object}
Build a body Hash, translating documented hyphenated body keys
(signer-access-code, verification-code) while passing everything
else through as-is.
60 61 62 |
# File 'lib/assinafy/utils.rb', line 60 def body_params(hash) normalize_keys(clean_params(hash), body_key_map) end |
.clean_params(hash) ⇒ Hash
Drop nil values (but keep false).
35 36 37 38 39 40 41 42 |
# File 'lib/assinafy/utils.rb', line 35 def clean_params(hash) return {} if hash.nil? raise ValidationError.new('Parameters must be a Hash') unless hash.is_a?(Hash) hash.each_with_object({}) do |(key, value), result| result[key] = value unless value.nil? end end |
.handle_assinafy_response(body) ⇒ Object
Unwrap an Assinafy envelope — a Hash with a numeric status and an
optional data key. Returns data (or nil) for 2xx, raises ApiError
otherwise, and passes through non-envelope bodies.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/assinafy/utils.rb', line 17 def handle_assinafy_response(body) return body unless body.is_a?(Hash) return body unless body.key?('status') status = Integer(body['status'], exception: false) return body unless status if status >= 200 && status < 300 body['data'] if body.key?('data') else raise ApiError.from_response(status, body) end end |
.query_params(hash) ⇒ Hash{String=>Object}
Build a query-string Hash, translating the Ruby-friendly snake_case
aliases in query_key_map to the hyphenated forms documented in the
Assinafy API (e.g. per_page → per-page).
50 51 52 |
# File 'lib/assinafy/utils.rb', line 50 def query_params(hash) normalize_keys(clean_params(hash), query_key_map) end |