Skip to content

Commit

Permalink
Merge pull request #33 from Chloe-Woahie/dev-main
Browse files Browse the repository at this point in the history
v0.11.0
  • Loading branch information
fekie authored Apr 7, 2023
2 parents 8672995 + ac4382a commit be13963
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 48 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.10.2"
version = "0.11.0"

[dependencies]
reqwest = { version = "0.11.14", default-features=false, features = ["rustls-tls", "json"] }
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ A high performance interface for the Roblox API.
This library is designed to be high-performance capable, meaning that it supports proxies
and is capable of making requests in parallel.

# Documentation
Extensive documentation is used throughout this crate.
All public methods in this crate are documented and have at least one corresponding example.

Documentation can be found [here](https://docs.rs/roboat/).

# Covered Endpoints
* Catalog API - [`catalog.roblox.com/*`]
- Item Details - `/v1/catalog/items/details`
Expand All @@ -24,6 +27,7 @@ All public methods in this crate are documented and have at least one correspond
- User Sales - `/v2/users/{user_id}/transactions?transactionType=Sale`
- Put Limited On Sale - `/v1/assets/{item_id}/resellable-copies/{uaid}`
- Take Limited Off Sale - `/v1/assets/{item_id}/resellable-copies/{uaid}`
- Purchase Limited - `/v1/purchases/products/{product_id}`
* Users API - [`users.roblox.com/*`]
- User Information - `/v1/users/authenticated`
- User Search - `/v1/users/search`
Expand All @@ -32,6 +36,19 @@ All public methods in this crate are documented and have at least one correspond
* Trades API - [`trades.roblox.com/*`]
- Trades List - `/v1/trades/{trade_type}`

# Setup
You can add the latest version of roboat to your project by running:
```bash
cargo add roboat
```

Alternatively, you can add a specific version of roboat to your project by adding the crate to your `Cargo.toml`:

```toml
[dependencies]
roboat = "0.11.0"
```

# Quick Start Examples

## Example 1
Expand Down
52 changes: 52 additions & 0 deletions examples/purchase_limited.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use clap::Parser;
use roboat::ClientBuilder;

#[derive(Parser, Debug)]
struct Args {
#[arg(long, short)]
roblosecurity: String,
#[arg(long, short)]
item_id: u64,
#[arg(long, short)]
seller_id: u64,
#[arg(long, short)]
uaid: u64,
#[arg(long, short)]
price: u64,
}

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

let item_id = args.item_id;
let seller_id = args.seller_id;
let uaid = args.uaid;
let price = args.price;

let item_args = roboat::catalog::avatar_catalog::ItemArgs {
item_type: roboat::catalog::avatar_catalog::ItemType::Asset,
id: item_id,
};

let product_id = client
.item_details(vec![item_args])
.await?
.pop()
.unwrap()
.product_id;

let result = client
.purchase_limited(product_id, seller_id, uaid, price)
.await;

match result {
Ok(()) => println!("Purchased item for {} robux.", price),
Err(e) => println!("Failed to purchase item for {} robux. Reason: {}", price, e),
}

Ok(())
}
14 changes: 7 additions & 7 deletions src/catalog/avatar_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Client, RoboatError};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

mod reqwest_types;
mod request_types;

// A useful link for the encodings for item types: https://create.roblox.com/docs/studio/catalog-api#avatar-catalog-api

Expand Down Expand Up @@ -365,10 +365,10 @@ impl TryFrom<u64> for BundleType {
}
}

impl TryFrom<reqwest_types::ItemDetailsRaw> for ItemDetails {
impl TryFrom<request_types::ItemDetailsRaw> for ItemDetails {
type Error = RoboatError;

fn try_from(value: reqwest_types::ItemDetailsRaw) -> Result<Self, Self::Error> {
fn try_from(value: request_types::ItemDetailsRaw) -> Result<Self, Self::Error> {
let asset_type = match value.asset_type {
Some(asset_type_id) => {
let asset_type = AssetType::try_from(asset_type_id)?;
Expand Down Expand Up @@ -505,7 +505,7 @@ impl Client {
}

mod internal {
use super::{reqwest_types, ItemArgs, ItemDetails, ITEM_DETAILS_API};
use super::{request_types, ItemArgs, ItemDetails, ITEM_DETAILS_API};
use crate::XCSRF_HEADER;
use crate::{Client, RoboatError};
use std::convert::TryFrom;
Expand All @@ -515,11 +515,11 @@ mod internal {
&self,
items: Vec<ItemArgs>,
) -> Result<Vec<ItemDetails>, RoboatError> {
let request_body = reqwest_types::ItemDetailsReqBody {
let request_body = request_types::ItemDetailsReqBody {
// Convert the ItemParameters to te reqwest ItemParametersReq
items: items
.iter()
.map(|x| reqwest_types::ItemArgsReq::from(*x))
.map(|x| request_types::ItemArgsReq::from(*x))
.collect(),
};

Expand All @@ -532,7 +532,7 @@ mod internal {
.await;

let response = Self::validate_request_result(request_result).await?;
let raw = Self::parse_to_raw::<reqwest_types::ItemDetailsResponse>(response).await?;
let raw = Self::parse_to_raw::<request_types::ItemDetailsResponse>(response).await?;

let mut item_details = Vec::new();

Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ use tokio::sync::RwLock;
/// let reqwest_client = reqwest::Client::new();
/// let client = ClientBuilder::new().roblosecurity(ROBLOSECURITY.to_string()).reqwest_client(reqwest_client).build();
/// ```
///
/// # Standard Errors
/// The errors that can be returned by any of `Client`'s methods are:
/// - [`RoboatError::TooManyRequests`]
/// - [`RoboatError::InternalServerError`]
/// - [`RoboatError::BadRequest`]
/// - [`RoboatError::UnknownRobloxErrorCode`]
/// - [`RoboatError::UnidentifiedStatusCode`]
/// - [`RoboatError::ReqwestError`]
///
/// # Auth Required Errors
/// The errors that can be returned by any of `Client`'s methods that require authentication are:
/// - [`RoboatError::InvalidRoblosecurity`]
/// - [`RoboatError::RoblosecurityNotSet`]
///
/// # X-CSRF-TOKEN Required Errors
/// The errors that can be returned by any of `Client`'s methods that require the X-CSRF-TOKEN header are:
/// - [`RoboatError::InvalidXcsrf`]
/// - [`RoboatError::XcsrfNotReturned`]
#[derive(Debug, Default)]
pub struct Client {
/// The full cookie that includes the roblosecurity token.
Expand Down
Loading

0 comments on commit be13963

Please sign in to comment.