Skip to content

Commit

Permalink
Merge pull request #58 from jackTabsCode/place-api
Browse files Browse the repository at this point in the history
Support Place API
  • Loading branch information
Sleitnick authored Jun 30, 2024
2 parents 328a2c0 + 0da4b83 commit 5896b14
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Possible use-cases:
| -- | -- |
| :white_check_mark: | Groups |
| :white_check_mark: | Universes |
| :x: | Places |
| :white_check_mark: | Places |
| :x: | Instances |
| :white_check_mark: | Subscriptions |
| :x: | Inventory |
Expand Down
72 changes: 72 additions & 0 deletions docs/cli/cli-place.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Universe API

## Getting Place Info
```
Usage: rbxcloud place get [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --api-key <API_KEY>
Options:
-u, --universe-id <UNIVERSE_ID> Universe ID
-p, --place-id <PLACE_ID> Place ID
--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 place get -u 12345 -p 67890 -a MY_KEY
```

## Updating Name
```
Usage: rbxcloud place update-name [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --name <NAME> --api-key <API_KEY>
Options:
-u, --universe-id <UNIVERSE_ID> Universe ID
-p, --place-id <PLACE_ID> Place ID
-n, --name <NAME> New Place name
--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 place update-name -n "Place Name" -u 12345 -p 67890 -a MY_KEY
```

## Updating Description
```
Usage: rbxcloud place update-description [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --description <DESCRIPTION> --api-key <API_KEY>
Options:
-u, --universe-id <UNIVERSE_ID> Universe ID
-p, --place-id <PLACE_ID> Place ID
-d, --description <DESCRIPTION> New Place description
--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 universe update-description -n "Place description here." -u 12345 -p 67890 -a MY_KEY
```

## Updating Server Size
```
Usage: rbxcloud place update-server-size [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --server-size <SERVER_SIZE> --api-key <API_KEY>
Options:
-u, --universe-id <UNIVERSE_ID> Universe ID
-p, --place-id <PLACE_ID> Place ID
-s, --server-size <SERVER_SIZE> New Place server size
--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 place update-server-size -s 700 -u 12345 -p 67890 -a MY_KEY
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ nav:
- Group: cli/cli-group.md
- Subscription: cli/cli-subscription.md
- Notification: cli/cli-notification.md
- Place: cli/cli-place.md
- Universe: cli/cli-universe.md
- User: cli/cli-user.md
- Rust Lib:
Expand Down
7 changes: 6 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod group_cli;
mod messaging_cli;
mod notification_cli;
mod ordered_datastore_cli;
mod place_cli;
mod subscription_cli;
mod universe_cli;
mod user_cli;
Expand All @@ -16,7 +17,7 @@ use user_cli::User;
use self::{
assets_cli::Assets, datastore_cli::DataStore, experience_cli::Experience, group_cli::Group,
messaging_cli::Messaging, notification_cli::Notification,
ordered_datastore_cli::OrderedDataStore, subscription_cli::Subscription,
ordered_datastore_cli::OrderedDataStore, place_cli::Place, subscription_cli::Subscription,
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -52,6 +53,9 @@ pub enum Command {
/// Access the Roblox Notification API
Notification(Notification),

/// Access the Roblox Place API
Place(Place),

/// Access the Roblox Universe API
Universe(Universe),

Expand All @@ -70,6 +74,7 @@ impl Cli {
Command::Group(command) => command.run().await,
Command::Subscription(command) => command.run().await,
Command::Notification(command) => command.run().await,
Command::Place(command) => command.run().await,
Command::Universe(command) => command.run().await,
Command::User(command) => command.run().await,
}
Expand Down
236 changes: 236 additions & 0 deletions src/cli/place_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::{
types::{PlaceId, UniverseId},
v2::{place::UpdatePlaceInfo, Client},
};

#[derive(Debug, Subcommand)]
pub enum PlaceCommands {
/// Get Place information
Get {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short, long, value_parser)]
place_id: u64,

/// Pretty-print the JSON response
#[clap(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,
},

/// Update Place name
UpdateName {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short, long, value_parser)]
place_id: u64,

/// New Place name
#[clap(short, long, value_parser)]
name: String,

/// Pretty-print the JSON response
#[clap(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,
},

/// Update Place description
UpdateDescription {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short, long, value_parser)]
place_id: u64,

/// New Place description
#[clap(short, long, value_parser)]
description: String,

/// Pretty-print the JSON response
#[clap(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,
},

/// Update Place server size
UpdateServerSize {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short, long, value_parser)]
place_id: u64,

/// New Place server size
#[clap(short, long, value_parser)]
server_size: u32,

/// Pretty-print the JSON response
#[clap(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 Place {
#[clap(subcommand)]
command: PlaceCommands,
}

impl Place {
pub async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
PlaceCommands::Get {
universe_id,
place_id,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let place_client = client.place(UniverseId(universe_id), PlaceId(place_id));
let res = place_client.get().await;
match res {
Ok(place_info) => {
let r = if pretty {
serde_json::to_string_pretty(&place_info)?
} else {
serde_json::to_string(&place_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

PlaceCommands::UpdateName {
universe_id,
place_id,
name,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let place_client = client.place(UniverseId(universe_id), PlaceId(place_id));
let res = place_client
.update(
"displayName".to_string(),
UpdatePlaceInfo {
path: None,
create_time: None,
update_time: None,
display_name: Some(name),
description: None,
server_size: None,
},
)
.await;
match res {
Ok(place_info) => {
let r = if pretty {
serde_json::to_string_pretty(&place_info)?
} else {
serde_json::to_string(&place_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

PlaceCommands::UpdateDescription {
universe_id,
place_id,
description,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let place_client = client.place(UniverseId(universe_id), PlaceId(place_id));
let res = place_client
.update(
"description".to_string(),
UpdatePlaceInfo {
path: None,
create_time: None,
update_time: None,
display_name: None,
description: Some(description),
server_size: None,
},
)
.await;
match res {
Ok(place_info) => {
let r = if pretty {
serde_json::to_string_pretty(&place_info)?
} else {
serde_json::to_string(&place_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

PlaceCommands::UpdateServerSize {
universe_id,
place_id,
server_size,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let place_client = client.place(UniverseId(universe_id), PlaceId(place_id));
let res = place_client
.update(
"serverSize".to_string(),
UpdatePlaceInfo {
path: None,
create_time: None,
update_time: None,
display_name: None,
description: None,
server_size: Some(server_size),
},
)
.await;

match res {
Ok(place_info) => {
let r = if pretty {
serde_json::to_string_pretty(&place_info)?
} else {
serde_json::to_string(&place_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}
}
}
}
Loading

0 comments on commit 5896b14

Please sign in to comment.