|
13 | 13 | require_relative 'generated/video_client' |
14 | 14 | require_relative 'extensions/moderation_extensions' |
15 | 15 | require_relative 'generated/feed' |
| 16 | +require_relative 'generated/webhook' |
16 | 17 | require_relative 'stream_response' |
17 | 18 |
|
18 | 19 | module GetStreamRuby |
@@ -76,6 +77,52 @@ def feed(feed_group_id, feed_id) |
76 | 77 | GetStream::Generated::Feed.new(self, feed_group_id, feed_id) |
77 | 78 | end |
78 | 79 |
|
| 80 | + # Verify a webhook signature using this client's API secret (CHA-2961). |
| 81 | + # |
| 82 | + # Convenience wrapper around StreamChat::Webhook.verify_signature that |
| 83 | + # supplies the secret automatically. The module-level method is still |
| 84 | + # available for callers that need to verify with an arbitrary secret. |
| 85 | + # |
| 86 | + # @param body [String] The raw request body (already-decompressed) |
| 87 | + # @param signature [String] The signature from the X-Signature header |
| 88 | + # @return [Boolean] true if the signature is valid, false otherwise |
| 89 | + def verify_signature(body, signature) |
| 90 | + StreamChat::Webhook.verify_signature(body, signature, @configuration.api_secret) |
| 91 | + end |
| 92 | + |
| 93 | + # Verify and parse a webhook payload in one call, using this client's API |
| 94 | + # secret (CHA-2961). |
| 95 | + # |
| 96 | + # Handles gzip-compressed bodies transparently. Raises |
| 97 | + # StreamChat::Webhook::InvalidWebhookError on signature mismatch or parse |
| 98 | + # failures; distinguish failure modes via the message substring. |
| 99 | + # |
| 100 | + # @param body [String] raw request body (possibly gzip-compressed) |
| 101 | + # @param signature [String] X-Signature header value |
| 102 | + # @return [Object] the typed event class instance or |
| 103 | + # StreamChat::Webhook::UnknownEvent |
| 104 | + # @raise [StreamChat::Webhook::InvalidWebhookError] |
| 105 | + def verify_and_parse_webhook(body, signature) |
| 106 | + StreamChat::Webhook.verify_and_parse_webhook(body, signature, @configuration.api_secret) |
| 107 | + end |
| 108 | + |
| 109 | + # Decode + parse a Stream-delivered SQS message body. |
| 110 | + # |
| 111 | + # Convenience wrapper around StreamChat::Webhook.parse_sqs. No signature is |
| 112 | + # required; SQS deliveries are authenticated via AWS IAM. |
| 113 | + def parse_sqs(message_body) |
| 114 | + StreamChat::Webhook.parse_sqs(message_body) |
| 115 | + end |
| 116 | + |
| 117 | + # Decode + parse a Stream-delivered SNS notification body. |
| 118 | + # |
| 119 | + # Accepts either the raw SNS HTTP envelope JSON or the pre-extracted Message |
| 120 | + # string. Convenience wrapper around StreamChat::Webhook.parse_sns. No signature |
| 121 | + # is required; SNS deliveries are authenticated via AWS IAM. |
| 122 | + def parse_sns(notification_body) |
| 123 | + StreamChat::Webhook.parse_sns(notification_body) |
| 124 | + end |
| 125 | + |
79 | 126 | # @param path [String] The API path |
80 | 127 | # @param body [Hash] The request body |
81 | 128 | # @return [GetStreamRuby::StreamResponse] The API response |
|
0 commit comments