Class: LibDiscord::Client
- Inherits:
-
Object
- Object
- LibDiscord::Client
- Defined in:
- lib/lib_discord/client.rb
Overview
This class is the entry point in utilizing lib_discord
to access Discord’s API. Initialize a client and cache it for as long as you need to make requests to Discord.
require "lib_discord"
client = LibDiscord::Client.new("Bot my.amazing.token")
Instance Method Summary collapse
-
#[](resource) ⇒ Object
Get a Resource for making Discord API requests.
-
#initialize(auth_header, base_url: "https://discord.com/api/v10", user_agent: "LibDiscord (#{LibDiscord::PROJECT_URL}, #{LibDiscord.version})", logger: nil) ⇒ self
constructor
Initialize a
LibDiscord::Client
for making requests to Discord’s RESTful web API. -
#keys ⇒ Array<String>
Get available Resource keys.
Constructor Details
#initialize(auth_header, base_url: "https://discord.com/api/v10", user_agent: "LibDiscord (#{LibDiscord::PROJECT_URL}, #{LibDiscord.version})", logger: nil) ⇒ self
Initialize a LibDiscord::Client
for making requests to Discord’s RESTful web API.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/lib_discord/client.rb', line 75 def initialize( auth_header, base_url: "https://discord.com/api/v10", user_agent: "LibDiscord (#{LibDiscord::PROJECT_URL}, #{LibDiscord.version})", logger: nil ) auth_header = Types::Coercible::String[auth_header] base_url = Types::Coercible::String[base_url] user_agent = Types::Coercible::String[user_agent] unless logger logger = Logger.new($stdout) logger.level = :info end logger = Types::Logger[logger] @container = Dry::Container.new @container.register("application") do Application.new(auth_header, base_url, user_agent, logger) end @container.register("application_command") do ApplicationCommand.new(auth_header, base_url, user_agent, logger) end @container.register("application_role_connection_metadata") do ApplicationRoleConnectionMetadata.new( auth_header, base_url, user_agent, logger ) end @container.register("audit_log") do AuditLog.new(auth_header, base_url, user_agent, logger) end @container.register("auto_moderation") do AutoModeration.new(auth_header, base_url, user_agent, logger) end @container.register("channel") do Channel.new(auth_header, base_url, user_agent, logger) end @container.register("emoji") do Emoji.new(auth_header, base_url, user_agent, logger) end @container.register("guild") do Guild.new(auth_header, base_url, user_agent, logger) end @container.register("guild_scheduled_event") do GuildScheduledEvent.new(auth_header, base_url, user_agent, logger) end @container.register("guild_template") do GuildTemplate.new(auth_header, base_url, user_agent, logger) end @container.register("interaction") do Interaction.new(auth_header, base_url, user_agent, logger) end @container.register("invite") do Invite.new(auth_header, base_url, user_agent, logger) end @container.register("poll") do Poll.new(auth_header, base_url, user_agent, logger) end @container.register("stage_instance") do StageInstance.new(auth_header, base_url, user_agent, logger) end @container.register("sticker") do Sticker.new(auth_header, base_url, user_agent, logger) end @container.register("user") do User.new(auth_header, base_url, user_agent, logger) end @container.register("voice") do Voice.new(auth_header, base_url, user_agent, logger) end @container.register("webhook") do Webhook.new(auth_header, base_url, user_agent, logger) end rescue Dry::Types::ConstraintError => e raise ConstraintError.new(e.result, e.input) end |
Instance Method Details
#[](resource) ⇒ Object
Get a Resource for making Discord API requests.
189 190 191 192 193 |
# File 'lib/lib_discord/client.rb', line 189 def [](resource) @container[resource] rescue Dry::Container::KeyError => e raise KeyError.new(e.) end |
#keys ⇒ Array<String>
Get available Resource keys.
207 |
# File 'lib/lib_discord/client.rb', line 207 def keys = @container.keys |