[][src]Struct top_gg::client::Client

pub struct Client(_);

Struct which defines the methods necessary to interact with the service.

Methods

impl Client[src]

pub fn new(
    http_client: impl Into<Arc<HttpClient>>,
    token: impl Into<Option<String>>
) -> Self
[src]

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);

pub async fn get_bot<'_>(&'_ self, user_id: u64) -> Result<Bot>[src]

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.

Important traits for SearchBots<'_>
pub fn get_bots(&self) -> SearchBots[src]

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.

pub async fn get_bot_stats<'_>(&'_ self, user_id: u64) -> Result<BotStats>[src]

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.

pub async fn get_bot_vote_check<'_>(
    &'_ self,
    bot_id: u64,
    user_id: u64
) -> Result<bool>
[src]

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.

pub async fn get_bot_votes<'_>(&'_ self, bot_id: u64) -> Result<BotVotes>[src]

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.

pub async fn get_user<'_>(&'_ self, user_id: u64) -> Result<User>[src]

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.

pub async fn post_stats<'a>(
    &'a self,
    bot_id: u64,
    stats: &'a ShardStats
) -> Result<()>
[src]

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.

Trait Implementations

impl From<(Arc<Client>, Option<String>)> for Client[src]

impl Clone for Client[src]

impl Debug for Client[src]

Auto Trait Implementations

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

impl !RefUnwindSafe for Client

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]