Class: Strava::Webhooks::Client
- Inherits:
-
Strava::Web::Client
- Object
- Strava::Web::Client
- Strava::Webhooks::Client
- Defined in:
- lib/strava/webhooks/client.rb
Overview
Webhooks client for Strava push subscriptions.
Strava provides webhooks for receiving real-time updates about athlete activities and other events. This client manages webhook subscriptions (create, list, delete).
Before creating a subscription, you must implement an HTTP endpoint that:
- Handles GET requests for subscription validation (Challenge)
- Handles POST requests for webhook events (Event)
Class Method Summary collapse
-
.config ⇒ Module
Returns the current Webhooks client configuration.
-
.configure {|Config| ... } ⇒ Module
Configure the Webhooks client with a block.
Instance Method Summary collapse
-
#create_push_subscription(options = {}) ⇒ Strava::Webhooks::Models::Subscription
Create a new push subscription.
-
#delete_push_subscription(id_or_options, options = {}) ⇒ nil
Delete a push subscription.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new Webhooks client.
-
#push_subscriptions(options = {}) ⇒ Array<Strava::Webhooks::Models::Subscription>
List existing push subscriptions.
- #request(method, path, options) ⇒ Object
Constructor Details
Class Method Details
.config ⇒ Module
Returns the current Webhooks client configuration.
155 156 157 |
# File 'lib/strava/webhooks/client.rb', line 155 def config Config end |
Instance Method Details
#create_push_subscription(options = {}) ⇒ Strava::Webhooks::Models::Subscription
Create a new push subscription.
Creates a webhook subscription for receiving real-time activity updates. Your callback URL must be publicly accessible and handle both GET (for validation) and POST (for events) requests.
Strava will send a GET request to validate your callback URL before creating the subscription. Your endpoint must respond with the challenge token.
129 130 131 |
# File 'lib/strava/webhooks/client.rb', line 129 def create_push_subscription( = {}) Strava::Webhooks::Models::Subscription.new(post('push_subscriptions', )) end |
#delete_push_subscription(id_or_options, options = {}) ⇒ nil
Delete a push subscription.
Removes an existing webhook subscription by ID. After deletion, your application will no longer receive webhook events.
97 98 99 100 101 |
# File 'lib/strava/webhooks/client.rb', line 97 def delete_push_subscription(, = {}) id, = parse_args(, ) delete("push_subscriptions/#{id}", ) nil end |
#push_subscriptions(options = {}) ⇒ Array<Strava::Webhooks::Models::Subscription>
List existing push subscriptions.
Returns all active webhook subscriptions for your application. Typically, Strava only allows one subscription per application.
75 76 77 78 79 |
# File 'lib/strava/webhooks/client.rb', line 75 def push_subscriptions( = {}) get('push_subscriptions', ).map do |row| Strava::Webhooks::Models::Subscription.new(row) end end |
#request(method, path, options) ⇒ Object
55 56 57 |
# File 'lib/strava/webhooks/client.rb', line 55 def request(method, path, ) super(method, path, { client_id: client_id, client_secret: client_secret }.merge()) end |