From 403518117f1868adf5adbe238aed0fa5cfabfd6f Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:13:13 -0400 Subject: [PATCH 1/6] chore: add with_roblosecurity() to client --- src/client.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client.rs b/src/client.rs index 9239732..d749fe0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -30,6 +30,14 @@ impl Client { Self::default() } + /// Creates a new [`Client`] with a roblosecurity already set. + pub fn with_roblosecurity(roblosecurity: String) -> Self { + Self { + roblosecurity: Mutex::new(Some(roblosecurity)), + ..Default::default() + } + } + /// Creates a new [`Client`] providing a custom [`reqwest::Client`]. /// Custom [`reqwest::Client`]s are used for configuring proxies. pub fn with_reqwest_client(reqwest_client: reqwest::Client) -> Self { From 3c7d4e215a2cda50493bc3c689972c60dd00d3d4 Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:15:20 -0400 Subject: [PATCH 2/6] style: prefer Client::with_roblosecurity() --- examples/get_client_user_info.rs | 3 +-- examples/get_resellers.rs | 3 +-- examples/get_robux_balance.rs | 3 +-- examples/get_user_sales.rs | 3 +-- examples/put_limited_on_sale.rs | 3 +-- examples/register_presence.rs | 3 +-- examples/take_limited_off_sale.rs | 3 +-- src/client.rs | 3 +-- src/economy/mod.rs | 15 +++++---------- src/presence/mod.rs | 3 +-- 10 files changed, 14 insertions(+), 28 deletions(-) diff --git a/examples/get_client_user_info.rs b/examples/get_client_user_info.rs index 6dedc24..1594f01 100644 --- a/examples/get_client_user_info.rs +++ b/examples/get_client_user_info.rs @@ -10,8 +10,7 @@ struct Args { #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); println!("Username: {}", client.username().await?); println!("Display Name: {}", client.display_name().await?); diff --git a/examples/get_resellers.rs b/examples/get_resellers.rs index 63c3ce7..a217a3e 100644 --- a/examples/get_resellers.rs +++ b/examples/get_resellers.rs @@ -12,8 +12,7 @@ struct Args { async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let item_id = 1365767; let limit = Limit::Ten; diff --git a/examples/get_robux_balance.rs b/examples/get_robux_balance.rs index 6c5f75e..48a8960 100644 --- a/examples/get_robux_balance.rs +++ b/examples/get_robux_balance.rs @@ -11,8 +11,7 @@ struct Args { async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let user = client.username().await?; let robux = client.robux().await?; diff --git a/examples/get_user_sales.rs b/examples/get_user_sales.rs index 0652767..0042d6b 100644 --- a/examples/get_user_sales.rs +++ b/examples/get_user_sales.rs @@ -11,8 +11,7 @@ struct Args { async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let limit = Limit::Hundred; let cursor = None; diff --git a/examples/put_limited_on_sale.rs b/examples/put_limited_on_sale.rs index 762e150..2f0b488 100644 --- a/examples/put_limited_on_sale.rs +++ b/examples/put_limited_on_sale.rs @@ -16,8 +16,7 @@ struct Args { #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let item_id = args.item_id; let uaid = args.uaid; diff --git a/examples/register_presence.rs b/examples/register_presence.rs index 02bb472..20a12a3 100644 --- a/examples/register_presence.rs +++ b/examples/register_presence.rs @@ -10,8 +10,7 @@ struct Args { #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let result = client.register_presence().await; diff --git a/examples/take_limited_off_sale.rs b/examples/take_limited_off_sale.rs index eeb4ade..a714b77 100644 --- a/examples/take_limited_off_sale.rs +++ b/examples/take_limited_off_sale.rs @@ -14,8 +14,7 @@ struct Args { #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); - let client = Client::new(); - client.set_roblosecurity(args.roblosecurity); + let client = Client::with_roblosecurity(args.roblosecurity); let item_id = args.item_id; let uaid = args.uaid; diff --git a/src/client.rs b/src/client.rs index d749fe0..a07f0a2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -110,8 +110,7 @@ impl Client { /// # fn main() -> Result<(), Box> { /// use roboat::Client; /// - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("my_roblosecurity".to_string()); /// let roblosecurity = client.roblosecurity()?; /// assert_eq!(roblosecurity, "my_roblosecurity".to_string()); /// # Ok(()) diff --git a/src/economy/mod.rs b/src/economy/mod.rs index 73da4db..0cfecb0 100644 --- a/src/economy/mod.rs +++ b/src/economy/mod.rs @@ -74,8 +74,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// let robux = client.robux().await?; /// println!("Robux: {}", robux); @@ -122,8 +121,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// let item_id = 1365767; /// let limit = Limit::Ten; @@ -202,8 +200,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// let limit = Limit::Ten; /// let cursor = None; @@ -296,8 +293,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// let item_id = 123456789; /// let uaid = 987654321; @@ -348,8 +344,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// let item_id = 123456789; /// let uaid = 987654321; diff --git a/src/presence/mod.rs b/src/presence/mod.rs index f63ae8a..d832861 100644 --- a/src/presence/mod.rs +++ b/src/presence/mod.rs @@ -20,8 +20,7 @@ impl Client { /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// let client = Client::new(); - /// client.set_roblosecurity("my_roblosecurity".to_string()); + /// let client = Client::with_roblosecurity("roblosecurity".to_string()); /// /// match client.register_presence().await { /// Ok(_) => println!("Successfully registered presence!"), From c1e41e80b9cabe07796c46ced84aeed89c2fe419 Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:15:59 -0400 Subject: [PATCH 3/6] docs: fix docs for Client::new() --- src/client.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/client.rs b/src/client.rs index a07f0a2..1cc2cef 100644 --- a/src/client.rs +++ b/src/client.rs @@ -22,10 +22,7 @@ pub struct Client { } impl Client { - /// Used to interface with Roblox.com endpoints. - /// - /// Contains any necessary authentication and security tokens, as well as the - /// reqwest client. + /// Creates a new [`Client`] with no authentication nor a custom `reqwest` client. pub fn new() -> Self { Self::default() } From 2da4c8d9b2f9d190a8cbceb04d12ec5b12a01aa6 Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:16:26 -0400 Subject: [PATCH 4/6] chore: add quick start examples --- src/lib.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e115ad5..bfa5f8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,91 @@ //! (all of them use the same endpoint internally and cache the results) //! * Presence API //! - Register Presence - [`Client::register_presence`] +//! +//! # Quick Start Examples +//! +//! ## Example 1 +//! +//! This code snippet allows you to get the details of an item. +//! +//! ```no_run +//! use roboat::catalog::avatar_catalog::{ItemArgs, ItemType}; +//! +//! #[tokio::main] +//! async fn main() -> Result<(), Box> { +//! let client = roboat::Client::new(); +//! +//! let item = ItemArgs { +//! item_type: ItemType::Asset, +//! id: 1365767, +//! }; +//! +//! let details = &client.item_details(vec![item]).await?[0]; +//! +//! let name = &details.name; +//! let description = &details.description; +//! let creator_name = &details.creator_name; +//! let price = details.price.unwrap_or(0); +//! +//! println!("Name: {}", name); +//! println!("Description: {}", description); +//! println!("Creator Name: {}", creator_name); +//! println!("Price: {}", price); +//! +//! Ok(()) +//! } +//! ``` +//! +//! ## Example 2 +//! +//! This code snippet allows you view the lowest price of a limited item by +//! fetching a list of reseller listings. +//! +//! ```no_run +//! // Replace value this with your own roblosecurity token. +//! const ROBLOSECURITY: &str = "your-roblosecurity-token"; +//! +//! #[tokio::main] +//! async fn main() -> Result<(), Box> { +//! let client = roboat::Client::with_roblosecurity(ROBLOSECURITY.to_string()); +//! +//! let item_id = 1365767; +//! let limit = roboat::Limit::Ten; +//! let cursor = None; +//! +//! let (resellers, _) = client.resellers(item_id, limit, cursor).await?; +//! +//! println!("Lowest Price for Valkyrie Helm: {}", resellers[0].price); +//! +//! Ok(()) +//! } +//! ``` +//! +//! //! ## Example 3 +//! +//! This code snippet allows you to get your current robux, id, username, and display name. +//! +//! ```no_run +//! // Replace value this with your own roblosecurity token. +//! const ROBLOSECURITY: &str = "your-roblosecurity-token"; +//! +//! #[tokio::main] +//! async fn main() -> Result<(), Box> { +//! let client = roboat::Client::with_roblosecurity(ROBLOSECURITY.to_string()); +//! +//! let robux = client.robux().await?; +//! let user_id = client.user_id().await?; +//! let username = client.username().await?; +//! let display_name = client.display_name().await?; +//! +//! println!("Robux: {}", robux); +//! println!("User ID: {}", user_id); +//! println!("Username: {}", username); +//! println!("Display Name: {}", display_name); +//! +//! Ok(()) +//! } +//! ``` #![warn(missing_docs)] From 9518a4330ca7a400e128c418b20cc77c3af45a9b Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:16:39 -0400 Subject: [PATCH 5/6] chore: remove todos --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bfa5f8e..5fb155a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,9 +124,8 @@ pub mod users; mod validation; // todo: add manual xcsrf refresh -// todo: endpoints that require premium/robux to test: recent trades, send trade, sell limited item, buy limited item, buy non-limited item +// todo: endpoints that require premium/robux to test: recent trades, send trade, buy limited item, buy non-limited item // todo: inventory api, groups api, follow api -// todo: add with_roblosecurity for client use serde::{Deserialize, Serialize}; From fd6e98f46be53ffccdf9183cd7fe54e7d9d1d18d Mon Sep 17 00:00:00 2001 From: Chloe-Woahie <68732833+Chloe-Woahie@users.noreply.github.com> Date: Sun, 2 Apr 2023 03:16:51 -0400 Subject: [PATCH 6/6] chore: increase crate version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 29ce982..1acf51d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "roboat" readme = "README.md" repository = "https://github.com/Chloe-Woahie/roboat" -version = "0.7.1" +version = "0.7.2" [dependencies] reqwest = { version = "0.11.14", default-features=false, features = ["rustls-tls", "json"] }