Skip to content

Commit

Permalink
feat: swap for blocking reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
Mollemoll committed May 3, 2024
1 parent f47fd92 commit c6d6302
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 87 deletions.
84 changes: 12 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ edition = "2021"
[dependencies]
lazy_static = "1.4.0"
regex = "1.10.4"
reqwest = "0.12.4"
reqwest = { version = "0.12.4", features = ["blocking"] }
roxmltree = "0.19.0"
chrono = "0.4.38"

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
6 changes: 2 additions & 4 deletions src/eu_vat/vies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl VIES {
}

impl Verifier for VIES {
async fn make_request(&self, tax_id: TaxId) -> Result<String, VerificationError> {
let client = reqwest::Client::new();
fn make_request(&self, tax_id: &TaxId) -> Result<String, VerificationError> {
let client = reqwest::blocking::Client::new();
let body = ENVELOPE
.replace("{country}", tax_id.tax_country_code())
.replace("{number}", tax_id.local_value());
Expand All @@ -45,10 +45,8 @@ impl Verifier for VIES {
.header("Content-Type", "text/xml")
.body(body)
.send()
.await
.map_err(VerificationError::HttpError)?
.text()
.await
.map_err(VerificationError::HttpError)?;

Ok(res)
Expand Down
15 changes: 7 additions & 8 deletions src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ impl Verification {
}

pub trait Verifier {
async fn verify(&self, tax_id: TaxId) -> Result<Verification, VerificationError> {
let request = self.make_request(tax_id).await?;
fn verify(&self, tax_id: &TaxId) -> Result<Verification, VerificationError> {
let request = self.make_request(tax_id)?;
let verification = self.parse_response(request)?;
Ok(verification)
}

async fn make_request(&self, tax_id: TaxId) -> Result<String, VerificationError>;
fn make_request(&self, tax_id: &TaxId) -> Result<String, VerificationError>;

fn parse_response(&self, _response: String) -> Result<Verification, VerificationError>;
}
Expand All @@ -52,7 +51,7 @@ mod tests {
struct TestVerifier;

impl Verifier for TestVerifier {
async fn make_request(&self, _tax_id: TaxId) -> Result<String, VerificationError> {
fn make_request(&self, _tax_id: &TaxId) -> Result<String, VerificationError> {
Ok("test".to_string())
}

Expand All @@ -63,11 +62,11 @@ mod tests {
}
}

#[tokio::test]
async fn test_verify() {
#[test]
fn test_verify() {
let tax_id = TaxId::new("SE123456789101").unwrap();
let verifier = TestVerifier;
let verification = verifier.verify(tax_id).await.unwrap();
let verification = verifier.verify(&tax_id).unwrap();
assert_eq!(*verification.status(), VerificationStatus::Verified);
assert_eq!(verification.performed_at.date_naive(), Local::now().date_naive());
}
Expand Down

0 comments on commit c6d6302

Please sign in to comment.