Module: Vox::HTTP::Routes::Webhook
- Defined in:
- lib/vox/http/routes/webhook.rb
Overview
Mixin for webhook routes.
Instance Method Summary collapse
-
#create_webhook(channel_id, name: :undef, avatar: :undef) ⇒ Hash<Symbol, Object>
Create a new webhook.
-
#delete_webhook(webhook_id) ⇒ nil
Delete a webhook.
-
#delete_webhook_with_token(webhook_id, webhook_token) ⇒ nil
Delete a webhook with a token.
-
#execute_webhook(webhook_id, webhook_token, wait: :undef, content: :undef, username: :undef, avatar_url: :undef, tts: :undef, file: :undef, embeds: :undef, allowed_mentions: :undef, attachments: :undef) ⇒ Object
Post content to a webhook.
-
#get_channel_webhooks(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get webhooks associated with a channel.
-
#get_guild_webhooks(guild_id) ⇒ Array<Hash<Symbol, Object>>
Get webhooks associated with a guild.
-
#get_webhook(webhook_id) ⇒ Hash<Symbol, Object>
Get a webhook by ID.
-
#get_webhook_with_token(webhook_id, webhook_token) ⇒ Hash<Symbol, Object>
Get a webhook by ID and token.
-
#modify_webhook(webhook_id, name: :undef, avatar: :undef, channel_id: :undef) ⇒ Hash<Symbol, Object>
Modify a webhook’s properties.
-
#modify_webhook_with_token(webhook_id, webhook_token, name: :undef, avatar: :undef, channel_id: :undef) ⇒ Hash<Symbol, Object>
Modify a webhook’s properties with a token.
Instance Method Details
#create_webhook(channel_id, name: :undef, avatar: :undef) ⇒ Hash<Symbol, Object>
Create a new webhook.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vox/http/routes/webhook.rb', line 21 def create_webhook(channel_id, name: :undef, avatar: :undef) avatar_data = if avatar != :undef && !avatar.nil? "data:#{avatar.content_type};base64,#{Base64.encode64(avatar.io.read)}" else :undef end json = filter_undef({ name: name, avatar: avatar_data }) route = Route.new(:POST, '/channels/%{channel_id}/webhooks', channel_id: channel_id) request(route, json: json) end |
#delete_webhook(webhook_id) ⇒ nil
Delete a webhook.
120 121 122 |
# File 'lib/vox/http/routes/webhook.rb', line 120 def delete_webhook(webhook_id) request(Route.new(:DELETE, '/webhooks/%{webhook_id}', webhook_id: webhook_id)) end |
#delete_webhook_with_token(webhook_id, webhook_token) ⇒ nil
Delete a webhook with a token. This endpoint does not require authorization.
129 130 131 132 133 |
# File 'lib/vox/http/routes/webhook.rb', line 129 def delete_webhook_with_token(webhook_id, webhook_token) route = Route.new(:DELETE, '/webhooks/%{webhook_id}/%{webhook_token}', webhook_id: webhook_id, webhook_token: webhook_token) request(route) end |
#execute_webhook(webhook_id, webhook_token, wait: :undef, content: :undef, username: :undef, avatar_url: :undef, tts: :undef, file: :undef, embeds: :undef, allowed_mentions: :undef, attachments: :undef) ⇒ Object
Post content to a webhook.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vox/http/routes/webhook.rb', line 153 def execute_webhook(webhook_id, webhook_token, wait: :undef, content: :undef, username: :undef, avatar_url: :undef, tts: :undef, file: :undef, embeds: :undef, allowed_mentions: :undef, attachments: :undef) params = filter_undef({ wait: wait }) json = filter_undef({ content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: , allowed_mentions: allowed_mentions }) route = Route.new(:POST, '/webhooks/%{webhook_id}/%{webhook_token}', webhook_id: webhook_id, webhook_token: webhook_token) if file != :undef data = { file: file, payload_json: MultiJson.dump(json) } request(route, data: data, query: params) elsif != :undef = .collect { |k, v| UploadIO.new(v.io, v.content_type, k) } if .is_a? Hash attach_hash = Array(0....size).zip().to_h data = attach_hash.merge(payload_json: MultiJson.dump(json)) request(route, data: data, query: params) else request(route, json: json, query: params) end end |
#get_channel_webhooks(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get webhooks associated with a channel.
38 39 40 |
# File 'lib/vox/http/routes/webhook.rb', line 38 def get_channel_webhooks(channel_id) request(Route.new(:GET, '/channels/%{channel_id}/webhooks', channel_id: channel_id)) end |
#get_guild_webhooks(guild_id) ⇒ Array<Hash<Symbol, Object>>
Get webhooks associated with a guild.
48 49 50 |
# File 'lib/vox/http/routes/webhook.rb', line 48 def get_guild_webhooks(guild_id) request(Route.new(:GET, '/guilds/%{guild_id}/webhooks', guild_id: guild_id)) end |
#get_webhook(webhook_id) ⇒ Hash<Symbol, Object>
Get a webhook by ID.
58 59 60 |
# File 'lib/vox/http/routes/webhook.rb', line 58 def get_webhook(webhook_id) request(Route.new(:GET, '/webhooks/%{webhook_id}', webhook_id: webhook_id)) end |
#get_webhook_with_token(webhook_id, webhook_token) ⇒ Hash<Symbol, Object>
Get a webhook by ID and token. This does not require authentication.
68 69 70 71 72 |
# File 'lib/vox/http/routes/webhook.rb', line 68 def get_webhook_with_token(webhook_id, webhook_token) route = Route.new(:GET, '/webhooks/%{webhook_id}/%{webhook_token}', webhook_id: webhook_id, webhook_token: webhook_token) request(route) end |
#modify_webhook(webhook_id, name: :undef, avatar: :undef, channel_id: :undef) ⇒ Hash<Symbol, Object>
Modify a webhook’s properties.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vox/http/routes/webhook.rb', line 83 def modify_webhook(webhook_id, name: :undef, avatar: :undef, channel_id: :undef) avatar_data = if avatar != :undef && !avatar.nil? "data:#{avatar.content_type};base64,#{Base64.encode64(avatar.io.read)}" else :undef end json = filter_undef({ name: name, avatar: avatar_data, channel_id: channel_id }) route = Route.new(:PATCH, '/webhooks/%{webhook_id}', webhook_id: webhook_id) request(route, json: json) end |
#modify_webhook_with_token(webhook_id, webhook_token, name: :undef, avatar: :undef, channel_id: :undef) ⇒ Hash<Symbol, Object>
Modify a webhook’s properties with a token. This endpoint does not require authorization.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vox/http/routes/webhook.rb', line 103 def modify_webhook_with_token(webhook_id, webhook_token, name: :undef, avatar: :undef, channel_id: :undef) avatar_data = if avatar != :undef && !avatar.nil? "data:#{avatar.content_type};base64,#{Base64.encode64(avatar.io.read)}" else :undef end json = filter_undef({ name: name, avatar: avatar_data, channel_id: channel_id }) route = Route.new(:PATCH, '/webhooks/%{webhook_id}/%{webhook_token}', webhook_id: webhook_id, webhook_token: webhook_token) request(route, json: json) end |