Class: Twitch::EventsubSubscriptionsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/twitch/resources/eventsub_subscriptions.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twitch::Resource

Instance Method Details

#create(type:, version:, condition:, transport:, **params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitch/resources/eventsub_subscriptions.rb', line 8

def create(type:, version:, condition:, transport:, **params)
  attributes = { type: type, version: version, condition: condition, transport: transport }.merge(params)
  response = client.connection.post("eventsub/subscriptions", attributes)
  update_rate_limit(response)

  if response.status == 409
    raise Twitch::Errors::EventsubSubscriptionConflictError.new(
      response.body,
      response.status,
      existing_subscription_id: response.body.dig("data", 0, "id")
    )
  end

  return raise_error(response) if error?(response)

  EventsubSubscription.new(response.body.dig("data")[0]) if response.success?
end

#delete(id:) ⇒ Object



26
27
28
# File 'lib/twitch/resources/eventsub_subscriptions.rb', line 26

def delete(id:)
  delete_request("eventsub/subscriptions", params: { id: id })
end

#list(**params) ⇒ Object



3
4
5
6
# File 'lib/twitch/resources/eventsub_subscriptions.rb', line 3

def list(**params)
  response = get_request("eventsub/subscriptions", params: params)
  Collection.from_response(response, type: EventsubSubscription)
end