Skip to content

Commit 0b5df91

Browse files
committed
Update README and handler plugin documentation for snake_case conventions; add Team1Handler example
1 parent b6c9268 commit 0b5df91

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ Here is a very high-level overview of how Hooks works:
5050
```yaml
5151
# file: config/endpoints/hello.yml
5252
path: /hello
53-
handler: MyCustomHandler # This is a custom handler plugin you would define in the plugins/handlers directory
53+
handler: my_custom_handler # This is a custom handler plugin you would define in the plugins/handlers directory (snake_case)
5454
```
5555

56+
> Note: If your handler's class name is `MyCustomHandler`, you would define it in the `plugins/handlers/my_custom_handler.rb` file. The `handler` field in the endpoint configuration file should be the snake_case version of the class name. So if your handler class is `MyCustomHandler`, you would use `my_custom_handler` in the endpoint configuration file.
57+
5658
3. Now create a corresponding handler plugin in the `plugins/handlers` directory. Here is an example of a simple handler plugin:
5759

5860
```ruby
@@ -64,7 +66,7 @@ Here is a very high-level overview of how Hooks works:
6466
# For this example, we will just return a success message
6567
{
6668
status: "success",
67-
handler: "MyCustomHandler",
69+
handler: "my_custom_handler",
6870
payload_received: payload,
6971
timestamp: Time.now.utc.iso8601
7072
}
@@ -208,16 +210,16 @@ Endpoint configurations are defined in the `config/endpoints` directory. Each en
208210
```yaml
209211
# file: config/endpoints/hello.yml
210212
path: /hello # becomes /webhooks/hello based on the root_path in hooks.yml
211-
handler: HelloHandler # This is a custom handler plugin you would define in the plugins/handlers
213+
handler: hello_handler # This is a custom handler plugin you would define in the plugins/handlers
212214
```
213215

214216
```yaml
215217
# file: config/endpoints/goodbye.yml
216218
path: /goodbye # becomes /webhooks/goodbye based on the root_path in hooks.yml
217-
handler: GoodbyeHandler # This is another custom handler plugin you would define in the plugins/handlers
219+
handler: goodbye_handler # This is another custom handler plugin you would define in the plugins/handlers
218220
219221
auth:
220-
type: Goodbye # This is a custom authentication plugin you would define in the plugins/auth
222+
type: goodbye # This is a custom authentication plugin you would define in the plugins/auth
221223
secret_env_key: GOODBYE_API_KEY # the name of the environment variable containing the secret
222224
header: Authorization
223225
@@ -255,7 +257,7 @@ class GoodbyeHandler < Hooks::Plugins::Handlers::Base
255257
# Ditto for the goodbye endpoint
256258
{
257259
message: "goodbye webhook processed successfully",
258-
handler: "GoodbyeHandler",
260+
handler: "goodbye_handler",
259261
timestamp: Time.now.utc.iso8601
260262
}
261263
end

docs/handler_plugins.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Handler plugins are Ruby classes that extend the `Hooks::Plugins::Handlers::Base
88

99
- `payload`: The webhook payload, which can be a Hash or a String. This is the data that the webhook sender sends to your endpoint.
1010
- `headers`: A Hash of HTTP headers that were sent with the webhook request.
11+
- `env`: A modified Rack environment that contains a lot of context about the request. This includes information about the request method, path, query parameters, and more. See [`rack_env_builder.rb`](../lib/hooks/app/rack_env_builder.rb) for the complete list of available keys.
1112
- `config`: A Hash containing the endpoint configuration. This can include any additional settings or parameters that you want to use in your handler. Most of the time, this won't be used but sometimes endpoint configs add `opts` that can be useful for the handler.
1213

1314
```ruby
@@ -28,6 +29,20 @@ class Example < Hooks::Plugins::Handlers::Base
2829
end
2930
```
3031

32+
After you write your own handler, it can be referenced in endpoint configuration files like so:
33+
34+
```yaml
35+
# example file path: config/endpoints/example.yml
36+
path: /example_webhook
37+
handler: example # this is the name of the handler plugin class
38+
```
39+
40+
It should be noted that the `handler:` key in the endpoint configuration file should match the name of the handler plugin class, but in lowercase and snake case. For example, if your handler plugin class is named `ExampleHandler`, the `handler:` key in the endpoint configuration file should be `example_handler`. Here are some more examples:
41+
42+
- `ExampleHandler` -> `example_handler`
43+
- `MyCustomHandler` -> `my_custom_handler`
44+
- `Cool2Handler` -> `cool_2_handler`
45+
3146
### `payload` Parameter
3247

3348
The `payload` parameter can be a Hash or a String. If the payload is a String, it will be parsed as JSON. If it is a Hash, it will be passed directly to the handler. The payload can contain any data that the webhook sender wants to send.

0 commit comments

Comments
 (0)