Skip to content
Closed
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: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Check formatting
run: cargo fmt --all -- --check
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
3 changes: 1 addition & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE};
use reqwest::header::{AUTHORIZATION, CONTENT_TYPE, HeaderMap, HeaderValue};
use serde_json::Value;

use crate::config::{Config, OAuthConfig};
Expand Down Expand Up @@ -53,7 +53,6 @@ impl ApiClient {
}
Ok(body)
}

}

/// HTTP client for the OAuth management API (Basic auth).
Expand Down
12 changes: 3 additions & 9 deletions src/commands/automotive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ pub async fn execute(cmd: &AutomotiveCommands, client: &ApiClient) -> Result<()>
let base = client.base_url(PROD, SANDBOX);
match cmd {
AutomotiveCommands::Car { plate } => {
let resp = client
.get(&format!("{}/IT-car/{}", base, plate))
.await?;
let resp = client.get(&format!("{}/IT-car/{}", base, plate)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
AutomotiveCommands::Bike { plate } => {
let resp = client
.get(&format!("{}/IT-bike/{}", base, plate))
.await?;
let resp = client.get(&format!("{}/IT-bike/{}", base, plate)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
AutomotiveCommands::Insurance { plate } => {
Expand All @@ -56,9 +52,7 @@ pub async fn execute(cmd: &AutomotiveCommands, client: &ApiClient) -> Result<()>
println!("{}", serde_json::to_string_pretty(&resp)?);
}
AutomotiveCommands::CheckId { id } => {
let resp = client
.get(&format!("{}/check_id/{}", base, id))
.await?;
let resp = client.get(&format!("{}/check_id/{}", base, id)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/cadastre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ pub async fn execute(cmd: &CadastreCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CadastreCommands::VisuraCatastale => {
let resp = client
.get(&format!("{}/visura_catastale", base))
.await?;
let resp = client.get(&format!("{}/visura_catastale", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CadastreCommands::GetVisuraCatastale { id } => {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/chamber_of_commerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub async fn execute(cmd: &ChamberOfCommerceCommands, client: &ApiClient) -> Res
println!("{}", serde_json::to_string_pretty(&resp)?);
}
ChamberOfCommerceCommands::Get { code } => {
let resp = client
.get(&format!("{}/impresa/{}", base, code))
.await?;
let resp = client.get(&format!("{}/impresa/{}", base, code)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
ChamberOfCommerceCommands::OrdinariaImpresaIndividuale => {
Expand All @@ -56,9 +54,7 @@ pub async fn execute(cmd: &ChamberOfCommerceCommands, client: &ApiClient) -> Res
println!("{}", serde_json::to_string_pretty(&resp)?);
}
ChamberOfCommerceCommands::SociAttivi => {
let resp = client
.get(&format!("{}/soci-attivi", base))
.await?;
let resp = client.get(&format!("{}/soci-attivi", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
20 changes: 5 additions & 15 deletions src/commands/company.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub async fn execute(cmd: &CompanyCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Start { code } => {
let resp = client
.get(&format!("{}/IT-start/{}", base, code))
.await?;
let resp = client.get(&format!("{}/IT-start/{}", base, code)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Advanced { code } => {
Expand All @@ -76,9 +74,7 @@ pub async fn execute(cmd: &CompanyCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Pec { code } => {
let resp = client
.get(&format!("{}/IT-pec/{}", base, code))
.await?;
let resp = client.get(&format!("{}/IT-pec/{}", base, code)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Shareholders { code } => {
Expand All @@ -88,21 +84,15 @@ pub async fn execute(cmd: &CompanyCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Address { code } => {
let resp = client
.get(&format!("{}/IT-address/{}", base, code))
.await?;
let resp = client.get(&format!("{}/IT-address/{}", base, code)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Sdicode { code } => {
let resp = client
.get(&format!("{}/IT-sdicode/{}", base, code))
.await?;
let resp = client.get(&format!("{}/IT-sdicode/{}", base, code)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
CompanyCommands::Legalforms => {
let resp = client
.get(&format!("{}/IT-legalforms", base))
.await?;
let resp = client.get(&format!("{}/IT-legalforms", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/commands/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ pub async fn execute(cmd: &DomainsCommands, client: &ApiClient) -> Result<()> {
let base = client.base_url(PROD, SANDBOX);
match cmd {
DomainsCommands::Check { domain } => {
let resp = client
.get(&format!("{}/check/{}", base, domain))
.await?;
let resp = client.get(&format!("{}/check/{}", base, domain)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
DomainsCommands::List => {
let resp = client.get(&format!("{}/domain", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
DomainsCommands::Get { domain } => {
let resp = client
.get(&format!("{}/domain/{}", base, domain))
.await?;
let resp = client.get(&format!("{}/domain/{}", base, domain)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
DomainsCommands::Contacts => {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/massive_rem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ pub async fn execute(cmd: &MassiveRemCommands, client: &ApiClient) -> Result<()>
println!("{}", serde_json::to_string_pretty(&resp)?);
}
MassiveRemCommands::Quota { mailbox } => {
let resp = client
.get(&format!("{}/quota/{}", base, mailbox))
.await?;
let resp = client.get(&format!("{}/quota/{}", base, mailbox)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
pub mod token;
pub mod oauthv2;
pub mod esignature;
pub mod ai;
pub mod sms;
pub mod trust;
pub mod exchange_rate;
pub mod risk;
pub mod automotive;
pub mod sdi;
pub mod time_stamping;
pub mod real_estate;
pub mod cadastre;
pub mod certified_email;
pub mod chamber_of_commerce;
pub mod company;
pub mod docuengine;
pub mod domains;
pub mod esignature;
pub mod exchange_rate;
pub mod geocoding;
pub mod invoice;
pub mod info;
pub mod invoice;
pub mod massive_rem;
pub mod oauthv2;
pub mod paying_bills;
pub mod pdf;
pub mod postal_service;
pub mod company;
pub mod chamber_of_commerce;
pub mod docuengine;
pub mod real_estate;
pub mod risk;
pub mod sdi;
pub mod sms;
pub mod time_stamping;
pub mod token;
pub mod trust;
pub mod visengine;
pub mod zip_codes;
28 changes: 22 additions & 6 deletions src/commands/oauthv2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Subcommand;
use serde_json::{json, Map, Value};
use serde_json::{Map, Value, json};

use crate::client::OAuthV2Client;
use crate::scopes;
Expand Down Expand Up @@ -260,7 +260,9 @@ pub async fn execute(cmd: &Oauthv2Commands, client: &OAuthV2Client) -> Result<()
body.insert("limits".to_string(), limits);
}

let resp = client.post(&format!("{}/tokens", base), &Value::Object(body)).await?;
let resp = client
.post(&format!("{}/tokens", base), &Value::Object(body))
.await?;
print_json(&resp)?;
}
Oauthv2TokenCommands::List { limit, skip } => {
Expand Down Expand Up @@ -336,7 +338,11 @@ pub async fn execute(cmd: &Oauthv2Commands, client: &OAuthV2Client) -> Result<()
}
},
Oauthv2Commands::Errors { command } => match command {
Oauthv2ErrorCommands::List { scopes, limit, skip } => {
Oauthv2ErrorCommands::List {
scopes,
limit,
skip,
} => {
let mut params = pagination_params(*limit, *skip);
push_optional(&mut params, "scopes", scopes.clone());
let resp = client
Expand All @@ -362,7 +368,9 @@ pub async fn execute(cmd: &Oauthv2Commands, client: &OAuthV2Client) -> Result<()
Oauthv2StatsCommands::Overview { date } => {
let mut params = Vec::new();
push_optional(&mut params, "date", date.clone());
let resp = client.get_query(&format!("{}/stats", base), &params).await?;
let resp = client
.get_query(&format!("{}/stats", base), &params)
.await?;
print_json(&resp)?;
}
Oauthv2StatsCommands::Apis { date } => {
Expand Down Expand Up @@ -391,7 +399,11 @@ pub async fn execute(cmd: &Oauthv2Commands, client: &OAuthV2Client) -> Result<()
}
},
Oauthv2Commands::Subscriptions { command } => match command {
Oauthv2SubscriptionCommands::List { scopes, limit, skip } => {
Oauthv2SubscriptionCommands::List {
scopes,
limit,
skip,
} => {
let mut params = pagination_params(*limit, *skip);
push_optional(&mut params, "scopes", scopes.clone());
let resp = client
Expand All @@ -407,7 +419,11 @@ pub async fn execute(cmd: &Oauthv2Commands, client: &OAuthV2Client) -> Result<()
}
},
Oauthv2Commands::Callbacks { command } => match command {
Oauthv2CallbackCommands::List { scopes, limit, skip } => {
Oauthv2CallbackCommands::List {
scopes,
limit,
skip,
} => {
let mut params = pagination_params(*limit, *skip);
push_optional(&mut params, "scopes", scopes.clone());
let resp = client
Expand Down
4 changes: 1 addition & 3 deletions src/commands/paying_bills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ pub async fn execute(cmd: &PayingBillsCommands, client: &ApiClient) -> Result<()
println!("{}", serde_json::to_string_pretty(&resp)?);
}
PayingBillsCommands::Receipt { id } => {
let resp = client
.get(&format!("{}/pay/{}/ricevuta", base, id))
.await?;
let resp = client.get(&format!("{}/pay/{}/ricevuta", base, id)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/commands/risk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ pub async fn execute(cmd: &RiskCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
RiskCommands::ReportPersona => {
let resp = client
.get(&format!("{}/IT-report-persona", base))
.await?;
let resp = client.get(&format!("{}/IT-report-persona", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
RiskCommands::GetReportPersona { id } => {
Expand All @@ -78,9 +76,7 @@ pub async fn execute(cmd: &RiskCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
RiskCommands::ReportAzienda => {
let resp = client
.get(&format!("{}/IT-report-azienda", base))
.await?;
let resp = client.get(&format!("{}/IT-report-azienda", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
RiskCommands::GetReportAzienda { id } => {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/sdi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ pub async fn execute(cmd: &SdiCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
SdiCommands::Get { uuid } => {
let resp = client
.get(&format!("{}/invoices/{}", base, uuid))
.await?;
let resp = client.get(&format!("{}/invoices/{}", base, uuid)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
SdiCommands::Download { uuid } => {
Expand All @@ -66,9 +64,7 @@ pub async fn execute(cmd: &SdiCommands, client: &ApiClient) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
}
SdiCommands::ApiConfigurations => {
let resp = client
.get(&format!("{}/api_configurations", base))
.await?;
let resp = client.get(&format!("{}/api_configurations", base)).await?;
println!("{}", serde_json::to_string_pretty(&resp)?);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/commands/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub enum TokenCommands {
pub async fn execute(cmd: &TokenCommands, client: &OAuthClient) -> Result<()> {
let base = client.base_url();
match cmd {
TokenCommands::Create { scopes: scopes_input } => {
TokenCommands::Create {
scopes: scopes_input,
} => {
// Fetch all available scopes to expand aliases
let all_scopes = fetch_all_scopes(client).await?;
let expanded = scopes::expand_aliases(scopes_input, &all_scopes, client.sandbox);
Expand Down
Loading