-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Sleitnick/feature/user
User API
- Loading branch information
Showing
12 changed files
with
446 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# User CLI | ||
|
||
## Getting User Information | ||
``` | ||
Usage: rbxcloud user get [OPTIONS] --user-id <USER_ID> --api-key <API_KEY> | ||
Options: | ||
-u, --user-id <USER_ID> User ID | ||
-p, --pretty Pretty-print the JSON response | ||
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=] | ||
-h, --help Print help | ||
``` | ||
|
||
### Example | ||
``` | ||
$ rbxcloud user get -p -u 12345 -a MY_KEY | ||
``` | ||
|
||
## Generating User Thumbnail | ||
``` | ||
Usage: rbxcloud user thumbnail [OPTIONS] --user-id <USER_ID> --api-key <API_KEY> | ||
Options: | ||
-u, --user-id <USER_ID> User ID | ||
-s, --size <SIZE> Thumbnail size [possible values: size48x48, size50x50, size60x60, size75x75, size100x100, size110x110, size150x150, size180x180, size352x352, size420x420, size720x720] | ||
-f, --format <FORMAT> Thumbnail format [possible values: png, jpeg] | ||
-S, --shape <SHAPE> Thumbnail shape [possible values: round, square] | ||
-p, --pretty Pretty-print the JSON response | ||
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=] | ||
-h, --help Print help | ||
``` | ||
|
||
### Example | ||
``` | ||
$ rbxcloud user thumbnail -p -u 12345 -s size100x100 -f png -S round -a MY_KEY | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use rbxcloud::rbx::{ | ||
error::Error, | ||
types::RobloxUserId, | ||
v2::{user::GetUserResponse, Client}, | ||
}; | ||
|
||
async fn user_info() -> Result<GetUserResponse, Error> { | ||
// Inputs: | ||
let api_key = "MY_API_KEY"; | ||
let user_id = 308165; | ||
|
||
let client = Client::new(api_key); | ||
let user_client = client.user(); | ||
|
||
user_client.get_user(RobloxUserId(user_id)).await | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let user_info_res = user_info().await; | ||
|
||
match user_info_res { | ||
Ok(user_info) => { | ||
println!("{:?}", user_info); | ||
} | ||
Err(e) => { | ||
eprintln!("{e:?}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use clap::{Args, Subcommand}; | ||
use rbxcloud::rbx::{ | ||
types::RobloxUserId, | ||
v2::{ | ||
user::{UserThumbnailFormat, UserThumbnailShape, UserThumbnailSize}, | ||
Client, | ||
}, | ||
}; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum UserCommands { | ||
/// Get user information | ||
Get { | ||
/// User ID | ||
#[clap(short, long, value_parser)] | ||
user_id: u64, | ||
|
||
/// Pretty-print the JSON response | ||
#[clap(short, long, value_parser, default_value_t = false)] | ||
pretty: bool, | ||
|
||
/// Roblox Open Cloud API Key | ||
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")] | ||
api_key: String, | ||
}, | ||
|
||
/// Generate user thumbnail | ||
Thumbnail { | ||
/// User ID | ||
#[clap(short, long, value_parser)] | ||
user_id: u64, | ||
|
||
/// Thumbnail size | ||
#[clap(short, long, value_enum)] | ||
size: Option<UserThumbnailSize>, | ||
|
||
/// Thumbnail format | ||
#[clap(short, long, value_enum)] | ||
format: Option<UserThumbnailFormat>, | ||
|
||
/// Thumbnail shape | ||
#[clap(short = 'S', long, value_enum)] | ||
shape: Option<UserThumbnailShape>, | ||
|
||
/// Pretty-print the JSON response | ||
#[clap(short, long, value_parser, default_value_t = false)] | ||
pretty: bool, | ||
|
||
/// Roblox Open Cloud API Key | ||
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")] | ||
api_key: String, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
pub struct User { | ||
#[clap(subcommand)] | ||
command: UserCommands, | ||
} | ||
|
||
impl User { | ||
pub async fn run(self) -> anyhow::Result<Option<String>> { | ||
match self.command { | ||
UserCommands::Get { | ||
user_id, | ||
pretty, | ||
api_key, | ||
} => { | ||
let client = Client::new(&api_key); | ||
let user_client = client.user(); | ||
let res = user_client.get_user(RobloxUserId(user_id)).await; | ||
match res { | ||
Ok(universe_info) => { | ||
let r = if pretty { | ||
serde_json::to_string_pretty(&universe_info)? | ||
} else { | ||
serde_json::to_string(&universe_info)? | ||
}; | ||
Ok(Some(r)) | ||
} | ||
Err(err) => Err(anyhow::anyhow!(err)), | ||
} | ||
} | ||
|
||
UserCommands::Thumbnail { | ||
user_id, | ||
size, | ||
format, | ||
shape, | ||
pretty, | ||
api_key, | ||
} => { | ||
let client = Client::new(&api_key); | ||
let user_client = client.user(); | ||
let res = user_client | ||
.generate_thumbnail(RobloxUserId(user_id), size, format, shape) | ||
.await; | ||
match res { | ||
Ok(universe_info) => { | ||
let r = if pretty { | ||
serde_json::to_string_pretty(&universe_info)? | ||
} else { | ||
serde_json::to_string(&universe_info)? | ||
}; | ||
Ok(Some(r)) | ||
} | ||
Err(err) => Err(anyhow::anyhow!(err)), | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.