Skip to content

Commit

Permalink
Merge pull request #45 from Sleitnick/feature/v2-groups
Browse files Browse the repository at this point in the history
v2 Groups
  • Loading branch information
Sleitnick authored Mar 28, 2024
2 parents 90b7ece + b9d49d9 commit bf1627e
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rbxcloud"
version = "0.7.0"
version = "0.8.0"
description = "CLI and SDK for the Roblox Open Cloud APIs"
authors = ["Stephen Leitnick"]
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Possible use-cases:

| | API v2 (Beta) |
| -- | -- |
| :x: | Groups |
| :white_check_mark: | Groups |
| :x: | Universes |
| :x: | Places |
| :x: | Instances |
Expand All @@ -42,7 +42,7 @@ The goal of this project is to support all API endpoints that Roblox provides.
### Aftman
Run the `aftman add` command within your project directory. This will add `rbxcloud` to the project's `aftman.toml` file (or create one if it doesn't yet exist).
```sh
$ aftman add Sleitnick/rbxcloud@0.7.0
$ aftman add Sleitnick/rbxcloud@0.8.0
```

### From Release
Expand All @@ -59,7 +59,7 @@ The library built for the CLI tool is available to use directly in Rust projects
To use `rbxcloud` in a Rust project, simply add `rbxcloud` to the `Cargo.toml` dependency list.
```toml
[dependencies]
rbxcloud = "0.7.0"
rbxcloud = "0.8.0"
```

Alternatively, use `cargo add`.
Expand Down
61 changes: 61 additions & 0 deletions docs/cli/cli-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Group API

## Get Group Info
Get information about a group.
```
Usage: rbxcloud group get [OPTIONS] --group-id <GROUP_ID> --api-key <API_KEY>
Options:
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
-g, --group-id <GROUP_ID> Group ID
-p, --pretty Pretty-print the JSON response
-h, --help Print help
```

### Example
```
$ rbxcloud group get -p -g 12345 -a MY_KEY
```

## Get Group Shout
Get a group's current shout and its metadata.
```
Usage: rbxcloud group shout [OPTIONS] --group-id <GROUP_ID> --api-key <API_KEY>
Options:
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
-g, --group-id <GROUP_ID> Group ID
-p, --pretty Pretty-print the JSON response
-o, --only-message Only return the shout message string
-h, --help Print help
```

### Example
Get a group's shout and its metadata:
```
$ rbxcloud group shout -p -g 12345 -a MY_KEY
```

Get a group's shout message only:
```
$ rbxcloud group shout -p -g 12345 -a MY_KEY --only-message
```

## List Group Roles
List the roles of a given group.
```
Usage: rbxcloud group roles [OPTIONS] --group-id <GROUP_ID> --api-key <API_KEY>
Options:
-g, --group-id <GROUP_ID> Group ID
-p, --pretty Pretty-print the JSON response
-m, --max-page-size <MAX_PAGE_SIZE> Max items returned per page
-n, --next-page-token <NEXT_PAGE_TOKEN> Next page token
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
-h, --help Print help
```

### Example
```
$ rbxcloud group roles -p -g 12345 -a MY_KEY
```
4 changes: 2 additions & 2 deletions docs/cli/cli-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are a few different ways to install the `rbxcloud` CLI.
### [Aftman](https://github.com/LPGhatguy/aftman) <small>(Preferred)</small>
Run the `aftman add` command within your project directory. This will add `rbxcloud` to the project's `aftman.toml` file (or create one if it doesn't yet exist).
```sh
$ aftman add Sleitnick/rbxcloud@0.7.0
$ aftman add Sleitnick/rbxcloud@0.8.0
```

Next, run `aftman install` to install `rbxcloud`.
Expand All @@ -17,7 +17,7 @@ Add `rbxcloud` under the `[tools]` section of your `foreman.toml` file.
```toml
# foreman.toml
[tools]
rbxcloud = { github = "Sleitnick/rbxcloud", version = "0.7.0" }
rbxcloud = { github = "Sleitnick/rbxcloud", version = "0.8.0" }
```

Next, run `foreman install` to install `rbxcloud`.
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/lib-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
To use `rbxcloud` in a Rust project, simply add `rbxcloud` to the `Cargo.toml` dependency list.
```toml
[dependencies]
rbxcloud = "0.7.0"
rbxcloud = "0.8.0"
```

Alternatively, use `cargo add`.
Expand Down
25 changes: 25 additions & 0 deletions examples/group-get-shout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use rbxcloud::rbx::{
error::Error,
v2::{group::GroupId, Client},
};

