Compare commits
No commits in common. "57e76753f562ac408fb8d890bfd54121a1dc5e1c" and "914db27a98189514d58225fdc1d2fbe061605fe7" have entirely different histories.
57e76753f5
...
914db27a98
5 changed files with 44 additions and 41 deletions
|
@ -34,6 +34,3 @@ serde = { version = "1.0.219", features = ["derive"] }
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
tokio = "1.45.1"
|
tokio = "1.45.1"
|
||||||
url = { version = "2.5.4", features = ["serde"] }
|
url = { version = "2.5.4", features = ["serde"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
all-features = true
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Contains structs, enums and implementations for the main Bunny.net API
|
//! Contains structs, enums and implementations for the main bunny.net API
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub struct BunnyClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BunnyClient {
|
impl BunnyClient {
|
||||||
/// Creates a new Bunny.net API Client using the supplied `api_key`
|
/// Creates a new BunnyClient using the supplied `api_key`
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
||||||
|
@ -44,7 +44,9 @@ impl BunnyClient {
|
||||||
|
|
||||||
let reqwest = RClient::builder().default_headers(headers).build()?;
|
let reqwest = RClient::builder().default_headers(headers).build()?;
|
||||||
|
|
||||||
Ok(Self { reqwest })
|
Ok(Self {
|
||||||
|
reqwest,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Following functions could probably use better naming, the names are currently derived from the titles on the API reference
|
// TODO: Following functions could probably use better naming, the names are currently derived from the titles on the API reference
|
||||||
|
@ -52,12 +54,12 @@ impl BunnyClient {
|
||||||
/// Returns a list of countries and tax rates
|
/// Returns a list of countries and tax rates
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
/// use bunny_api_tokio::{Client, error::Error};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// // Bunny.net api key
|
/// // Bunny.net api key
|
||||||
/// let mut client = BunnyClient::new("api_key").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
///
|
///
|
||||||
/// let countries = client.get_country_list().await?;
|
/// let countries = client.get_country_list().await?;
|
||||||
///
|
///
|
||||||
|
@ -85,12 +87,12 @@ impl BunnyClient {
|
||||||
/// Returns a list of API Keys
|
/// Returns a list of API Keys
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
/// use bunny_api_tokio::{Client, error::Error};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// // Bunny.net api key
|
/// // Bunny.net api key
|
||||||
/// let mut client = BunnyClient::new("api_key").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
///
|
///
|
||||||
/// let api_keys = client.list_api_keys(1, 1000).await?;
|
/// let api_keys = client.list_api_keys(1, 1000).await?;
|
||||||
///
|
///
|
||||||
|
@ -122,12 +124,12 @@ impl BunnyClient {
|
||||||
/// Returns a list of Regions
|
/// Returns a list of Regions
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
/// use bunny_api_tokio::{Client, error::Error};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// // Bunny.net api key
|
/// // Bunny.net api key
|
||||||
/// let mut client = BunnyClient::new("api_key").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
///
|
///
|
||||||
/// let regions = client.region_list().await?;
|
/// let regions = client.region_list().await?;
|
||||||
///
|
///
|
||||||
|
@ -154,12 +156,12 @@ impl BunnyClient {
|
||||||
/// Purges a URL from the cache
|
/// Purges a URL from the cache
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{BunnyClient, error::Error};
|
/// use bunny_api_tokio::{Client, error::Error};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// // Bunny.net api key
|
/// // Bunny.net api key
|
||||||
/// let mut client = BunnyClient::new("api_key").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
///
|
///
|
||||||
/// client.purge_url("https://url_to_purge.com".parse()?, false).await?;
|
/// client.purge_url("https://url_to_purge.com".parse()?, false).await?;
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::error::Error;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use crate::error::Error;
|
||||||
|
|
||||||
/// Endpoints for Edge Storage API
|
/// Endpoints for Edge Storage API
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
//! Edge Storage API
|
//! Edge Storage API
|
||||||
//!
|
//!
|
||||||
//! Contains enums, structs and functions for the Bunny Edge Storage API
|
//! Contains enums, structs and functions for the Bunny Edge Storage API
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use reqwest::{
|
use reqwest::{header::{HeaderMap, HeaderValue}, Client};
|
||||||
Client,
|
|
||||||
header::{HeaderMap, HeaderValue},
|
|
||||||
};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
mod endpoint;
|
mod endpoint;
|
||||||
|
@ -23,7 +20,7 @@ pub struct EdgeStorageClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EdgeStorageClient {
|
impl<'a> EdgeStorageClient {
|
||||||
/// Creates a new EdgeStorageClient
|
/// Creates a new EdgeStorageClient using the supplied `api_key`
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
||||||
|
@ -35,11 +32,7 @@ impl<'a> EdgeStorageClient {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn new<T: AsRef<str>, T1: AsRef<str>>(
|
pub async fn new<T: AsRef<str>, T1: AsRef<str>>(api_key: T, endpoint: Endpoint, storage_zone: T1) -> Result<Self, Error> {
|
||||||
api_key: T,
|
|
||||||
endpoint: Endpoint,
|
|
||||||
storage_zone: T1,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.append("AccessKey", HeaderValue::from_str(api_key.as_ref())?);
|
headers.append("AccessKey", HeaderValue::from_str(api_key.as_ref())?);
|
||||||
headers.append("accept", HeaderValue::from_str("application/json")?);
|
headers.append("accept", HeaderValue::from_str("application/json")?);
|
||||||
|
@ -51,23 +44,28 @@ impl<'a> EdgeStorageClient {
|
||||||
|
|
||||||
let url = endpoint.join(&storage_zone)?;
|
let url = endpoint.join(&storage_zone)?;
|
||||||
|
|
||||||
Ok(Self { url, reqwest })
|
Ok(Self {
|
||||||
|
url,
|
||||||
|
reqwest,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads a file to the Storage Zone
|
/// Uploads a file to the Storage Zone
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
/// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint};
|
||||||
/// use tokio::fs;
|
/// use tokio::fs;
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
|
///
|
||||||
|
/// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
||||||
///
|
///
|
||||||
/// let file_bytes = fs::read("path/to/file.png").await.unwrap();
|
/// let file_bytes = fs::read("path/to/file.png").await.unwrap();
|
||||||
///
|
///
|
||||||
/// // Will put a file in STORAGE_ZONE/images/file.png
|
/// // Will put a file in STORAGE_ZONE/images/file.png
|
||||||
/// client.upload("/images/file.png", file_bytes.into()).await?;
|
/// client.storage.upload("/images/file.png", file_bytes.into()).await?;
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
|
@ -93,16 +91,18 @@ impl<'a> EdgeStorageClient {
|
||||||
/// Downloads a file from the Storage Zone
|
/// Downloads a file from the Storage Zone
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
/// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint};
|
||||||
/// use tokio::fs;
|
/// use tokio::fs;
|
||||||
/// use tokio::io::AsyncWriteExt;
|
/// use tokio::io::AsyncWriteExt;
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
|
///
|
||||||
|
/// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
||||||
///
|
///
|
||||||
/// // Will download the file STORAGE_ZONE/images/file.png
|
/// // Will download the file STORAGE_ZONE/images/file.png
|
||||||
/// let contents = client.download("/images/file.png").await?;
|
/// let contents = client.storage.download("/images/file.png").await?;
|
||||||
///
|
///
|
||||||
/// let mut file = fs::File::create("file.png").await.unwrap();
|
/// let mut file = fs::File::create("file.png").await.unwrap();
|
||||||
/// file.write_all(&contents).await.unwrap();
|
/// file.write_all(&contents).await.unwrap();
|
||||||
|
@ -130,14 +130,16 @@ impl<'a> EdgeStorageClient {
|
||||||
/// Deletes a file from the Storage Zone
|
/// Deletes a file from the Storage Zone
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
/// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
|
///
|
||||||
|
/// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
||||||
///
|
///
|
||||||
/// // Will delete the file STORAGE_ZONE/images/file.png
|
/// // Will delete the file STORAGE_ZONE/images/file.png
|
||||||
/// client.delete("/images/file.png").await?;
|
/// client.storage.delete("/images/file.png").await?;
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
|
@ -161,14 +163,16 @@ impl<'a> EdgeStorageClient {
|
||||||
/// Lists files on the Storage Zone
|
/// Lists files on the Storage Zone
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint};
|
/// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), Error> {
|
/// async fn main() -> Result<(), Error> {
|
||||||
/// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
/// let mut client = Client::new("api_key").await?;
|
||||||
|
///
|
||||||
|
/// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?;
|
||||||
///
|
///
|
||||||
/// // Will list the files in STORAGE_ZONE/images/
|
/// // Will list the files in STORAGE_ZONE/images/
|
||||||
/// let files = client.list("/images/").await?;
|
/// let files = client.storage.list("/images/").await?;
|
||||||
///
|
///
|
||||||
/// println!("{:#?}", files);
|
/// println!("{:#?}", files);
|
||||||
///
|
///
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
//! 2. Start coding
|
//! 2. Start coding
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use bunny_api_tokio::{BunnyClient, error::Error};
|
//! use bunny_api_tokio::{Client, error::Error};
|
||||||
//!
|
//!
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
//! async fn main() -> Result<(), Error> {
|
//! async fn main() -> Result<(), Error> {
|
||||||
//! let mut client = BunnyClient::new("api_key").await?;
|
//! let mut client = Client::new("api_key").await?;
|
||||||
//!
|
//!
|
||||||
//! Ok(())
|
//! Ok(())
|
||||||
//! }
|
//! }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue