From ea0239c78b4378e5d48fd28600b22fd96eee2906 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 1 Oct 2024 11:31:23 -0700 Subject: [PATCH] cookie.get_user_inventory_page --- rbx_asset/src/cookie.rs | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/rbx_asset/src/cookie.rs b/rbx_asset/src/cookie.rs index b4921bf..7f1d7dc 100644 --- a/rbx_asset/src/cookie.rs +++ b/rbx_asset/src/cookie.rs @@ -150,6 +150,38 @@ pub struct CreationsPageResponse{ pub data:Vec, } +pub struct UserInventoryPageRequest{ + pub user_id:u64, + pub cursor:Option, +} + +#[derive(serde::Deserialize,serde::Serialize)] +#[allow(nonstandard_style,dead_code)] +pub struct UserInventoryItemOwner{ + userId:u64, + username:String, + buildersClubMembershipType:u64, +} +#[derive(serde::Deserialize,serde::Serialize)] +#[allow(nonstandard_style,dead_code)] +pub struct UserInventoryItem{ + userAssetId:u64, + assetId:u64, + assetName:String, + collectibleItemId:Option, + collectibleItemInstanceId:Option, + owner:UserInventoryItemOwner, + created:chrono::DateTime, + updated:chrono::DateTime, +} +#[derive(serde::Deserialize,serde::Serialize)] +#[allow(nonstandard_style,dead_code)] +pub struct UserInventoryPageResponse{ + pub previousPageCursor:Option, + pub nextPageCursor:Option, + pub data:Vec, +} + //idk how to do this better enum ReaderType{ GZip(flate2::read::GzDecoder>), @@ -321,4 +353,18 @@ impl CookieContext{ .error_for_status().map_err(PageError::Reqwest)? .json::().await.map_err(PageError::Reqwest) } + pub async fn get_user_inventory_page(&self,config:&UserInventoryPageRequest)->Result{ + let mut url=reqwest::Url::parse(format!("https://inventory.roblox.com/v2/users/{}/inventory/10?limit=100&sortOrder=Desc",config.user_id).as_str()).map_err(PageError::ParseError)?; + //url borrow scope + { + let mut query=url.query_pairs_mut();//borrow here + if let Some(cursor)=config.cursor.as_deref(){ + query.append_pair("cursor",cursor); + } + } + + self.get(url).await.map_err(PageError::Reqwest)? + .error_for_status().map_err(PageError::Reqwest)? + .json::().await.map_err(PageError::Reqwest) + } }