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.
-
#webhook_secret ⇒ Object
readonly
Returns the value of attribute webhook_secret.
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.
8 9 10 11 12 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 8 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.
6 7 8 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 6 def errors @errors end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 6 def payload @payload end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
6 7 8 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 6 def request @request end |
#webhook_secret ⇒ Object (readonly)
Returns the value of attribute webhook_secret.
6 7 8 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 6 def webhook_secret @webhook_secret end |
Instance Method Details
#error_message ⇒ Object
29 30 31 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 29 def @errors.join(", ") end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coolhand/open_ai/webhook_validator.rb', line 14 def valid? @errors.clear @payload = request.raw_post || request.body.read return false unless payload_valid? return validate_in_non_production_env unless 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 |