Skip to content

Commit 5c78e9c

Browse files
committed
Updates README with Webhooks docs
1 parent ba2ae9b commit 5c78e9c

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

README.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Or install it yourself as:
2828
## Usage
2929

3030
### Resources
31-
All client methods return `Resource` objects or a collection of `Resource` objects. Every attribute from a resource can be accessed by calling attribute methods:
31+
All client methods return `Resource` objects or a collection of `Resource` objects. Every attribute from a resource can be accessed by calling attribute methods:
3232

3333
```ruby
3434
conversation = platform.conversations.find("fb2f3a48-523d-4449-a57f-c6651fc6612c")
@@ -46,8 +46,8 @@ conversation.attributes
4646
# => {"id" => "fb2f3a48-523d-4449-a57f-c6651fc6612c", "url" => "https://api.layer.com/apps/<APP_ID>/conversations/fb2f3a48-523d-4449-a57f-c6651fc6612c", ...}
4747
```
4848

49-
### [Platform API](https://developer.layer.com/docs/platform)
50-
See the official [Platform API docs](https://developer.layer.com/docs/platform) for additional info.
49+
### [Platform](https://developer.layer.com/docs/platform)
50+
See the [Platform API docs](https://developer.layer.com/docs/platform) for additional info.
5151

5252
#### Authentication/setup
5353

@@ -280,12 +280,76 @@ Make sure the following environment variables are set:
280280
```ruby
281281
# Returns a valid signed identity token. #
282282
token = platform.generate_identity_token(user_id: "1234", nonce: "your_random_nonce")
283-
# => #<Layer::IdentityToken:0x007f89b4adb890
283+
# => #<Layer::IdentityToken:0x007f89b4adb890>
284284

285285
token.to_s
286286
# => "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsInR.cCI6IkpXVCIsImN0eSI6ImxheWVyLWVpdDt2PTEiLCJraWQiOiJhNz.5YTE0MC02YzY3LTExZTUtYjM0Mi1jZGJmNDAwZTE5NDgifQ"
287287
```
288288

289+
### [Webhooks](https://developer.layer.com/docs/webhooks)
290+
See the [Webhooks API docs](https://developer.layer.com/docs/webhooks) for additional info.
291+
292+
#### Authentication/setup
293+
294+
```ruby
295+
client = Layer::Webhooks::Client.new(api_token: "your_api_token", app_id: "your_app_id")
296+
# => #<Layer::Webhooks::Client @api_token="...", @app_id="...">
297+
```
298+
If you have `ENV['LAYER_API_TOKEN']` and `ENV['LAYER_APP_ID']` environment variables setup, they will be used by default and don't need to be included:
299+
```ruby
300+
client = Layer::Webhooks::Client.new
301+
# => #<Layer::Webhooks::Client @api_token="...", @app_id="...">
302+
```
303+
304+
#### Registering Webhooks
305+
306+
```ruby
307+
client.webhooks.create(
308+
version: "1.0",
309+
target_url: "https://mydomain.com/my-webhook-endpoint",
310+
events: ["conversation.created", "message.sent"],
311+
secret: "1697f925ec7b1697f925ec7b",
312+
config: {:key1=>"value1", :key2=>"value2"}
313+
)
314+
# => #<Layer::Resources::Webhook @attributes={...}>
315+
```
316+
317+
#### Listing Webhooks
318+
319+
```ruby
320+
client.webhooks.list
321+
# => [#<Layer::Resources::Webhook>, #<Layer::Resources::Webhook>, ...]
322+
```
323+
324+
#### Retrieving Webhooks
325+
326+
```ruby
327+
client.webhooks.find("webhook_id")
328+
# => #<Layer::Resources::Webhook @attributes={...}>
329+
```
330+
331+
#### Activating Webhooks
332+
333+
```ruby
334+
webhook = client.webhooks.find("webhook_id")
335+
webhook.activate
336+
```
337+
338+
#### Deactivating Webhooks
339+
340+
```ruby
341+
webhook = client.webhooks.find("webhook_id")
342+
webhook.deactivate
343+
```
344+
345+
#### Deleting Webhooks
346+
347+
```ruby
348+
webhook = client.webhooks.find("webhook_id")
349+
webhook.destroy
350+
```
351+
352+
289353
## Development ##
290354

291355
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

0 commit comments

Comments
 (0)