Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Adä committed Nov 1, 2020
1 parent 79cf52d commit 4ae7666
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "r6stats_client"
version = "0.2.1"
version = "0.2.2"
authors = ["Jan Adä <jan561.github@gmail.com>"]
edition = "2018"
description = "Client for the r6stats API."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add the following to your `Cargo.toml`:

```toml
[dependencies]
r6stats_client = "0.1"
r6stats_client = "0.2"
```
Basic example:
```rust
Expand Down
8 changes: 4 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl Client {
/// # Args
///
/// - `token` - The API key for authentication with the endpoint
pub fn new(token: &str) -> Result<Self, Error> {
pub fn new(token: impl AsRef<str>) -> Result<Self, Error> {
Self::_new(
token,
token.as_ref(),
#[cfg(feature = "ratelimiting")]
Ratelimit::default(),
)
Expand All @@ -68,14 +68,14 @@ impl Client {
///
/// [`Ratelimit`]: http/ratelimit/struct.Ratelimit.html
#[cfg(feature = "ratelimiting")]
pub fn with_ratelimit<F>(token: &str, op: F) -> Result<Self, Error>
pub fn with_ratelimit<F>(token: impl AsRef<str>, op: F) -> Result<Self, Error>
where
F: FnOnce(RatelimitBuilder) -> RatelimitBuilder,
{
let builder = op(RatelimitBuilder::new());
let ratelimit = builder.build();

Self::_new(token, ratelimit)
Self::_new(token.as_ref(), ratelimit)
}

/// Returns the client for requests to the stats endpoint.
Expand Down
36 changes: 26 additions & 10 deletions src/stats/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ impl Client {
/// - `platform` - The [`Platform`] of the player
///
/// [`Platform`]: ../../platform/enum.Platform.html
pub async fn generic(&self, username: &str, platform: Platform) -> Result<GenericStats, Error> {
let response = self.request(username, platform, Kind::Generic).await?;
pub async fn generic(
&self,
username: impl AsRef<str>,
platform: Platform,
) -> Result<GenericStats, Error> {
let response = self
.request(username.as_ref(), platform, Kind::Generic)
.await?;
let bytes = response.bytes().await?;
Ok(serde_json::from_slice(&bytes)?)
}
Expand All @@ -40,10 +46,12 @@ impl Client {
/// [`Platform`]: ../../platform/enum.Platform.html
pub async fn seasonal(
&self,
username: &str,
username: impl AsRef<str>,
platform: Platform,
) -> Result<SeasonalStats, Error> {
let response = self.request(username, platform, Kind::Seasonal).await?;
let response = self
.request(username.as_ref(), platform, Kind::Seasonal)
.await?;
let bytes = response.bytes().await?;
Ok(serde_json::from_slice(&bytes)?)
}
Expand All @@ -58,10 +66,12 @@ impl Client {
/// [`Platform`]: ../../platform/enum.Platform.html
pub async fn operators(
&self,
username: &str,
username: impl AsRef<str>,
platform: Platform,
) -> Result<OperatorStats, Error> {
let response = self.request(username, platform, Kind::Operators).await?;
let response = self
.request(username.as_ref(), platform, Kind::Operators)
.await?;
let bytes = response.bytes().await?;
Ok(serde_json::from_slice(&bytes)?)
}
Expand All @@ -76,11 +86,11 @@ impl Client {
/// [`Platform`]: ../../platform/enum.Platform.html
pub async fn weapon_categories(
&self,
username: &str,
username: impl AsRef<str>,
platform: Platform,
) -> Result<WeaponCategoryStats, Error> {
let response = self
.request(username, platform, Kind::WeaponCategories)
.request(username.as_ref(), platform, Kind::WeaponCategories)
.await?;
let bytes = response.bytes().await?;
Ok(serde_json::from_slice(&bytes)?)
Expand All @@ -94,8 +104,14 @@ impl Client {
/// - `platform` - The [`Platform`] of the player
///
/// [`Platform`]: ../../platform/enum.Platform.html
pub async fn weapons(&self, username: &str, platform: Platform) -> Result<WeaponStats, Error> {
let response = self.request(username, platform, Kind::Weapons).await?;
pub async fn weapons(
&self,
username: impl AsRef<str>,
platform: Platform,
) -> Result<WeaponStats, Error> {
let response = self
.request(username.as_ref(), platform, Kind::Weapons)
.await?;
let bytes = response.bytes().await?;
Ok(serde_json::from_slice(&bytes)?)
}
Expand Down

0 comments on commit 4ae7666

Please sign in to comment.