square_api_client/api/gift_card_activities_api.rs
1//! Create and retrieve gift card activities.
2//!
3//! Developers can use the Gift Cards API to create and access gift cards and use the Gift Card
4//! Activities API to create gift card activities, such as activate a gift card, add funds to a gift
5//! card, and redeem a gift card.
6
7use crate::{
8 config::Configuration,
9 http::client::HttpClient,
10 models::{
11 errors::ApiError, CreateGiftCardActivityRequest, CreateGiftCardActivityResponse,
12 ListGiftCardActivitiesParameters, ListGiftCardActivitiesResponse,
13 },
14};
15
16const DEFAULT_URI: &str = "/gift-cards/activities";
17
18pub struct GiftCardActivitiesApi {
19 /// App config information
20 config: Configuration,
21 /// HTTP Client for requests to the Gift Card Activities API endpoints
22 client: HttpClient,
23}
24
25impl GiftCardActivitiesApi {
26 /// Instantiates a new `GiftCardActivitiesApi`
27 pub fn new(config: Configuration, client: HttpClient) -> Self {
28 Self { config, client }
29 }
30
31 /// Lists gift card activities.
32 ///
33 /// By default, you get gift card activities for all gift cards in the seller's account. You can
34 /// optionally specify query parameters to filter the list. For example, you can get a list of
35 /// gift card activities for a gift card, for all gift cards in a specific region, or for
36 /// activities within a time window.
37 pub async fn list_gift_card_activities(
38 &self,
39 params: &ListGiftCardActivitiesParameters,
40 ) -> Result<ListGiftCardActivitiesResponse, ApiError> {
41 let url = format!("{}{}", &self.url(), params.to_query_string());
42 let response = self.client.get(&url).await?;
43
44 response.deserialize().await
45 }
46
47 /// Creates a gift card activity to manage the balance or state of a [gift card](GiftCard).
48 ///
49 /// For example, you create an `ACTIVATE` activity to activate a gift card with an initial
50 /// balance before the gift card can be used.
51 pub async fn create_gift_card_activity(
52 &self,
53 body: &CreateGiftCardActivityRequest,
54 ) -> Result<CreateGiftCardActivityResponse, ApiError> {
55 let response = self.client.post(&self.url(), body).await?;
56
57 response.deserialize().await
58 }
59
60 /// Constructs the basic entity URL including domain and entity path. Any additional path
61 /// elements (e.g. path parameters) will need to be appended to this URL.
62 fn url(&self) -> String {
63 format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
64 }
65}