Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions #46

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.8.0"
version = "0.9.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 @@ -29,7 +29,7 @@ Possible use-cases:
| :x: | Universes |
| :x: | Places |
| :x: | Instances |
| :x: | Subscriptions |
| :white_check_mark: | Subscriptions |
| :x: | Inventory |
| :x: | User Notifications |

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.8.0
$ aftman add Sleitnick/rbxcloud@0.9.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.8.0"
rbxcloud = "0.9.0"
```

Alternatively, use `cargo add`.
Expand Down
5 changes: 5 additions & 0 deletions docs/cli/cli-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ Options:
-n, --next-page-token <NEXT_PAGE_TOKEN> Next page token
-h, --help Print help
```

### Example
```
$ rbxcloud group memberships -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.8.0
$ aftman add Sleitnick/rbxcloud@0.9.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.8.0" }
rbxcloud = { github = "Sleitnick/rbxcloud", version = "0.9.0" }
```

Next, run `foreman install` to install `rbxcloud`.
Expand Down
20 changes: 20 additions & 0 deletions docs/cli/cli-subscription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Subscription API

## Getting Subscription Info
```
Usage: rbxcloud.exe subscription get [OPTIONS] --universe-id <UNIVERSE_ID> --product <PRODUCT> --subscription <SUBSCRIPTION> --api-key <API_KEY>

Options:
-u, --universe-id <UNIVERSE_ID> Universe ID
-S, --product <PRODUCT> Subscription product ID
-s, --subscription <SUBSCRIPTION> Subscription ID
-v, --view <VIEW> View type [possible values: basic, full]
-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 subscription get -p -u 12345 -S 1234 -s 5678 -a MY_KEY
```
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.8.0"
rbxcloud = "0.9.0"
```

Alternatively, use `cargo add`.
Expand Down
5 changes: 4 additions & 1 deletion examples/datastore-get-entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use rbxcloud::rbx::v1::{DataStoreGetEntry, RbxCloud, UniverseId};
use rbxcloud::rbx::{
types::UniverseId,
v1::{DataStoreGetEntry, RbxCloud},
};

#[tokio::main]
async fn main() {
Expand Down
5 changes: 1 addition & 4 deletions examples/group-get-shout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use rbxcloud::rbx::{
error::Error,
v2::{group::GroupId, Client},
};
use rbxcloud::rbx::{error::Error, types::GroupId, v2::Client};

async fn get_group_shout() -> Result<String, Error> {
// Inputs:
Expand Down
5 changes: 1 addition & 4 deletions examples/publish-message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use rbxcloud::rbx::{
error::Error,
v1::{RbxCloud, UniverseId},
};
use rbxcloud::rbx::{error::Error, types::UniverseId, v1::RbxCloud};

async fn publish_message() -> Result<(), Error> {
// Inputs:
Expand Down
5 changes: 4 additions & 1 deletion examples/publish-place.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use rbxcloud::rbx::v1::{PlaceId, PublishVersionType, RbxCloud, UniverseId};
use rbxcloud::rbx::{
types::{PlaceId, UniverseId},
v1::{PublishVersionType, RbxCloud},
};

#[tokio::main]
async fn main() {
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nav:
- DataStore: cli/cli-datastore.md
- OrderedDataStore: cli/cli-ordered-datastore.md
- Group: cli/cli-group.md
- Subscription: cli/cli-subscription.md
- Rust Lib:
- Install: lib/lib-install.md

Expand Down
11 changes: 7 additions & 4 deletions src/cli/datastore_cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use clap::{Args, Subcommand, ValueEnum};

use rbxcloud::rbx::v1::{
DataStoreDeleteEntry, DataStoreGetEntry, DataStoreGetEntryVersion, DataStoreIncrementEntry,
DataStoreListEntries, DataStoreListEntryVersions, DataStoreListStores, DataStoreSetEntry,
RbxCloud, ReturnLimit, RobloxUserId, UniverseId,
use rbxcloud::rbx::{
types::{ReturnLimit, RobloxUserId, UniverseId},
v1::{
DataStoreDeleteEntry, DataStoreGetEntry, DataStoreGetEntryVersion, DataStoreIncrementEntry,
DataStoreListEntries, DataStoreListEntryVersions, DataStoreListStores, DataStoreSetEntry,
RbxCloud,
},
};

#[derive(Debug, Subcommand)]
Expand Down
5 changes: 4 additions & 1 deletion src/cli/experience_cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use clap::{Args, Subcommand, ValueEnum};

use rbxcloud::rbx::v1::{PlaceId, PublishVersionType, RbxCloud, UniverseId};
use rbxcloud::rbx::{
types::{PlaceId, UniverseId},
v1::{PublishVersionType, RbxCloud},
};

#[derive(Debug, Subcommand)]
pub enum ExperienceCommands {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/group_cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::v2::{group::GroupId, Client};
use rbxcloud::rbx::{types::GroupId, v2::Client};

#[derive(Debug, Subcommand)]
pub enum GroupCommands {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/messaging_cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Args, Subcommand};

use rbxcloud::rbx::v1::{RbxCloud, UniverseId};
use rbxcloud::rbx::{types::UniverseId, v1::RbxCloud};

#[derive(Debug, Subcommand)]
pub enum MessagingCommands {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ mod experience_cli;
mod group_cli;
mod messaging_cli;
mod ordered_datastore_cli;
mod subscription_cli;

use clap::{Parser, Subcommand};

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

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -38,6 +40,9 @@ pub enum Command {

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

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

impl Cli {
Expand All @@ -49,6 +54,7 @@ impl Cli {
Command::Datastore(command) => command.run().await,
Command::OrderedDatastore(command) => command.run().await,
Command::Group(command) => command.run().await,
Command::Subscription(command) => command.run().await,
}
}
}
9 changes: 6 additions & 3 deletions src/cli/ordered_datastore_cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::v1::{
OrderedDataStoreCreateEntry, OrderedDataStoreEntry, OrderedDataStoreIncrementEntry,
OrderedDataStoreListEntries, OrderedDataStoreUpdateEntry, RbxCloud, UniverseId,
use rbxcloud::rbx::{
types::UniverseId,
v1::{
OrderedDataStoreCreateEntry, OrderedDataStoreEntry, OrderedDataStoreIncrementEntry,
OrderedDataStoreListEntries, OrderedDataStoreUpdateEntry, RbxCloud,
},
};

#[derive(Debug, Subcommand)]
Expand Down
73 changes: 73 additions & 0 deletions src/cli/subscription_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::{
types::UniverseId,
v2::{subscription::SubscriptionView, Client},
};

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

/// Subscription product ID
#[clap(short = 'S', long, value_parser)]
product: String,

/// Subscription ID
#[clap(short, long, value_parser)]
subscription: String,

/// View type
#[clap(short, long, value_enum)]
view: Option<SubscriptionView>,

/// 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 Subscription {
#[clap(subcommand)]
command: SubscriptionCommands,
}

impl Subscription {
pub async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
SubscriptionCommands::Get {
universe_id,
product,
subscription,
view,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let subscription_client = client.subscription();
let res = subscription_client
.get(UniverseId(universe_id), product, subscription, view)
.await;
match res {
Ok(subscription_info) => {
let r = if pretty {
serde_json::to_string_pretty(&subscription_info)?
} else {
serde_json::to_string(&subscription_info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! Example: Publishing a message.
//! ```rust,no_run
//! use rbxcloud::rbx::{error::Error, v1::{RbxCloud, UniverseId}};
//! use rbxcloud::rbx::{error::Error, v1::RbxCloud, types::UniverseId};
//!
//! async fn publish_message() -> Result<(), Error> {
//! let api_key = "my_api_key";
Expand Down
1 change: 1 addition & 0 deletions src/rbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! Most usage should go through the `RbxCloud` struct.
pub mod error;
pub mod types;
pub(crate) mod util;
pub mod v1;
pub mod v2;
21 changes: 21 additions & 0 deletions src/rbx/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Represents the UniverseId of a Roblox experience.
#[derive(Debug, Clone, Copy)]
pub struct UniverseId(pub u64);