async fn get_group_shout() -> Result<String, Error> {
// Inputs:
let api_key = "MY_API_KEY";
let group_id = 9876543210;

let client = Client::new(api_key);
let group = client.group(GroupId(group_id));

// Get the shout's content:
group.get_shout().await.map(|r| r.content)
}

#[tokio::main]
async fn main() {
let shout_res = get_group_shout().await;
match shout_res {
Ok(shout) => println!("{shout}"),
Err(e) => eprintln!("{e:?}"),
}
}
196 changes: 196 additions & 0 deletions src/cli/group_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::v2::{group::GroupId, Client};

#[derive(Debug, Subcommand)]
pub enum GroupCommands {
/// Get info about the group
Get {
/// Group ID
#[clap(short, long, value_parser)]
group_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,
},

/// Get the current shout and other metadata
Shout {
/// Group ID
#[clap(short, long, value_parser)]
group_id: u64,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Only return the shout message string
#[clap(short, long, value_parser, default_value_t = false)]
only_message: bool,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},

/// List the roles of a group
Roles {
/// Group ID
#[clap(short, long, value_parser)]
group_id: u64,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Max items returned per page
#[clap(short, long, value_parser)]
max_page_size: Option<u32>,

/// Next page token
#[clap(short, long, value_parser)]
next_page_token: Option<String>,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},

/// List the memberships of a group
Memberships {
/// Group ID
#[clap(short, long, value_parser)]
group_id: u64,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Max items returned per page
#[clap(short, long, value_parser)]
max_page_size: Option<u32>,

/// Filter
#[clap(short, long, value_parser)]
filter: Option<String>,

/// Next page token
#[clap(short, long, value_parser)]
next_page_token: Option<String>,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},
}

#[derive(Debug, Args)]
pub struct Group {
#[clap(subcommand)]
command: GroupCommands,
}

impl Group {
pub async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
GroupCommands::Get {
group_id,
api_key,
pretty,
} => {
let client = Client::new(&api_key);
let group = client.group(GroupId(group_id));
let res = group.get_info().await;
match res {
Ok(group_info) => {
let r = if pretty {
serde_json::to_string_pretty(&group_info)?
} else {
serde_json::to_string(&group_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

GroupCommands::Shout {
group_id,
pretty,
only_message,
api_key,
} => {
let client = Client::new(&api_key);
let group = client.group(GroupId(group_id));
let res = group.get_shout().await;
match res {
Ok(group_info) => {
if only_message {
return Ok(Some(group_info.content));
}
let r = if pretty {
serde_json::to_string_pretty(&group_info)?
} else {
serde_json::to_string(&group_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

GroupCommands::Roles {
group_id,
api_key,
pretty,
max_page_size,
next_page_token,
} => {
let client = Client::new(&api_key);
let group = client.group(GroupId(group_id));
let res = group.list_roles(max_page_size, next_page_token).await;
match res {
Ok(group_info) => {
let r = if pretty {
serde_json::to_string_pretty(&group_info)?
} else {
serde_json::to_string(&group_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

GroupCommands::Memberships {
group_id,
api_key,
pretty,
max_page_size,
next_page_token,
filter,
} => {
let client = Client::new(&api_key);
let group = client.group(GroupId(group_id));
let res = group
.list_memberships(max_page_size, filter, next_page_token)
.await;
match res {
Ok(group_info) => {
let r = if pretty {
serde_json::to_string_pretty(&group_info)?
} else {
serde_json::to_string(&group_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
mod assets_cli;
mod datastore_cli;
mod experience_cli;
mod group_cli;
mod messaging_cli;
mod ordered_datastore_cli;

use clap::{Parser, Subcommand};

use self::{
assets_cli::Assets, datastore_cli::DataStore, experience_cli::Experience,
assets_cli::Assets, datastore_cli::DataStore, experience_cli::Experience, group_cli::Group,
messaging_cli::Messaging, ordered_datastore_cli::OrderedDataStore,
};

Expand All @@ -34,6 +35,9 @@ pub enum Command {

/// Access the Roblox OrderedDataStore API
OrderedDatastore(OrderedDataStore),

/// Access the Roblox Group API
Group(Group),
}

impl Cli {
Expand All @@ -44,6 +48,7 @@ impl Cli {
Command::Messaging(command) => command.run().await,
Command::Datastore(command) => command.run().await,
Command::OrderedDatastore(command) => command.run().await,
Command::Group(command) => command.run().await,
}
}
}
1 change: 1 addition & 0 deletions src/rbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
pub mod error;
pub(crate) mod util;
pub mod v1;
pub mod v2;
Loading

0 comments on commit bf1627e

Please sign in to comment.