From ff1f82ab0f3966dd0d7dc4aa08a09c50926305d2 Mon Sep 17 00:00:00 2001 From: Christian Binzer Date: Sun, 9 Feb 2025 15:25:03 +0100 Subject: [PATCH 1/2] feat(account): Add account details endpoint --- cloudflare-examples/src/main.rs | 29 ++++++++++++++++--- .../src/endpoints/account/account_details.rs | 19 ++++++++++++ cloudflare/src/endpoints/account/mod.rs | 1 + 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 cloudflare/src/endpoints/account/account_details.rs diff --git a/cloudflare-examples/src/main.rs b/cloudflare-examples/src/main.rs index 19d4bac9..58e605fa 100644 --- a/cloudflare-examples/src/main.rs +++ b/cloudflare-examples/src/main.rs @@ -152,6 +152,18 @@ fn list_routes(arg_matches: &ArgMatches, api_client: &HttpApiClient) { print_response_json(response); } +fn account(arg_matches: &ArgMatches, api_client: &HttpApiClient) { + let account_identifier = arg_matches.get_one::("account_identifier"); + let endpoint = account::account_details::AccountDetails { + account_identifier: account_identifier.unwrap(), + }; + if api_client.is_mock() { + add_static_mock(&endpoint); + } + let response = api_client.request(&endpoint); + print_response(response) +} + fn list_accounts(_arg_matches: &ArgMatches, api_client: &HttpApiClient) { let endpoint = account::ListAccounts { params: None }; if api_client.is_mock() { @@ -236,9 +248,9 @@ where endpoint.method().as_str(), format!("/{}", endpoint.path()).as_str(), ) - .with_status(500) - .with_body(serde_json::to_string(&body).unwrap()) - .create(), + .with_status(500) + .with_body(serde_json::to_string(&body).unwrap()) + .create(), ); Box::leak(m); } @@ -250,7 +262,7 @@ fn main() -> Result<(), Box> { Section { args: vec![Arg::new("zone_identifier").required(true)], description: - "A Zone is a domain name along with its subdomains and other identities", + "A Zone is a domain name along with its subdomains and other identities", function: zone, }, ), @@ -282,6 +294,15 @@ fn main() -> Result<(), Box> { function: list_routes, }, ), + ( + "account", + Section { + args: vec![Arg::new("account_identifier").required(true)], + description: + "Get information about a specific account that you are a member of", + function: account, + }, + ), ( "list_accounts", Section { diff --git a/cloudflare/src/endpoints/account/account_details.rs b/cloudflare/src/endpoints/account/account_details.rs new file mode 100644 index 00000000..7984e7e0 --- /dev/null +++ b/cloudflare/src/endpoints/account/account_details.rs @@ -0,0 +1,19 @@ +use crate::endpoints::account::Account; +use crate::framework::endpoint::{EndpointSpec, Method}; + +/// Account Details +/// +#[derive(Debug)] +pub struct AccountDetails<'a> { + pub account_identifier: &'a str, +} + +impl<'a> EndpointSpec for AccountDetails<'a> { + fn method(&self) -> Method { + Method::GET + } + + fn path(&self) -> String { + format!("accounts/{}", self.account_identifier) + } +} diff --git a/cloudflare/src/endpoints/account/mod.rs b/cloudflare/src/endpoints/account/mod.rs index 2954079c..ea84d47a 100644 --- a/cloudflare/src/endpoints/account/mod.rs +++ b/cloudflare/src/endpoints/account/mod.rs @@ -2,6 +2,7 @@ use crate::framework::response::ApiResult; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +pub mod account_details; pub mod list_accounts; pub use list_accounts::ListAccounts; From e21dce6a7b9aced7bb14e76dfd1efbc8e779203b Mon Sep 17 00:00:00 2001 From: Christian Binzer Date: Sun, 9 Feb 2025 16:47:20 +0100 Subject: [PATCH 2/2] chore: Format --- cloudflare-examples/src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cloudflare-examples/src/main.rs b/cloudflare-examples/src/main.rs index 58e605fa..a67697fc 100644 --- a/cloudflare-examples/src/main.rs +++ b/cloudflare-examples/src/main.rs @@ -248,9 +248,9 @@ where endpoint.method().as_str(), format!("/{}", endpoint.path()).as_str(), ) - .with_status(500) - .with_body(serde_json::to_string(&body).unwrap()) - .create(), + .with_status(500) + .with_body(serde_json::to_string(&body).unwrap()) + .create(), ); Box::leak(m); } @@ -262,7 +262,7 @@ fn main() -> Result<(), Box> { Section { args: vec![Arg::new("zone_identifier").required(true)], description: - "A Zone is a domain name along with its subdomains and other identities", + "A Zone is a domain name along with its subdomains and other identities", function: zone, }, ), @@ -298,8 +298,7 @@ fn main() -> Result<(), Box> { "account", Section { args: vec![Arg::new("account_identifier").required(true)], - description: - "Get information about a specific account that you are a member of", + description: "Get information about a specific account that you are a member of", function: account, }, ),