Class: Coolhand::OpenAi::WebhookValidator
- Inherits:
-
Object
- Object
- Coolhand::OpenAi::WebhookValidator
- Defined in:
- lib/coolhand/open_ai/webhook_validator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(request, webhook_secret) ⇒ WebhookValidator
constructor
A new instance of WebhookValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(request, webhook_secret) ⇒ WebhookValidator
Returns a new instance of WebhookValidator.
10 11 12 13 14 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 10 def initialize(request, webhook_secret) @request = request @errors = [] @webhook_secret = webhook_secret end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 8 def errors @errors end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 8 def payload @payload end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 8 def request @request end |
Instance Method Details
#error_message ⇒ Object
31 32 33 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 31 def @errors.join(", ") end |
#valid? ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 16 def valid? @errors.clear @payload = request.raw_post || request.body.read return false unless payload_valid? return validate_in_non_production_env unless Coolhand.required_field?(webhook_secret) secret_bytes = extract_secret_bytes webhook_signature, , webhook_id = extract_webhook_headers return validate_headers_in_non_production_env unless webhook_signature && verify_signature(webhook_signature, , webhook_id, secret_bytes) end |