Class: MaxBotApi::Resources::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/max_bot_api/resources/subscriptions.rb

Overview

Webhook subscription methods.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Subscriptions

Returns a new instance of Subscriptions.



7
8
9
# File 'lib/max_bot_api/resources/subscriptions.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#get_subscriptionsObject

List active subscriptions.



12
13
14
# File 'lib/max_bot_api/resources/subscriptions.rb', line 12

def get_subscriptions
  @client.request(:get, 'subscriptions')
end

#subscribe(url:, update_types: [], secret: nil) ⇒ Object

Create a webhook subscription.

Parameters:

  • url (String)
  • update_types (Array<String>) (defaults to: [])
  • secret (String, nil) (defaults to: nil)


20
21
22
23
24
25
26
27
28
29
# File 'lib/max_bot_api/resources/subscriptions.rb', line 20

def subscribe(url:, update_types: [], secret: nil)
  body = {
    url: url,
    update_types: update_types,
    secret: secret,
    version: @client.version
  }.compact

  @client.request(:post, 'subscriptions', body: body)
end

#unsubscribe(url:) ⇒ Object

Remove a webhook subscription.

Parameters:

  • url (String)


33
34
35
# File 'lib/max_bot_api/resources/subscriptions.rb', line 33

def unsubscribe(url:)
  @client.request(:delete, 'subscriptions', query: { 'url' => url })
end