Skip to content

Commit

Permalink
Merge pull request #52 from Chloe-Woahie/dev-main
Browse files Browse the repository at this point in the history
v0.25.0
  • Loading branch information
fekie authored May 19, 2023
2 parents ae2fdf1 + 7c2f58b commit b35ca84
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
name = "roboat"
readme = "README.md"
repository = "https://github.com/Chloe-Woahie/roboat"
version = "0.24.0"
version = "0.25.0"

[dependencies]
reqwest = { version = "0.11.14", default-features=false, features = ["rustls-tls", "json"] }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Documentation can be found [here](https://docs.rs/roboat/).
* Private Messages API - [`privatemessages.roblox.com/*`]
- Fetch Messages - [`Client::messages`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.messages)
* Thumbnails API - [`thumbnails.roblox.com/*`]
- Fetch Asset Thumbnail URL - [`Client::asset_thumbnail_url`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.asset_thumbnail_url)
- Fetch Asset Thumbnail URL Bulk - [`Client::asset_thumbnail_url_bulk`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.asset_thumbnail_url_bulk)
* Trades API - [`trades.roblox.com/*`]
- Fetch Trades List - [`Client::trades`](https://docs.rs/roboat/latest/roboat/struct.Client.html#method.trades)
Expand All @@ -74,7 +75,7 @@ Alternatively, you can add a specific version of roboat to your project by addin

```toml
[dependencies]
roboat = "0.24.0"
roboat = "0.25.0"
```

# Quick Start Examples
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch_item_thumbnails.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use roboat::thumbnails::ThumbnailAssetSize;
use roboat::thumbnails::AssetThumbnailSize;
use roboat::ClientBuilder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let asset_id_1 = 20418400;
let asset_id_2 = 12660007639;

let size = ThumbnailAssetSize::S420x420;
let size = AssetThumbnailSize::S420x420;

let client = ClientBuilder::new().build();
let urls = client
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
//! * Private Messages API
//! - Fetch Messages - [`Client::messages`]
//! * Thumbnails API
//! - Fetch Asset Thumbnail URL - [`Client::asset_thumbnail_url`]
//! - Fetch Asset Thumbnail URL Bulk - [`Client::asset_thumbnail_url_bulk`]
//! * Trades API
//! - Fetch Trades List - [`Client::trades`]
Expand Down
52 changes: 46 additions & 6 deletions src/thumbnails/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const THUMBNAIL_API_URL: &str = "https://thumbnails.roblox.com/v1/batch";
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, Copy,
)]
pub enum ThumbnailAssetSize {
pub enum AssetThumbnailSize {
S30x30,
S42x42,
S50x50,
Expand Down Expand Up @@ -41,7 +41,7 @@ pub enum ThumbnailAssetSize {
S1200x80,
}

impl fmt::Display for ThumbnailAssetSize {
impl fmt::Display for AssetThumbnailSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::S30x30 => write!(f, "30x30"),
Expand Down Expand Up @@ -73,7 +73,7 @@ impl fmt::Display for ThumbnailAssetSize {
}

impl Client {
/// Fetches multiple asset thumbnails of a specified size using <https://users.roblox.com/v1/users/search>.
/// Fetches multiple asset thumbnails of a specified size using <https://thumbnails.roblox.com/v1/batch>.
///
/// # Notes
/// * Does not require a valid roblosecurity.
Expand All @@ -85,13 +85,13 @@ impl Client {
///
/// ```no_run
/// use roboat::ClientBuilder;
/// use roboat::thumbnails::ThumbnailAssetSize;
/// use roboat::thumbnails::AssetThumbnailSize;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = ClientBuilder::new().build();
///
/// let size = ThumbnailAssetSize::S420x420;
/// let size = AssetThumbnailSize::S420x420;
/// let asset_id_1 = 20418400;
/// let asset_id_2 = 12660007639;
///
Expand All @@ -108,7 +108,7 @@ impl Client {
pub async fn asset_thumbnail_url_bulk(
&self,
asset_ids: Vec<u64>,
size: ThumbnailAssetSize,
size: AssetThumbnailSize,
) -> Result<Vec<String>, RoboatError> {
let url = THUMBNAIL_API_URL;

Expand Down Expand Up @@ -143,6 +143,46 @@ impl Client {

Ok(urls)
}

/// Fetches an asset thumbnail of a specified size using <https://thumbnails.roblox.com/v1/batch>.
///
/// # Notes
/// * Does not require a valid roblosecurity.
///
/// # Errors
/// * All errors under [Standard Errors](#standard-errors).
///
/// # Example
///
/// ```no_run
/// use roboat::ClientBuilder;
/// use roboat::thumbnails::AssetThumbnailSize;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = ClientBuilder::new().build();
///
/// let size = AssetThumbnailSize::S420x420;
/// let asset_id = 20418400;
///
/// let url = client
/// .asset_thumbnail_url(asset_id, size)
/// .await?;
///
/// println!("Asset {} thumbnail url: {}", asset_id, url);
///
/// # Ok(())
/// # }
/// ```
pub async fn asset_thumbnail_url(
&self,
asset_id: u64,
size: AssetThumbnailSize,
) -> Result<String, RoboatError> {
let urls = self.asset_thumbnail_url_bulk(vec![asset_id], size).await?;
let url = urls.get(0).ok_or(RoboatError::MalformedResponse)?;
Ok(url.to_owned())
}
}

/// Makes sure that the url datas are in the same order as the arguments.
Expand Down

0 comments on commit b35ca84

Please sign in to comment.