Skip to main content

fizzy_sdk/generated/services/
comments.rs

1// Generated by fizzy-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3use crate::client::Scope;
4use crate::error::Error;
5use crate::generated::routes;
6use crate::generated::types::*;
7use crate::pagination::Page;
8
9/// The `Comments` operations.
10pub struct CommentsService<'a> {
11    scope: Scope<'a>,
12}
13
14impl<'a> CommentsService<'a> {
15    pub(crate) fn new(scope: Scope<'a>) -> Self {
16        Self { scope }
17    }
18
19    /// The client and account these operations send through.
20    pub fn scope(&self) -> &Scope<'a> {
21        &self.scope
22    }
23
24    /// `CreateComment` — `POST /{accountId}/cards/{cardNumber}/comments.json`.
25    ///
26    /// Sent once and never resent.
27    pub async fn create(
28        &self,
29        card_number: i32,
30        body: &CreateCommentRequestContent,
31    ) -> Result<Comment, Error> {
32        let mut operation = self
33            .scope
34            .operation(&routes::CREATE_COMMENT, &[&card_number])?;
35        operation.resource_id(card_number);
36        operation.json(body)?;
37        self.scope.client().send(operation).await
38    }
39
40    /// `DeleteComment` — `DELETE /{accountId}/cards/{cardNumber}/comments/{commentId}`.
41    ///
42    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
43    pub async fn delete(&self, card_number: i32, comment_id: &str) -> Result<(), Error> {
44        let mut operation = self
45            .scope
46            .operation(&routes::DELETE_COMMENT, &[&card_number, &comment_id])?;
47        operation.resource_id(comment_id);
48        self.scope.client().send_unit(operation).await
49    }
50
51    /// `GetComment` — `GET /{accountId}/cards/{cardNumber}/comments/{commentId}`.
52    ///
53    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
54    pub async fn get(&self, card_number: i32, comment_id: &str) -> Result<Comment, Error> {
55        let mut operation = self
56            .scope
57            .operation(&routes::GET_COMMENT, &[&card_number, &comment_id])?;
58        operation.resource_id(comment_id);
59        self.scope.client().send(operation).await
60    }
61
62    /// `ListComments` — `GET /{accountId}/cards/{cardNumber}/comments.json`.
63    ///
64    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
65    ///
66    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
67    pub async fn list(&self, card_number: i32) -> Result<Page<Vec<Comment>>, Error> {
68        let mut operation = self
69            .scope
70            .operation(&routes::LIST_COMMENTS, &[&card_number])?;
71        operation.resource_id(card_number);
72        self.scope.client().send_page(operation).await
73    }
74
75    /// `UpdateComment` — `PATCH /{accountId}/cards/{cardNumber}/comments/{commentId}`.
76    ///
77    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
78    pub async fn update(
79        &self,
80        card_number: i32,
81        comment_id: &str,
82        body: &UpdateCommentRequestContent,
83    ) -> Result<Comment, Error> {
84        let mut operation = self
85            .scope
86            .operation(&routes::UPDATE_COMMENT, &[&card_number, &comment_id])?;
87        operation.resource_id(comment_id);
88        operation.json(body)?;
89        self.scope.client().send(operation).await
90    }
91}