Class: WhopSDK::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/resources/webhooks.rb

Overview

Webhooks

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Webhooks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Webhooks.

Parameters:



188
189
190
# File 'lib/whop_sdk/resources/webhooks.rb', line 188

def initialize(client:)
  @client = client
end

Instance Method Details

#create(url:, api_version: nil, child_resource_events: nil, enabled: nil, events: nil, resource_id: nil, request_options: {}) ⇒ WhopSDK::Models::WebhookCreateResponse

Some parameter documentations has been truncated, see Models::WebhookCreateParams for more details.

Creates a new webhook

Required permissions:

  • ‘developer:manage_webhook`

Parameters:

  • url (String)

    The URL to send the webhook to.

  • api_version (Symbol, WhopSDK::Models::APIVersion, nil)

    The different API versions

  • child_resource_events (Boolean, nil)

    Whether or not to send events for child resources. For example, if the webhook i

  • enabled (Boolean, nil)

    Whether or not the webhook is enabled.

  • events (Array<Symbol, WhopSDK::Models::WebhookEvent>, nil)

    The events to send the webhook for.

  • resource_id (String, nil)

    The resource to create the webhook for. By default this will use current company

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



35
36
37
38
39
40
41
42
43
44
# File 'lib/whop_sdk/resources/webhooks.rb', line 35

def create(params)
  parsed, options = WhopSDK::WebhookCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "webhooks",
    body: parsed,
    model: WhopSDK::Models::WebhookCreateResponse,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ Boolean

Deletes a webhook

Required permissions:

  • ‘developer:manage_webhook`

Parameters:

  • id (String)

    The ID of the webhook to delete.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (Boolean)

See Also:



158
159
160
161
162
163
164
165
# File 'lib/whop_sdk/resources/webhooks.rb', line 158

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["webhooks/%1$s", id],
    model: WhopSDK::Internal::Type::Boolean,
    options: params[:request_options]
  )
end

#list(company_id:, after: nil, before: nil, first: nil, last: nil, request_options: {}) ⇒ WhopSDK::Internal::CursorPage<WhopSDK::Models::WebhookListResponse>

Returns a paginated list of webhook endpoints configured for a company, ordered by most recently created.

Required permissions:

  • ‘developer:manage_webhook`

Parameters:

  • company_id (String)

    The unique identifier of the company to list webhooks for.

  • after (String, nil)

    Returns the elements in the list that come after the specified cursor.

  • before (String, nil)

    Returns the elements in the list that come before the specified cursor.

  • first (Integer, nil)

    Returns the first n elements from the list.

  • last (Integer, nil)

    Returns the last n elements from the list.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/whop_sdk/resources/webhooks.rb', line 130

def list(params)
  parsed, options = WhopSDK::WebhookListParams.dump_request(params)
  query = WhopSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "webhooks",
    query: query,
    page: WhopSDK::Internal::CursorPage,
    model: WhopSDK::Models::WebhookListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ WhopSDK::Models::Webhook

Retrieves the details of an existing webhook.

Required permissions:

  • ‘developer:manage_webhook`

Parameters:

  • id (String)

    The unique identifier of the webhook to retrieve.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



61
62
63
64
65
66
67
68
# File 'lib/whop_sdk/resources/webhooks.rb', line 61

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["webhooks/%1$s", id],
    model: WhopSDK::Webhook,
    options: params[:request_options]
  )
end

#unwrap(payload, headers:, key: @client.webhook_key) ⇒ WhopSDK::Models::InvoiceCreatedWebhookEvent, ...

Parameters:

  • payload (String)

    The raw webhook payload as a string

  • headers (Hash{String=>String})

    The raw HTTP headers that came with the payload

  • key (String, nil) (defaults to: @client.webhook_key)

    The webhook signing key

Returns:



174
175
176
177
178
179
180
181
182
183
# File 'lib/whop_sdk/resources/webhooks.rb', line 174

def unwrap(payload, headers:, key: @client.webhook_key)
  if key.nil?
    raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_key or passed in as an argument")
  end

  ::StandardWebhooks::Webhook.new(key).verify(payload, headers)

  parsed = JSON.parse(payload, symbolize_names: true)
  WhopSDK::Internal::Type::Converter.coerce(WhopSDK::Models::UnwrapWebhookEvent, parsed)
end

#update(id, api_version: nil, child_resource_events: nil, enabled: nil, events: nil, url: nil, request_options: {}) ⇒ WhopSDK::Models::Webhook

Updates a webhook

Required permissions:

  • ‘developer:manage_webhook`

Parameters:

  • id (String)

    The ID of the Webhook to update

  • api_version (Symbol, WhopSDK::Models::APIVersion, nil)

    The different API versions

  • child_resource_events (Boolean, nil)

    Whether or not to send events for child resources.

  • enabled (Boolean, nil)

    Whether or not the webhook is enabled.

  • events (Array<Symbol, WhopSDK::Models::WebhookEvent>, nil)

    The events to send the webhook for.

  • url (String, nil)

    The URL to send the webhook to.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



95
96
97
98
99
100
101
102
103
104
# File 'lib/whop_sdk/resources/webhooks.rb', line 95

def update(id, params = {})
  parsed, options = WhopSDK::WebhookUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["webhooks/%1$s", id],
    body: parsed,
    model: WhopSDK::Webhook,
    options: options
  )
end