dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

#[allow(unused_imports)]
use super::types::*;

/// Delegated client for agreements operations. Signed operations are split into
/// init/complete pairs so the challenge can be signed on the user side.
#[derive(Clone)]
pub struct DelegatedAgreementsClient {
    client: crate::client::Client,
}

impl DelegatedAgreementsClient {
    pub fn new(client: crate::client::Client) -> Self {
        DelegatedAgreementsClient { client }
    }

    /// Get the latest unaccepted agreement for a specific agreement type
    pub async fn get_latest_unaccepted_agreement(
        &self,
        query: Option<GetLatestUnacceptedAgreementQuery>,
    ) -> Result<GetLatestUnacceptedAgreementResponse, crate::error::Error> {
        let mut path = String::from("/agreements/latest-unaccepted");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            q.push(format!(
                "agreementType={}",
                urlencoding::encode(&query.agreement_type.to_string())
            ));
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetLatestUnacceptedAgreementResponse>(
                reqwest::Method::GET,
                &path,
                None,
                false,
            )
            .await
    }

    /// Starts delegated signing for recordAgreementAcceptance: returns the challenge to sign.
    /// Pass the signed assertion to record_agreement_acceptance_complete with the same arguments.
    pub async fn record_agreement_acceptance_init(
        &self,
        agreement_id: String,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!("/agreements/{}/accept", urlencoding::encode(&agreement_id));
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, None)
            .await
    }

    /// Finishes delegated signing for recordAgreementAcceptance: submits the signed challenge
    /// and issues the request.
    pub async fn record_agreement_acceptance_complete(
        &self,
        agreement_id: String,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<RecordAgreementAcceptanceResponse, crate::error::Error> {
        let path = format!("/agreements/{}/accept", urlencoding::encode(&agreement_id));
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<RecordAgreementAcceptanceResponse>(
                reqwest::Method::POST,
                &path,
                None,
                &user_action,
            )
            .await
    }
}