/// Represents the PlaceId of a specific place within a Roblox experience.
#[derive(Debug, Clone, Copy)]
pub struct PlaceId(pub u64);

// Number of items to return.
#[derive(Debug, Clone, Copy)]
pub struct ReturnLimit(pub u64);

/// Represents a Roblox user's ID.
#[derive(Debug, Clone, Copy)]
pub struct RobloxUserId(pub u64);

#[derive(Debug, Clone, Copy)]
pub struct PageSize(pub u64);

#[derive(Debug, Clone, Copy)]
pub struct GroupId(pub u64);
19 changes: 1 addition & 18 deletions src/rbx/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,7 @@ use self::{
},
};

/// Represents the UniverseId of a Roblox experience.
#[derive(Debug, Clone, Copy)]
pub struct UniverseId(pub u64);

/// Represents the PlaceId of a specific place within a Roblox experience.
#[derive(Debug, Clone, Copy)]
pub struct PlaceId(pub u64);

// Number of items to return.
#[derive(Debug, Clone, Copy)]
pub struct ReturnLimit(pub u64);

/// Represents a Roblox user's ID.
#[derive(Debug, Clone, Copy)]
pub struct RobloxUserId(pub u64);

#[derive(Debug, Clone, Copy)]
pub struct PageSize(pub u64);
use super::types::{PageSize, PlaceId, ReturnLimit, RobloxUserId, UniverseId};

impl std::fmt::Display for UniverseId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
5 changes: 1 addition & 4 deletions src/rbx/v2/group.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use serde::{Deserialize, Serialize};

use crate::rbx::{error::Error, util::QueryString};
use crate::rbx::{error::Error, types::GroupId, util::QueryString};

use super::http_err::handle_http_err;

#[derive(Debug, Clone, Copy)]
pub struct GroupId(pub u64);

impl std::fmt::Display for GroupId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
Expand Down
Loading