discord_api 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -1
- data/Rakefile +1 -1
- data/lib/discord/client.rb +8 -0
- data/lib/discord/collection.rb +4 -4
- data/lib/discord/objects/channel.rb +4 -0
- data/lib/discord/objects/guild.rb +4 -0
- data/lib/discord/objects/message.rb +4 -0
- data/lib/discord/resources/channels.rb +13 -0
- data/lib/discord/resources/messages.rb +32 -0
- data/lib/discord/resources/users.rb +5 -1
- data/lib/discord/version.rb +1 -1
- data/lib/discord.rb +5 -0
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a993b6022f4e54a0a926ca4df2dd83a8cdf9e1e40c04644d8aa57bfdcc783117
|
4
|
+
data.tar.gz: 6bf9e38ff1fe30475706f9ce1afe30cf7455360d92b709e66ee42a969040555d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c7448fc44c27fcf7e26f2beb4a8de74fbdc33225cf4831c2f1df5f2f3c1e33af8a88f732ae7ca1d5968a4551d61fdc6b04d3bcc6bfddea9d348983963dc814
|
7
|
+
data.tar.gz: 67289c6d49b1eb6f701c03d90c79164cdaaae17ddf162ef85906dae140579a8cf1e3a73d093a6b10be1b325fa815d70f5fc946199543aa012d77357e637d22b4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Discord API
|
2
2
|
|
3
|
-
This is a Ruby wrapper for the Discord API.
|
3
|
+
This is a Ruby wrapper for the Discord HTTP API. **Currently in development**
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -28,5 +28,50 @@ Firstly you'll need to set either a user token or bot token. Some endpoints are
|
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
# Get the current user
|
31
|
+
# Required scope: identify
|
32
|
+
# Required scopes if you want the user's email: identify email
|
31
33
|
@client.users.me
|
34
|
+
|
35
|
+
# Get the user's guilds
|
36
|
+
# Required scope: guilds
|
37
|
+
@client.users.guilds
|
38
|
+
```
|
39
|
+
|
40
|
+
### Channels
|
41
|
+
|
42
|
+
These endpoints are only accessible using a bot token.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# Retrieve a Channel
|
46
|
+
@client.channels.retrieve(id: 123123)
|
47
|
+
|
48
|
+
# Update a Channel's details
|
49
|
+
# https://discord.com/developers/docs/resources/channel#modify-channel
|
50
|
+
@client.channels.update(id: 123123, name: "new-channel-name")
|
51
|
+
```
|
52
|
+
|
53
|
+
### Messages
|
54
|
+
|
55
|
+
These endpoints are only accessible using a bot token.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
# List messages for a channel
|
59
|
+
@client.messages.list(channel_id: 123123)
|
60
|
+
|
61
|
+
# Get a message
|
62
|
+
@client.messages.retrieve(channel_id: 123123, message_id: 123123)
|
63
|
+
|
64
|
+
# Create a message
|
65
|
+
# https://discord.com/developers/docs/resources/channel#create-message
|
66
|
+
@client.messages.create(channel_id: 123123, content: "Hello World")
|
67
|
+
|
68
|
+
# Update a message
|
69
|
+
# https://discord.com/developers/docs/resources/channel#edit-message
|
70
|
+
@client.messages.update(channel_id: 123123, message_id: 123123, content: "Hello World")
|
71
|
+
|
72
|
+
# Delete a message
|
73
|
+
@client.messages.delete(channel_id: 123123, message_id: 123123)
|
74
|
+
|
75
|
+
# Bulk delete messages
|
76
|
+
@client.messages.bulk_delete(channel_id: 123123, ids: [123123, 321321])
|
32
77
|
```
|
data/Rakefile
CHANGED
data/lib/discord/client.rb
CHANGED
@@ -14,6 +14,14 @@ module Discord
|
|
14
14
|
UsersResource.new(self)
|
15
15
|
end
|
16
16
|
|
17
|
+
def channels
|
18
|
+
ChannelsResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def messages
|
22
|
+
MessagesResource.new(self)
|
23
|
+
end
|
24
|
+
|
17
25
|
def connection
|
18
26
|
@connection ||= Faraday.new(BASE_URL) do |conn|
|
19
27
|
if user_access_token
|
data/lib/discord/collection.rb
CHANGED
@@ -6,13 +6,13 @@ module Discord
|
|
6
6
|
body = response.body
|
7
7
|
|
8
8
|
new(
|
9
|
-
data: body
|
10
|
-
total: body
|
11
|
-
cursor: body.dig("pagination", "cursor")
|
9
|
+
data: body.map { |attrs| type.new(attrs) },
|
10
|
+
total: body.count,
|
11
|
+
# cursor: body.dig("pagination", "cursor")
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(data:, total:, cursor:)
|
15
|
+
def initialize(data:, total:, cursor:nil)
|
16
16
|
@data = data
|
17
17
|
@total = total
|
18
18
|
@cursor = cursor.nil? ? nil : cursor
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Discord
|
2
|
+
class MessagesResource < Resource
|
3
|
+
|
4
|
+
def list(channel:, **params)
|
5
|
+
response = get_request("channels/#{channel}/messages", params: params)
|
6
|
+
Collection.from_response(response, type: Message)
|
7
|
+
end
|
8
|
+
|
9
|
+
def retrieve(channel:, message:)
|
10
|
+
Message.new get_request("channels/#{channel}/messages/#{message}").body
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(channel:, **params)
|
14
|
+
response = post_request("channels/#{channel}/messages", body: params)
|
15
|
+
Message.new response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(channel:, id:, **params)
|
19
|
+
response = patch_request("channels/#{channel}/messages/#{id}", body: params)
|
20
|
+
Message.new response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(channel:, id:)
|
24
|
+
delete_request("channels/#{channel}/messages/#{id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def bulk_delete(channel:, messages:)
|
28
|
+
post_request("channels/#{channel}/messages/bulk-delete", body: {messages: messages})
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Discord
|
2
2
|
class UsersResource < Resource
|
3
3
|
|
4
|
-
# Get the currently authenticated user
|
5
4
|
def me
|
6
5
|
User.new get_request("users/@me").body
|
7
6
|
end
|
8
7
|
|
8
|
+
def guilds
|
9
|
+
response = get_request("users/@me/guilds")
|
10
|
+
Collection.from_response(response, type: Guild)
|
11
|
+
end
|
12
|
+
|
9
13
|
end
|
10
14
|
end
|
data/lib/discord/version.rb
CHANGED
data/lib/discord.rb
CHANGED
@@ -11,7 +11,12 @@ module Discord
|
|
11
11
|
autoload :Object, "discord/object"
|
12
12
|
|
13
13
|
autoload :UsersResource, "discord/resources/users"
|
14
|
+
autoload :ChannelsResource, "discord/resources/channels"
|
15
|
+
autoload :MessagesResource, "discord/resources/messages"
|
14
16
|
|
15
17
|
autoload :User, "discord/objects/user"
|
18
|
+
autoload :Guild, "discord/objects/guild"
|
19
|
+
autoload :Channel, "discord/objects/channel"
|
20
|
+
autoload :Message, "discord/objects/message"
|
16
21
|
|
17
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discord_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -41,16 +41,23 @@ files:
|
|
41
41
|
- lib/discord/collection.rb
|
42
42
|
- lib/discord/error.rb
|
43
43
|
- lib/discord/object.rb
|
44
|
+
- lib/discord/objects/channel.rb
|
45
|
+
- lib/discord/objects/guild.rb
|
46
|
+
- lib/discord/objects/message.rb
|
44
47
|
- lib/discord/objects/user.rb
|
45
48
|
- lib/discord/resource.rb
|
49
|
+
- lib/discord/resources/channels.rb
|
50
|
+
- lib/discord/resources/messages.rb
|
46
51
|
- lib/discord/resources/users.rb
|
47
52
|
- lib/discord/version.rb
|
48
53
|
- lib/discord_api.rb
|
49
54
|
- sig/discord/api.rbs
|
50
|
-
homepage:
|
55
|
+
homepage: https://github.com/deanpcmad/discord_api
|
51
56
|
licenses:
|
52
57
|
- MIT
|
53
|
-
metadata:
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/deanpcmad/discord_api
|
60
|
+
source_code_uri: https://github.com/deanpcmad/discord_api
|
54
61
|
post_install_message:
|
55
62
|
rdoc_options: []
|
56
63
|
require_paths:
|
@@ -69,5 +76,5 @@ requirements: []
|
|
69
76
|
rubygems_version: 3.4.10
|
70
77
|
signing_key:
|
71
78
|
specification_version: 4
|
72
|
-
summary:
|
79
|
+
summary: Ruby wrapper for the Discord HTTP API
|
73
80
|
test_files: []
|