diff --git a/Cargo.toml b/Cargo.toml index f016627..53939b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "r6stats_client" -version = "0.2.1" +version = "0.2.2" authors = ["Jan Adä "] edition = "2018" description = "Client for the r6stats API." diff --git a/README.md b/README.md index ab301fc..c5f61f9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies] -r6stats_client = "0.1" +r6stats_client = "0.2" ``` Basic example: ```rust diff --git a/src/client.rs b/src/client.rs index 87298d9..6cc6da3 100644 --- a/src/client.rs +++ b/src/client.rs @@ -51,9 +51,9 @@ impl Client { /// # Args /// /// - `token` - The API key for authentication with the endpoint - pub fn new(token: &str) -> Result { + pub fn new(token: impl AsRef) -> Result { Self::_new( - token, + token.as_ref(), #[cfg(feature = "ratelimiting")] Ratelimit::default(), ) @@ -68,14 +68,14 @@ impl Client { /// /// [`Ratelimit`]: http/ratelimit/struct.Ratelimit.html #[cfg(feature = "ratelimiting")] - pub fn with_ratelimit(token: &str, op: F) -> Result + pub fn with_ratelimit(token: impl AsRef, op: F) -> Result 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. diff --git a/src/stats/client.rs b/src/stats/client.rs index 8648ef1..38f8193 100644 --- a/src/stats/client.rs +++ b/src/stats/client.rs @@ -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 { - let response = self.request(username, platform, Kind::Generic).await?; + pub async fn generic( + &self, + username: impl AsRef, + platform: Platform, + ) -> Result { + let response = self + .request(username.as_ref(), platform, Kind::Generic) + .await?; let bytes = response.bytes().await?; Ok(serde_json::from_slice(&bytes)?) } @@ -40,10 +46,12 @@ impl Client { /// [`Platform`]: ../../platform/enum.Platform.html pub async fn seasonal( &self, - username: &str, + username: impl AsRef, platform: Platform, ) -> Result { - 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)?) } @@ -58,10 +66,12 @@ impl Client { /// [`Platform`]: ../../platform/enum.Platform.html pub async fn operators( &self, - username: &str, + username: impl AsRef, platform: Platform, ) -> Result { - 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)?) } @@ -76,11 +86,11 @@ impl Client { /// [`Platform`]: ../../platform/enum.Platform.html pub async fn weapon_categories( &self, - username: &str, + username: impl AsRef, platform: Platform, ) -> Result { 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)?) @@ -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 { - let response = self.request(username, platform, Kind::Weapons).await?; + pub async fn weapons( + &self, + username: impl AsRef, + platform: Platform, + ) -> Result { + let response = self + .request(username.as_ref(), platform, Kind::Weapons) + .await?; let bytes = response.bytes().await?; Ok(serde_json::from_slice(&bytes)?) }