fizzy-sdk 0.2.4

Official Fizzy API client, generated from the Smithy model in spec/
Documentation
// Generated by fizzy-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

use crate::client::Scope;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;

/// The `AccessTokens` operations.
pub struct AccessTokensService<'a> {
    scope: Scope<'a>,
}

impl<'a> AccessTokensService<'a> {
    pub(crate) fn new(scope: Scope<'a>) -> Self {
        Self { scope }
    }

    /// The client and account these operations send through.
    pub fn scope(&self) -> &Scope<'a> {
        &self.scope
    }

    /// `CreateAccessToken` — `POST /my/access_tokens.json`.
    ///
    /// Sent once and never resent.
    pub async fn create(
        &self,
        body: &CreateAccessTokenRequestContent,
    ) -> Result<AccessToken, Error> {
        let mut operation = self.scope.operation(&routes::CREATE_ACCESS_TOKEN, &[])?;
        operation.json(body)?;
        self.scope.client().send(operation).await
    }

    /// `DeleteAccessToken` — `DELETE /my/access_tokens/{accessTokenId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn delete(&self, access_token_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::DELETE_ACCESS_TOKEN, &[&access_token_id])?;
        operation.resource_id(access_token_id);
        self.scope.client().send_unit(operation).await
    }

    /// `ListAccessTokens` — `GET /my/access_tokens.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn list(&self) -> Result<Vec<AccessToken>, Error> {
        let operation = self.scope.operation(&routes::LIST_ACCESS_TOKENS, &[])?;
        self.scope.client().send(operation).await
    }
}