Class: Fal::WebhookRequest
- Inherits:
-
Object
- Object
- Fal::WebhookRequest
- Defined in:
- lib/fal/webhook_request.rb
Overview
WebhookRequest parses incoming webhook payloads from fal and exposes convenient helpers to inspect success/error and access the response payload. Follows Rails-like naming with predicate helpers.
Defined Under Namespace
Modules: Status
Instance Attribute Summary collapse
-
#error ⇒ String?
readonly
Error message when provided.
-
#gateway_request_id ⇒ String?
readonly
The gateway request identifier, when present.
-
#logs ⇒ Array<Hash>?
readonly
Log entries, when present.
-
#metrics ⇒ Hash?
readonly
Metrics, when present.
-
#raw ⇒ Hash
readonly
The raw parsed payload.
-
#request_id ⇒ String?
readonly
The request identifier.
-
#response ⇒ Hash?
readonly
Model-specific response payload.
-
#status ⇒ String?
readonly
Webhook status (OK/ERROR) when provided.
Class Method Summary collapse
-
.from_hash(payload) ⇒ Fal::WebhookRequest
Build from a Hash payload.
-
.from_json(json) ⇒ Fal::WebhookRequest
Build from a JSON string body.
-
.from_rack_request(request) ⇒ Fal::WebhookRequest
Build from a Rack::Request.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#error_detail ⇒ String?
Any nested error detail.
-
#initialize(attributes) ⇒ WebhookRequest
constructor
Initialize from a parsed payload Hash (string keys expected, tolerant of symbol keys).
-
#payload ⇒ Hash?
Back-compat alias matching older naming (payload vs response).
- #success? ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ WebhookRequest
Initialize from a parsed payload Hash (string keys expected, tolerant of symbol keys).
35 36 37 38 |
# File 'lib/fal/webhook_request.rb', line 35 def initialize(attributes) @raw = attributes reset_attributes(attributes) end |
Instance Attribute Details
#error ⇒ String? (readonly)
Returns Error message when provided.
23 24 25 |
# File 'lib/fal/webhook_request.rb', line 23 def error @error end |
#gateway_request_id ⇒ String? (readonly)
Returns The gateway request identifier, when present.
19 20 21 |
# File 'lib/fal/webhook_request.rb', line 19 def gateway_request_id @gateway_request_id end |
#logs ⇒ Array<Hash>? (readonly)
Returns Log entries, when present.
27 28 29 |
# File 'lib/fal/webhook_request.rb', line 27 def logs @logs end |
#metrics ⇒ Hash? (readonly)
Returns Metrics, when present.
29 30 31 |
# File 'lib/fal/webhook_request.rb', line 29 def metrics @metrics end |
#raw ⇒ Hash (readonly)
Returns The raw parsed payload.
31 32 33 |
# File 'lib/fal/webhook_request.rb', line 31 def raw @raw end |
#request_id ⇒ String? (readonly)
Returns The request identifier.
17 18 19 |
# File 'lib/fal/webhook_request.rb', line 17 def request_id @request_id end |
#response ⇒ Hash? (readonly)
Returns Model-specific response payload.
25 26 27 |
# File 'lib/fal/webhook_request.rb', line 25 def response @response end |
#status ⇒ String? (readonly)
Returns Webhook status (OK/ERROR) when provided.
21 22 23 |
# File 'lib/fal/webhook_request.rb', line 21 def status @status end |
Class Method Details
.from_hash(payload) ⇒ Fal::WebhookRequest
Build from a Hash payload.
60 61 62 |
# File 'lib/fal/webhook_request.rb', line 60 def from_hash(payload) new(payload) end |
.from_json(json) ⇒ Fal::WebhookRequest
Build from a JSON string body.
44 45 46 |
# File 'lib/fal/webhook_request.rb', line 44 def from_json(json) new(JSON.parse(json)) end |
.from_rack_request(request) ⇒ Fal::WebhookRequest
Build from a Rack::Request.
51 52 53 54 55 |
# File 'lib/fal/webhook_request.rb', line 51 def from_rack_request(request) body = request.body.read request.body.rewind if request.body.respond_to?(:rewind) from_json(body) end |
Instance Method Details
#error? ⇒ Boolean
73 74 75 |
# File 'lib/fal/webhook_request.rb', line 73 def error? !success? end |
#error_detail ⇒ String?
Returns Any nested error detail.
84 |
# File 'lib/fal/webhook_request.rb', line 84 def error_detail = @response&.dig(:detail) |
#payload ⇒ Hash?
Back-compat alias matching older naming (payload vs response).
79 80 81 |
# File 'lib/fal/webhook_request.rb', line 79 def payload @response end |
#success? ⇒ Boolean
66 67 68 69 70 |
# File 'lib/fal/webhook_request.rb', line 66 def success? @status == Status::OK || ( @status.nil? && @error.nil? ) end |