Class: Strava::Webhooks::Client

Inherits:
Strava::Web::Client show all
Defined in:
lib/strava/webhooks/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Strava::Web::Client

#endpoint, #parse_args

Methods included from Strava::Web::Request

#delete, #get, #post, #put

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/strava/webhooks/client.rb', line 6

def initialize(options = {})
  Strava::Webhooks::Config::ATTRIBUTES.each do |key|
    send("#{key}=", options[key] || Strava::Webhooks.config.send(key))
  end
  super
end

Class Method Details

.configObject



52
53
54
# File 'lib/strava/webhooks/client.rb', line 52

def config
  Config
end

.configureObject



48
49
50
# File 'lib/strava/webhooks/client.rb', line 48

def configure
  block_given? ? yield(Config) : Config
end

Instance Method Details

#create_push_subscription(options = {}) ⇒ Object

Create a subscription.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :callback_url (String)

    Address where webhook events will be sent.

  • :verify_token (String)

    String chosen by the application owner for client security. An identical string should be returned by Strava’s subscription service.



43
44
45
# File 'lib/strava/webhooks/client.rb', line 43

def create_push_subscription(options = {})
  Strava::Webhooks::Models::Subscription.new(post('push_subscriptions', options))
end

#delete_push_subscription(id_or_options, options = {}) ⇒ Object

Delete an existing push subscription.



29
30
31
32
33
# File 'lib/strava/webhooks/client.rb', line 29

def delete_push_subscription(id_or_options, options = {})
  id, options = parse_args(id_or_options, options)
  delete("push_subscriptions/#{id}", options)
  nil
end

#push_subscriptions(options = {}) ⇒ Object

Get existing push subscriptions.



20
21
22
23
24
# File 'lib/strava/webhooks/client.rb', line 20

def push_subscriptions(options = {})
  get('push_subscriptions', options).map do |row|
    Strava::Webhooks::Models::Subscription.new(row)
  end
end

#request(method, path, options) ⇒ Object



13
14
15
# File 'lib/strava/webhooks/client.rb', line 13

def request(method, path, options)
  super method, path, { client_id: client_id, client_secret: client_secret }.merge(options)
end