Module: Rubycord::API::Webhook

Defined in:
lib/rubycord/api/webhook.rb

Overview

API calls for Webhook object

Class Method Summary collapse

Class Method Details

.delete_webhook(token, webhook_id, reason = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/rubycord/api/webhook.rb', line 81

def delete_webhook(token, webhook_id, reason = nil)
  Rubycord::API.request(
    :webhooks_wid,
    webhook_id,
    :delete,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}",
    Authorization: token,
    "X-Audit-Log-Reason": reason
  )
end

.token_delete_message(webhook_token, webhook_id, message_id) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/rubycord/api/webhook.rb', line 130

def token_delete_message(webhook_token, webhook_id, message_id)
  Rubycord::API.request(
    :webhooks_wid_messages,
    webhook_id,
    :delete,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}"
  )
end

.token_delete_webhook(webhook_token, webhook_id, reason = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/rubycord/api/webhook.rb', line 94

def token_delete_webhook(webhook_token, webhook_id, reason = nil)
  Rubycord::API.request(
    :webhooks_wid,
    webhook_id,
    :delete,
    "#{Rubycord::API.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) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'lib/rubycord/api/webhook.rb', line 117

def token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil)
  Rubycord::API.request(
    :webhooks_wid_messages,
    webhook_id,
    :patch,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}",
    {content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components}.to_json,
    content_type: :json
  )
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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubycord/api/webhook.rb', line 30

def 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)
  body = {content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds&.map(&:to_hash), allowed_mentions: allowed_mentions, flags: flags, components: components}
  body = if file
    {file: file, payload_json: body.to_json}
  else
    body.to_json
  end

  headers = {content_type: :json} unless file

  Rubycord::API.request(
    :webhooks_wid,
    webhook_id,
    :post,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}?wait=#{wait}",
    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



106
107
108
109
110
111
112
113
# File 'lib/rubycord/api/webhook.rb', line 106

def token_get_message(webhook_token, webhook_id, message_id)
  Rubycord::API.request(
    :webhooks_wid_messages_mid,
    webhook_id,
    :get,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}"
  )
end

.token_update_webhook(webhook_token, webhook_id, data, reason = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rubycord/api/webhook.rb', line 67

def token_update_webhook(webhook_token, webhook_id, data, reason = nil)
  Rubycord::API.request(
    :webhooks_wid,
    webhook_id,
    :patch,
    "#{Rubycord::API.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



19
20
21
22
23
24
25
26
# File 'lib/rubycord/api/webhook.rb', line 19

def token_webhook(webhook_token, webhook_id)
  Rubycord::API.request(
    :webhooks_wid,
    nil,
    :get,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}"
  )
end

.update_webhook(token, webhook_id, data, reason = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubycord/api/webhook.rb', line 52

def update_webhook(token, webhook_id, data, reason = nil)
  Rubycord::API.request(
    :webhooks_wid,
    webhook_id,
    :patch,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}",
    data.to_json,
    Authorization: token,
    content_type: :json,
    "X-Audit-Log-Reason": reason
  )
end

.webhook(token, webhook_id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rubycord/api/webhook.rb', line 7

def webhook(token, webhook_id)
  Rubycord::API.request(
    :webhooks_wid,
    nil,
    :get,
    "#{Rubycord::API.api_base}/webhooks/#{webhook_id}",
    Authorization: token
  )
end