Class: LibDiscord::Webhook

Inherits:
Resource show all
Defined in:
lib/lib_discord/webhook.rb

Overview

Webhook Resource

Do not instantiate a Webhook directly. Instead request one from an instance of Client.

client = LibDiscord::Client.new("Bot auth.token")
w = client["webhook"]

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from LibDiscord::Resource

Instance Method Details

#create_webhook(channel_id:, json:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



31
32
33
# File 'lib/lib_discord/webhook.rb', line 31

def create_webhook(channel_id:, json:)
  send_request(:post, "/channels/#{channel_id}/webhooks", json:)
end

#delete_webhook(webhook_id:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



151
152
153
# File 'lib/lib_discord/webhook.rb', line 151

def delete_webhook(webhook_id:)
  send_request(:delete, "/webhooks/#{webhook_id}")
end

#delete_webhook_message(webhook_id:, webhook_token:, message_id:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



295
296
297
# File 'lib/lib_discord/webhook.rb', line 295

def delete_webhook_message(webhook_id:, webhook_token:, message_id:)
  send_request(:delete, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}")
end

#delete_webhook_with_token(webhook_id:, webhook_token:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



167
168
169
170
171
172
173
# File 'lib/lib_discord/webhook.rb', line 167

def delete_webhook_with_token(webhook_id:, webhook_token:)
  send_request(
    :delete,
    "/webhooks/#{webhook_id}/#{webhook_token}",
    http_client: client
  )
end

#edit_webhook_message(webhook_id:, webhook_token:, message_id:, json:, params: {}) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



276
277
278
# File 'lib/lib_discord/webhook.rb', line 276

def edit_webhook_message(webhook_id:, webhook_token:, message_id:, json:, params: {})
  send_request(:patch, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}", json:, params:)
end

#execute_github_compatible_webhook(webhook_id:, webhook_token:, params: {}) ⇒ Response

Parameters:

Returns:

Raises:

  • (TimeoutError)

    if the HTTP request times out

  • (ConstraintError)

    if params cannot be coerced into a valid query parameters string

See Also:



230
231
232
# File 'lib/lib_discord/webhook.rb', line 230

def execute_github_compatible_webhook(webhook_id:, webhook_token:, params: {})
  send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}/github", params:)
end

#execute_slack_compatible_webhook(webhook_id:, webhook_token:, params: {}) ⇒ Response

Parameters:

Returns:

Raises:

  • (TimeoutError)

    if the HTTP request times out

  • (ConstraintError)

    if params cannot be coerced into a valid query parameters string

See Also:



211
212
213
# File 'lib/lib_discord/webhook.rb', line 211

def execute_slack_compatible_webhook(webhook_id:, webhook_token:, params: {})
  send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}/slack", params:)
end

#execute_webhook(webhook_id:, webhook_token:, json:, params: {}) ⇒ Response

Parameters:

  • webhook_id (#to_s)
  • webhook_token (#to_s)
  • json (#to_json)

    JSON serializable payload

  • params (Hash) (defaults to: {})

    optional HTTP query parameters

Returns:

Raises:

See Also:



192
193
194
# File 'lib/lib_discord/webhook.rb', line 192

def execute_webhook(webhook_id:, webhook_token:, json:, params: {})
  send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}", json:, params:)
end

#get_channel_webhooks(channel_id:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



46
47
48
# File 'lib/lib_discord/webhook.rb', line 46

def get_channel_webhooks(channel_id:)
  send_request(:get, "/channels/#{channel_id}/webhooks")
end

#get_guild_webhooks(guild_id:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



61
62
63
# File 'lib/lib_discord/webhook.rb', line 61

def get_guild_webhooks(guild_id:)
  send_request(:get, "/guilds/#{guild_id}/webhooks")
end

#get_webhook(webhook_id:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



76
77
78
# File 'lib/lib_discord/webhook.rb', line 76

def get_webhook(webhook_id:)
  send_request(:get, "/webhooks/#{webhook_id}")
end

#get_webhook_message(webhook_id:, webhook_token:, message_id:, params: {}) ⇒ Response

Parameters:

Returns:

Raises:

  • (TimeoutError)

    if the HTTP request times out

  • (ConstraintError)

    if params cannot be coerced into a valid query parameters string

See Also:



252
253
254
# File 'lib/lib_discord/webhook.rb', line 252

def get_webhook_message(webhook_id:, webhook_token:, message_id:, params: {})
  send_request(:get, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}", params:)
end

#get_webhook_with_token(webhook_id:, webhook_token:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



92
93
94
95
96
97
98
# File 'lib/lib_discord/webhook.rb', line 92

def get_webhook_with_token(webhook_id:, webhook_token:)
  send_request(
    :get,
    "/webhooks/#{webhook_id}/#{webhook_token}",
    http_client: client
  )
end

#modify_webhook(webhook_id:, json:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



113
114
115
# File 'lib/lib_discord/webhook.rb', line 113

def modify_webhook(webhook_id:, json:)
  send_request(:patch, "/webhooks/#{webhook_id}", json:)
end

#modify_webhook_with_token(webhook_id:, webhook_token:, json:) ⇒ Response

Parameters:

Returns:

Raises:

See Also:



131
132
133
134
135
136
137
138
# File 'lib/lib_discord/webhook.rb', line 131

def modify_webhook_with_token(webhook_id:, webhook_token:, json:)
  send_request(
    :patch,
    "/webhooks/#{webhook_id}/#{webhook_token}",
    json:,
    http_client: client
  )
end