Skip to content

Commit

Permalink
Merge pull request #15 from Chloe-Woahie/dev-main
Browse files Browse the repository at this point in the history
v0.7.2
  • Loading branch information
fekie authored Apr 2, 2023
2 parents e5edf68 + fd6e98f commit 9cb352e
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 1 addition & 2 deletions examples/get_client_user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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?);
Expand Down
3 changes: 1 addition & 2 deletions examples/get_resellers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct Args {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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;
Expand Down
3 changes: 1 addition & 2 deletions examples/get_robux_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ struct Args {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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?;
Expand Down
3 changes: 1 addition & 2 deletions examples/get_user_sales.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ struct Args {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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;
Expand Down
3 changes: 1 addition & 2 deletions examples/put_limited_on_sale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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;
Expand Down
3 changes: 1 addition & 2 deletions examples/register_presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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;

Expand Down
3 changes: 1 addition & 2 deletions examples/take_limited_off_sale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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;
Expand Down
16 changes: 10 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ 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()
}

/// 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 {
Expand Down Expand Up @@ -102,8 +107,7 @@ impl Client {
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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(())
Expand Down
15 changes: 5 additions & 10 deletions src/economy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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);
Expand Down Expand Up @@ -122,8 +121,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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;
Expand Down Expand Up @@ -202,8 +200,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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;
Expand Down Expand Up @@ -296,8 +293,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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;
Expand Down Expand Up @@ -348,8 +344,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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;
Expand Down
88 changes: 86 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
//! 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<dyn std::error::Error>> {
//! 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<dyn std::error::Error>> {
//! 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)]

Expand All @@ -39,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};

Expand Down
3 changes: 1 addition & 2 deletions src/presence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ impl Client {
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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!"),
Expand Down

0 comments on commit 9cb352e

Please sign in to comment.