Class: Discord::Client
- Inherits:
-
Object
- Object
- Discord::Client
- Defined in:
- lib/discord/client.rb
Constant Summary collapse
- BASE_URL =
"https://discord.com/api/v10"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#bot_access_token ⇒ Object
readonly
Returns the value of attribute bot_access_token.
-
#user_access_token ⇒ Object
readonly
Returns the value of attribute user_access_token.
Instance Method Summary collapse
- #channels ⇒ Object
- #connection ⇒ Object
- #guilds ⇒ Object
-
#initialize(user_access_token: nil, bot_access_token: nil, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #messages ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(user_access_token: nil, bot_access_token: nil, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/discord/client.rb', line 7 def initialize(user_access_token: nil, bot_access_token: nil, adapter: Faraday.default_adapter) @user_access_token = user_access_token @bot_access_token = bot_access_token @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/discord/client.rb', line 5 def adapter @adapter end |
#bot_access_token ⇒ Object (readonly)
Returns the value of attribute bot_access_token.
5 6 7 |
# File 'lib/discord/client.rb', line 5 def bot_access_token @bot_access_token end |
#user_access_token ⇒ Object (readonly)
Returns the value of attribute user_access_token.
5 6 7 |
# File 'lib/discord/client.rb', line 5 def user_access_token @user_access_token end |
Instance Method Details
#channels ⇒ Object
21 22 23 |
# File 'lib/discord/client.rb', line 21 def channels ChannelsResource.new(self) end |
#connection ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/discord/client.rb', line 29 def connection @connection ||= Faraday.new(BASE_URL) do |conn| if user_access_token conn.request :authorization, :Bearer, user_access_token elsif bot_access_token conn.request :authorization, :Bot, bot_access_token else raise Error, "You must provide a user or bot access token." end conn.headers = { "User-Agent" => "discord_api/v#{VERSION} (github.com/deanpcmad/discord_api)" } conn.request :json conn.response :json, content_type: "application/json" conn.adapter adapter, @stubs end end |
#guilds ⇒ Object
17 18 19 |
# File 'lib/discord/client.rb', line 17 def guilds GuildsResource.new(self) end |
#messages ⇒ Object
25 26 27 |
# File 'lib/discord/client.rb', line 25 def MessagesResource.new(self) end |
#users ⇒ Object
13 14 15 |
# File 'lib/discord/client.rb', line 13 def users UsersResource.new(self) end |