Skip to content

Commit

Permalink
Merge pull request #58 from Chloe-Woahie/dev-main
Browse files Browse the repository at this point in the history
v0.30.0
  • Loading branch information
fekie authored May 24, 2023
2 parents 0405bd1 + f128284 commit 29c03f5
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 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.29.0"
version = "0.30.0"

[dependencies]
reqwest = { version = "0.11.14", default-features=false, features = ["rustls-tls", "json"] }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Documentation can be found [here](https://docs.rs/roboat/).
- Send Trade - [`Client::send_trade`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.send_trade)
- Fetch Trades List - [`Client::trades`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.trades)
- Fetch Trade Details - [`Client::trade_details`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.trade_details)
- Fetch Trade Count - [`Client::trade_count`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.trade_count)
* Users API - [`users.roblox.com/*`]
- Fetch User ID - [`Client::user_id`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.user_id)
- Fetch Username - [`Client::username`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.username)
Expand All @@ -79,7 +80,7 @@ Alternatively, you can add a specific version of roboat to your project by addin

```toml
[dependencies]
roboat = "0.29.0"
roboat = "0.30.0"
```

# Quick Start Examples
Expand Down
23 changes: 23 additions & 0 deletions examples/fetch_trade_count.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use clap::Parser;
use roboat::ClientBuilder;
use roboat::RoboatError;

#[derive(Parser, Debug)]
struct Args {
#[arg(long, short)]
roblosecurity: String,
}

#[tokio::main]
async fn main() -> Result<(), RoboatError> {
let args = Args::parse();
let client = ClientBuilder::new()
.roblosecurity(args.roblosecurity)
.build();

let trade_count = client.trade_count().await?;

println!("Total trades: {}", trade_count);

Ok(())
}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
//! - Send Trade - [`Client::send_trade`]
//! - Fetch Trade Details - [`Client::trade_details`]
//! - Fetch Trades List - [`Client::trades`]
//! - Fetch Trade Count - [`Client::trade_count`]
//! * Users API
//! - Fetch User ID - [`Client::user_id`]
//! - Fetch Username - [`Client::username`]
Expand Down Expand Up @@ -226,7 +227,6 @@ pub mod users;
/// A module related to validating requests.
mod validation;

// 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 usage to readme
// todo: every type should have an explanation of the typical means by which the user will construct or fetch it, if the answer isn't “this is a struct literal with public methods”.
Expand All @@ -235,9 +235,6 @@ mod validation;
// todo: maybe post on devforums, reddit, maybe the rust server
// todo: put string of parsing error in MalformedResponse
// todo: apparently a v2 details api does 500 items at once
// todo: name apis api bedev2 or something
// todo: rename methods and docs to remain consistent over what non-tradable limiteds are called.
// todo: add method to get items from catalog
// todo: make ItemDetails include both price and lowest price
// todo: replace urls with the form GROUP_ROLES_API.replace("{group_id}", &group_id.to_string());
// todo: maybe add stronger types for stuff like cursors? stuff that can be returned basically
Expand Down
1 change: 1 addition & 0 deletions src/thumbnails/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl Client {
///
/// # Notes
/// * Does not require a valid roblosecurity.
/// * Can handle up to 100 asset ids at once.
///
/// # Errors
/// * All errors under [Standard Errors](#standard-errors).
Expand Down
44 changes: 44 additions & 0 deletions src/trades/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TRADE_DETAILS_API: &str = "https://trades.roblox.com/v1/trades/{trade_id}"
const DECLINE_TRADE_API: &str = "https://trades.roblox.com/v1/trades/{trade_id}/decline";
const SEND_TRADE_API: &str = "https://trades.roblox.com/v1/trades/send";
const ACCEPT_TRADE_API: &str = "https://trades.roblox.com/v1/trades/{trade_id}/accept";
const TRADE_COUNT_API: &str = "https://trades.roblox.com/v1/trades/inbound/count";

/// For requests related to trades, we use Descending as the sort order.
/// This is because there is hardly any use case for using a reverse sort order for trades.
Expand Down Expand Up @@ -463,6 +464,49 @@ impl Client {
},
}
}

/// Retrieves the count of trades the user using <https://trades.roblox.com/v1/trades/inbound/count>.
///
/// # Notes
/// * Requires a valid roblosecurity.
///
/// # Errors
/// * All errors under [Standard Errors](#standard-errors).
/// * All errors under [Auth Required Errors](#auth-required-errors).
///
/// # Examples
///
/// ```no_run
/// use roboat::ClientBuilder;
/// use roboat::RoboatError;
///
/// const ROBLOSECURITY: &str = "roblosecurity";
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), RoboatError> {
/// let client = ClientBuilder::new().roblosecurity(ROBLOSECURITY.to_string()).build();
///
/// let trade_count = client.trade_count().await?;
///
/// println!("Total trades: {}", trade_count);
/// # Ok(())
/// # }
/// ```
pub async fn trade_count(&self) -> Result<u64, RoboatError> {
let cookie_string = self.cookie_string()?;

let response_result = self
.reqwest_client
.get(TRADE_COUNT_API)
.header(header::COOKIE, cookie_string)
.send()
.await;

let response = Self::validate_request_result(response_result).await?;
let raw = Self::parse_to_raw::<request_types::TradeCountResponse>(response).await?;

Ok(raw.count)
}
}

mod internal {
Expand Down
5 changes: 5 additions & 0 deletions src/trades/request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ pub(super) struct SendTradeOffer {
pub(super) struct SendTradeResponse {
pub id: u64,
}

#[derive(Serialize, Deserialize)]
pub(super) struct TradeCountResponse {
pub count: u64,
}

0 comments on commit 29c03f5

Please sign in to comment.