pub struct Client(/* private fields */);Expand description
Struct which defines the methods necessary to interact with the service.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
http_client: impl Into<Arc<HttpClient>>,
token: impl Into<Option<String>>,
) -> Self
pub fn new( http_client: impl Into<Arc<HttpClient>>, token: impl Into<Option<String>>, ) -> Self
Creates a new client to interact with the API.
This accepts an existing reqwest Client so a single HTTP client may be shared across your application.
This method doesn’t require authentication.
§Examples
Create a new API client:
use reqwest::Client as HttpClient;
use top_gg::Client;
let http_client = HttpClient::new();
let client = Client::new(http_client, None);Sourcepub async fn get_bot(&self, user_id: u64) -> Result<Bot>
pub async fn get_bot(&self, user_id: u64) -> Result<Bot>
Retrieves information about a bot.
This method doesn’t require authentication.
§Examples
use reqwest::Client as HttpClient;
use top_gg::Client;
let http_client = HttpClient::new();
let client = Client::new(http_client, None);
let bot = client.get_bot(270198738570444801).await?;
println!("Bot's name: {}", bot.username);§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Sourcepub fn get_bots(&self) -> SearchBots<'_> ⓘ
pub fn get_bots(&self) -> SearchBots<'_> ⓘ
Retrieves a list of bots via a search.
This method doesn’t require authentication.
§Examples
Get 500 bots, skipping the first 250 bots:
use reqwest::Client as HttpClient;
use top_gg::Client;
let http_client = HttpClient::new();
let client = Client::new(http_client, None);
let bots = client.get_bots().limit(500).offset(250).await?;
println!("Got {} bots", bots.total);§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Sourcepub async fn get_bot_stats(&self, user_id: u64) -> Result<BotStats>
pub async fn get_bot_stats(&self, user_id: u64) -> Result<BotStats>
Retrieves information about a bot’s specific stats.
This method doesn’t require authentication.
§Examples
use reqwest::Client as HttpClient;
use top_gg::Client;
let http_client = HttpClient::new();
let client = Client::new(http_client, None);
let bot = client.get_bot_stats(270_198_738_570_444_801).await?;
if let Some(server_count) = bot.server_count {
println!("This bot is in {} servers", server_count);
}§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Sourcepub async fn get_bot_vote_check(
&self,
bot_id: u64,
user_id: u64,
) -> Result<bool>
pub async fn get_bot_vote_check( &self, bot_id: u64, user_id: u64, ) -> Result<bool>
Retrieve whether a user has upvoted a bot in the last 24 hours.
You can use this if your bot has over 1000 votes.
This method requires authentication.
§Examples
use reqwest::Client as HttpClient;
use std::env;
use top_gg::Client;
let http_client = HttpClient::new();
let token = env::var("TOP_GG_TOKEN")?;
let client = Client::new(http_client, token);
let voted = client.get_bot_vote_check(270_198_738_570_444_801, 114_941_315_417_899_012).await?;
if voted {
println!("This user voted");
} else {
println!("This user has not voted");
}§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Returns Error::TokenMissing if a token is needed for authentication
but it wasn’t present.
Sourcepub async fn get_bot_votes(&self, bot_id: u64) -> Result<BotVotes>
pub async fn get_bot_votes(&self, bot_id: u64) -> Result<BotVotes>
Retrieves information to see who has upvoted a bot.
This method does not require authentication.
Note: If your bot has over 1000 votes per month, then this can not be used. Webhooks must instead be used.
§Examples
use reqwest::Client as HttpClient;
use top_gg::{
model::BotVotes,
Client,
};
let http_client = HttpClient::new();
let client = Client::new(http_client, None);
let votes = client.get_bot_votes(270_198_738_570_444_801).await?;
match votes {
BotVotes::Ids(ids) => println!("There are {} votes", ids.len()),
BotVotes::Users(users) => println!("There are {} votes", users.len()),
}§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Sourcepub async fn get_user(&self, user_id: u64) -> Result<User>
pub async fn get_user(&self, user_id: u64) -> Result<User>
Retrieves information about a user.
This method doesn’t require authentication.
§Examples
use reqwest::Client as HttpClient;
use top_gg::Client;
let http_client = HttpClient::new();
let client = Client::new(http_client, None);
let user = client.get_user(114_941_315_417_899_012).await?;
println!("The user's name is {}", user.username);§Errors
Returns Error::ChunkingText when the response body couldn’t be
chunked as a valid UTF-8 string.
Returns Error::Deserializing if there was an issue deserializing the
response body.
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Sourcepub async fn post_stats<'a>(
&'a self,
bot_id: u64,
stats: &'a ShardStats,
) -> Result<()>
pub async fn post_stats<'a>( &'a self, bot_id: u64, stats: &'a ShardStats, ) -> Result<()>
Posts a bot’s shard stats.
This method requires authentication.
§Examples
use reqwest::Client as HttpClient;
use std::env;
use top_gg::{
model::ShardStats,
Client,
};
let http_client = HttpClient::new();
let token = env::var("TOP_GG_TOKEN")?;
let client = Client::new(http_client, token);
let shard_stats = ShardStats::Shard {
guild_count: 1123,
shard_count: 10,
shard_id: 6,
};
client.post_stats(270_198_738_570_444_801, &shard_stats).await?;§Errors
Returns Error::Request if there was an issue building the request.
This probably won’t happen.
Returns Error::TokenMissing if a token is needed for authentication
but it wasn’t present.