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::*;
use crate::pagination::Page;

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

impl<'a> CommentsService<'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
    }

    /// `CreateComment` — `POST /{accountId}/cards/{cardNumber}/comments.json`.
    ///
    /// Sent once and never resent.
    pub async fn create(
        &self,
        card_number: i32,
        body: &CreateCommentRequestContent,
    ) -> Result<Comment, Error> {
        let mut operation = self
            .scope
            .operation(&routes::CREATE_COMMENT, &[&card_number])?;
        operation.resource_id(card_number);
        operation.json(body)?;
        self.scope.client().send(operation).await
    }

    /// `DeleteComment` — `DELETE /{accountId}/cards/{cardNumber}/comments/{commentId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn delete(&self, card_number: i32, comment_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::DELETE_COMMENT, &[&card_number, &comment_id])?;
        operation.resource_id(comment_id);
        self.scope.client().send_unit(operation).await
    }

    /// `GetComment` — `GET /{accountId}/cards/{cardNumber}/comments/{commentId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get(&self, card_number: i32, comment_id: &str) -> Result<Comment, Error> {
        let mut operation = self
            .scope
            .operation(&routes::GET_COMMENT, &[&card_number, &comment_id])?;
        operation.resource_id(comment_id);
        self.scope.client().send(operation).await
    }

    /// `ListComments` — `GET /{accountId}/cards/{cardNumber}/comments.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    ///
    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
    pub async fn list(&self, card_number: i32) -> Result<Page<Vec<Comment>>, Error> {
        let mut operation = self
            .scope
            .operation(&routes::LIST_COMMENTS, &[&card_number])?;
        operation.resource_id(card_number);
        self.scope.client().send_page(operation).await
    }

    /// `UpdateComment` — `PATCH /{accountId}/cards/{cardNumber}/comments/{commentId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn update(
        &self,
        card_number: i32,
        comment_id: &str,
        body: &UpdateCommentRequestContent,
    ) -> Result<Comment, Error> {
        let mut operation = self
            .scope
            .operation(&routes::UPDATE_COMMENT, &[&card_number, &comment_id])?;
        operation.resource_id(comment_id);
        operation.json(body)?;
        self.scope.client().send(operation).await
    }
}