Module: OnyxCord::REST::Webhook
- Defined in:
- lib/onyxcord/rest/routes/webhook.rb
Overview
API calls for Webhook object
Class Method Summary collapse
-
.attachment_payload(attachments) ⇒ Object
Build attachment metadata payload for multipart uploads.
-
.delete_webhook(token, webhook_id, reason = nil) ⇒ Object
Deletes a webhook https://discord.com/developers/docs/resources/webhook#delete-webhook.
-
.multipart_body(body, attachments) ⇒ Object
Build multipart body with named file fields and JSON payload.
-
.token_delete_message(webhook_token, webhook_id, message_id) ⇒ Object
Delete a webhook message via webhook token.
-
.token_delete_webhook(webhook_token, webhook_id, reason = nil) ⇒ Object
Deletes a webhook via webhook token https://discord.com/developers/docs/resources/webhook#delete-webhook-with-token.
-
.token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil) ⇒ Object
Edit a webhook message via webhook token https://discord.com/developers/docs/resources/webhook#edit-webhook-message.
-
.token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, poll = nil) ⇒ Object
Execute a webhook via token.
-
.token_get_message(webhook_token, webhook_id, message_id) ⇒ Object
Get a message that was created by the webhook corresponding to the provided token.
-
.token_update_webhook(webhook_token, webhook_id, data, reason = nil) ⇒ Object
Update a webhook via webhook token https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token.
-
.token_webhook(webhook_token, webhook_id) ⇒ Object
Get a webhook via webhook token https://discord.com/developers/docs/resources/webhook#get-webhook-with-token.
-
.update_webhook(token, webhook_id, data, reason = nil) ⇒ Object
Update a webhook https://discord.com/developers/docs/resources/webhook#modify-webhook.
- .webhook(token, webhook_id) ⇒ Object
Class Method Details
.attachment_payload(attachments) ⇒ Object
Build attachment metadata payload for multipart uploads. Returns an array of { id:, filename: } hashes.
11 12 13 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 11 def () OnyxCord::MessagePayload.() end |
.delete_webhook(token, webhook_id, reason = nil) ⇒ Object
Deletes a webhook https://discord.com/developers/docs/resources/webhook#delete-webhook
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 106 def delete_webhook(token, webhook_id, reason = nil) OnyxCord::REST.request( :webhooks_wid, webhook_id, :delete, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}", Authorization: token, 'X-Audit-Log-Reason': reason ) end |
.multipart_body(body, attachments) ⇒ Object
Build multipart body with named file fields and JSON payload.
16 17 18 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 16 def multipart_body(body, ) OnyxCord::MessagePayload.multipart_body(body, ) end |
.token_delete_message(webhook_token, webhook_id, message_id) ⇒ Object
Delete a webhook message via webhook token. https://discord.com/developers/docs/resources/webhook#delete-webhook-message
168 169 170 171 172 173 174 175 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 168 def (webhook_token, webhook_id, ) OnyxCord::REST.request( :webhooks_wid_messages, webhook_id, :delete, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{}" ) end |
.token_delete_webhook(webhook_token, webhook_id, reason = nil) ⇒ Object
Deletes a webhook via webhook token https://discord.com/developers/docs/resources/webhook#delete-webhook-with-token
119 120 121 122 123 124 125 126 127 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 119 def token_delete_webhook(webhook_token, webhook_id, reason = nil) OnyxCord::REST.request( :webhooks_wid, webhook_id, :delete, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}", 'X-Audit-Log-Reason': reason ) end |
.token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil) ⇒ Object
Edit a webhook message via webhook token https://discord.com/developers/docs/resources/webhook#edit-webhook-message
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 142 def (webhook_token, webhook_id, , content = nil, = nil, allowed_mentions = nil, components = nil, = nil, flags = nil, poll = nil) components = OnyxCord::MessageComponents.payload(components) unless components.nil? flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components) OnyxCord::MessagePayload.validate!(content: content, embeds: , components: components, flags: flags, attachments: , poll: poll) body = OnyxCord::MessagePayload.edit_body(content, ).merge({ allowed_mentions: allowed_mentions, components: components, attachments: ? () : nil, flags: flags, poll: poll }.compact) body = if multipart_body(body, ) else body.to_json end headers = { content_type: :json } unless OnyxCord::REST.request( :webhooks_wid_messages, webhook_id, :patch, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{}", body, headers ) end |
.token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, poll = nil) ⇒ Object
Execute a webhook via token. https://discord.com/developers/docs/resources/webhook#execute-webhook
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 45 def token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, = nil, allowed_mentions = nil, flags = nil, components = nil, = nil, poll = nil) raise ArgumentError, 'cannot mix file and attachments' if file && components = OnyxCord::MessageComponents.payload(components) unless components.nil? flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components) OnyxCord::MessagePayload.validate!(content: content, embeds: , components: components, flags: flags, attachments: , poll: poll) body = { content: content, username: username, avatar_url: avatar_url, tts: tts == true ? true : nil, embeds: &.map(&:to_hash), allowed_mentions: allowed_mentions, flags: flags, components: components&.any? ? components : nil, attachments: ? () : nil, poll: poll }.compact body = if file { file: file, payload_json: body.to_json } elsif multipart_body(body, ) else body.to_json end headers = { content_type: :json } unless file || with_components = components&.any? || nil query = URI.encode_www_form({ wait: wait, with_components: with_components }.compact) OnyxCord::REST.request( :webhooks_wid, webhook_id, :post, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}?#{query}", body, headers ) end |
.token_get_message(webhook_token, webhook_id, message_id) ⇒ Object
Get a message that was created by the webhook corresponding to the provided token. https://discord.com/developers/docs/resources/webhook#get-webhook-message
131 132 133 134 135 136 137 138 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 131 def (webhook_token, webhook_id, ) OnyxCord::REST.request( :webhooks_wid_messages_mid, webhook_id, :get, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{}" ) end |
.token_update_webhook(webhook_token, webhook_id, data, reason = nil) ⇒ Object
Update a webhook via webhook token https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 92 def token_update_webhook(webhook_token, webhook_id, data, reason = nil) OnyxCord::REST.request( :webhooks_wid, webhook_id, :patch, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}", data.to_json, content_type: :json, 'X-Audit-Log-Reason': reason ) end |
.token_webhook(webhook_token, webhook_id) ⇒ Object
Get a webhook via webhook token https://discord.com/developers/docs/resources/webhook#get-webhook-with-token
34 35 36 37 38 39 40 41 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 34 def token_webhook(webhook_token, webhook_id) OnyxCord::REST.request( :webhooks_wid, nil, :get, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}/#{webhook_token}" ) end |
.update_webhook(token, webhook_id, data, reason = nil) ⇒ Object
Update a webhook https://discord.com/developers/docs/resources/webhook#modify-webhook
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/onyxcord/rest/routes/webhook.rb', line 77 def update_webhook(token, webhook_id, data, reason = nil) OnyxCord::REST.request( :webhooks_wid, webhook_id, :patch, "#{OnyxCord::REST.api_base}/webhooks/#{webhook_id}", data.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end |