Class: ChatSDK::Discord::ApiClient
- Inherits:
-
ApiClient::Base
- Object
- ApiClient::Base
- ChatSDK::Discord::ApiClient
- Defined in:
- lib/chat_sdk/discord/api_client.rb
Constant Summary collapse
- BASE_URL =
"https://discord.com"- API_PREFIX =
"/api/v10"
Instance Method Summary collapse
-
#add_reaction(channel_id, message_id, emoji) ⇒ Object
Reactions.
-
#create_dm(user_id) ⇒ Object
DMs.
-
#create_message(channel_id, content: nil, embeds: nil, components: nil) ⇒ Object
Messages.
- #delete_message(channel_id, message_id) ⇒ Object
- #edit_message(channel_id, message_id, content: nil, embeds: nil, components: nil) ⇒ Object
-
#get_messages(channel_id, limit: 50, before: nil) ⇒ Object
Messages history.
-
#initialize(bot_token:) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #remove_reaction(channel_id, message_id, emoji) ⇒ Object
-
#upload_file(channel_id, io, filename) ⇒ Object
File upload.
Constructor Details
#initialize(bot_token:) ⇒ ApiClient
Returns a new instance of ApiClient.
11 12 13 |
# File 'lib/chat_sdk/discord/api_client.rb', line 11 def initialize(bot_token:) @bot_token = bot_token end |
Instance Method Details
#add_reaction(channel_id, message_id, emoji) ⇒ Object
Reactions
37 38 39 40 |
# File 'lib/chat_sdk/discord/api_client.rb', line 37 def add_reaction(channel_id, , emoji) encoded = ERB::Util.url_encode(emoji) request(:put, "#{API_PREFIX}/channels/#{channel_id}/messages/#{}/reactions/#{encoded}/@me") end |
#create_dm(user_id) ⇒ Object
DMs
48 49 50 |
# File 'lib/chat_sdk/discord/api_client.rb', line 48 def create_dm(user_id) request(:post, "#{API_PREFIX}/users/@me/channels", {"recipient_id" => user_id}) end |
#create_message(channel_id, content: nil, embeds: nil, components: nil) ⇒ Object
Messages
16 17 18 19 20 21 22 |
# File 'lib/chat_sdk/discord/api_client.rb', line 16 def (channel_id, content: nil, embeds: nil, components: nil) body = {} body["content"] = content if content body["embeds"] = if body["components"] = components if components request(:post, "#{API_PREFIX}/channels/#{channel_id}/messages", body) end |
#delete_message(channel_id, message_id) ⇒ Object
32 33 34 |
# File 'lib/chat_sdk/discord/api_client.rb', line 32 def (channel_id, ) request(:delete, "#{API_PREFIX}/channels/#{channel_id}/messages/#{}") end |
#edit_message(channel_id, message_id, content: nil, embeds: nil, components: nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/chat_sdk/discord/api_client.rb', line 24 def (channel_id, , content: nil, embeds: nil, components: nil) body = {} body["content"] = content if content body["embeds"] = if body["components"] = components if components request(:patch, "#{API_PREFIX}/channels/#{channel_id}/messages/#{}", body) end |
#get_messages(channel_id, limit: 50, before: nil) ⇒ Object
Messages history
53 54 55 56 57 |
# File 'lib/chat_sdk/discord/api_client.rb', line 53 def (channel_id, limit: 50, before: nil) path = "#{API_PREFIX}/channels/#{channel_id}/messages?limit=#{limit}" path += "&before=#{before}" if before request(:get, path) end |
#remove_reaction(channel_id, message_id, emoji) ⇒ Object
42 43 44 45 |
# File 'lib/chat_sdk/discord/api_client.rb', line 42 def remove_reaction(channel_id, , emoji) encoded = ERB::Util.url_encode(emoji) request(:delete, "#{API_PREFIX}/channels/#{channel_id}/messages/#{}/reactions/#{encoded}/@me") end |
#upload_file(channel_id, io, filename) ⇒ Object
File upload
60 61 62 63 64 65 66 67 |
# File 'lib/chat_sdk/discord/api_client.rb', line 60 def upload_file(channel_id, io, filename) payload = { "file[0]" => Faraday::Multipart::FilePart.new(io, "application/octet-stream", filename) } response = upload_connection.post("#{API_PREFIX}/channels/#{channel_id}/messages", payload) handle_response(response) end |