Class: ModerationAPI::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/moderation_api/resources/webhooks.rb,
sig/moderation_api/resources/webhooks.rbs

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:



134
135
136
# File 'lib/moderation_api/resources/webhooks.rb', line 134

def initialize(client:)
  @client = client
end

Instance Method Details

#create(event_types:, name:, url:, description: nil, request_options: {}) ⇒ ModerationAPI::Models::WebhookCreateResponse

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

Create a webhook subscribed to one or more event types. Deliveries use the v2 envelope and are signed with the project signing secret (see the signing secret endpoint).

Parameters:

  • event_types (Array<Symbol, ModerationAPI::Models::WebhookCreateParams::EventType>)

    Event types this webhook subscribes to. One webhook URL receives all events you

  • name (String)

    The webhook's name, used to identify it in the dashboard

  • url (String)

    The webhook's URL. We'll call this URL when an event occurs.

  • description (String, nil)

    The webhook's description

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

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
# File 'lib/moderation_api/resources/webhooks.rb', line 28

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

#delete(id, request_options: {}) ⇒ ModerationAPI::Models::WebhookDeleteResponse

Delete a webhook.

Parameters:

Returns:

See Also:



122
123
124
125
126
127
128
129
# File 'lib/moderation_api/resources/webhooks.rb', line 122

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

#list(request_options: {}) ⇒ Array<ModerationAPI::Models::WebhookListResponseItem>

List all webhooks for the authenticated project.

Parameters:

Returns:

See Also:



102
103
104
105
106
107
108
109
# File 'lib/moderation_api/resources/webhooks.rb', line 102

def list(params = {})
  @client.request(
    method: :get,
    path: "webhooks",
    model: ModerationAPI::Internal::Type::ArrayOf[ModerationAPI::Models::WebhookListResponseItem],
    options: params[:request_options]
  )
end

#retrieve(id, request_options: {}) ⇒ ModerationAPI::Models::WebhookRetrieveResponse

Get a webhook by ID.

Parameters:

Returns:

See Also:



50
51
52
53
54
55
56
57
# File 'lib/moderation_api/resources/webhooks.rb', line 50

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

#update(id, description: nil, event_types: nil, name: nil, url: nil, request_options: {}) ⇒ ModerationAPI::Models::WebhookUpdateResponse

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

Update a webhook. Legacy v1 webhooks are read-only: delete them and create a new webhook instead.

Parameters:

  • id (String)

    The ID of the webhook to update.

  • description (String, nil)

    The webhook's description

  • event_types (Array<Symbol, ModerationAPI::Models::WebhookUpdateParams::EventType>)

    Event types this webhook subscribes to. One webhook URL receives all events you

  • name (String)

    The webhook's name, used to identify it in the dashboard

  • url (String)

    The webhook's URL. We'll call this URL when an event occurs.

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

Returns:

See Also:



82
83
84
85
86
87
88
89
90
91
# File 'lib/moderation_api/resources/webhooks.rb', line 82

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