Sha256: 910176a676a4188e5084f1c5283f3666a9cba0b1c14efc30c6e7ee04e9a9a9da

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

module Strava
  module Webhooks
    class Client < Strava::Web::Client
      attr_accessor(*Config::ATTRIBUTES)

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

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

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

      #
      # Delete an existing push subscription.
      #
      def delete_push_subscription(id_or_options, options = {})
        id, options = parse_args(id_or_options, options)
        delete("push_subscriptions/#{id}", options)
        nil
      end

      #
      # Create a subscription.
      #
      # @option options [String] :callback_url
      #   Address where webhook events will be sent.
      # @option options [String] :verify_token
      #   String chosen by the application owner for client security. An identical string should be returned by Strava's subscription service.
      #
      def create_push_subscription(options = {})
        Strava::Webhooks::Models::Subscription.new(post('push_subscriptions', options))
      end

      class << self
        def configure
          block_given? ? yield(Config) : Config
        end

        def config
          Config
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strava-ruby-client-0.4.2 lib/strava/webhooks/client.rb
strava-ruby-client-0.4.1 lib/strava/webhooks/client.rb
strava-ruby-client-0.4.0 lib/strava/webhooks/client.rb
strava-ruby-client-0.3.2 lib/strava/webhooks/client.rb
strava-ruby-client-0.3.1 lib/strava/webhooks/client.rb
strava-ruby-client-0.3.0 lib/strava/webhooks/client.rb