square_api_client/models/list_gift_card_activities_parameters.rs
1//! Query parameters for the List Gift Card Activities API
2
3use super::{
4 enums::{GiftCardActivityType, SortOrder},
5 DateTime,
6};
7
8/// This is a model struct for ListGiftCardActivitiesParameters (query parameters)
9#[derive(Clone, Debug, Default)]
10pub struct ListGiftCardActivitiesParameters {
11 /// If a gift card ID is provided, the endpoint returns activities related to the specified gift
12 /// card. Otherwise, the endpoint returns all gift card activities for the seller.
13 pub gift_card_id: Option<String>,
14 /// If a [type](GiftCardActivityType) is provided, the endpoint returns gift card activities of
15 /// the specified type. Otherwise, the endpoint returns all types of gift card activities.
16 pub r#type: Option<GiftCardActivityType>,
17 /// If a location ID is provided, the endpoint returns gift card activities for the specified
18 /// location. Otherwise, the endpoint returns gift card activities for all locations.
19 pub location_id: Option<String>,
20 /// The timestamp for the beginning of the reporting period, in RFC 3339 format. This start time
21 /// is inclusive. The default value is the current time minus one year.
22 pub begin_time: Option<DateTime>,
23 /// The timestamp for the end of the reporting period, in RFC 3339 format. This end time is
24 /// inclusive. The default value is the current time.
25 pub end_time: Option<DateTime>,
26 /// If a limit is provided, the endpoint returns the specified number of results (or fewer) per
27 /// page. The maximum value is 100. The default value is 50. For more information, see
28 /// [Pagination](https://developer.squareup.com/docs/working-with-apis/pagination).
29 pub limit: Option<i32>,
30 /// A pagination cursor returned by a previous call to this endpoint. Provide this cursor to
31 /// retrieve the next set of results for the original query. If a cursor is not provided, the
32 /// endpoint returns the first page of the results. For more information, see
33 /// [Pagination](https://developer.squareup.com/docs/basics/api101/pagination).
34 pub cursor: Option<String>,
35 /// The order in which the endpoint returns the activities, based on `created_at`.
36 ///
37 /// - ASC - Oldest to newest.
38 /// - DESC - Newest to oldest (default).
39 pub sort_order: Option<SortOrder>,
40}
41
42impl ListGiftCardActivitiesParameters {
43 pub fn to_query_string(&self) -> String {
44 self.to_string()
45 }
46}
47
48impl From<ListGiftCardActivitiesParameters> for String {
49 fn from(list_gift_card_activities_parameters: ListGiftCardActivitiesParameters) -> Self {
50 list_gift_card_activities_parameters.to_string()
51 }
52}
53
54impl ToString for ListGiftCardActivitiesParameters {
55 fn to_string(&self) -> String {
56 let mut params = Vec::new();
57
58 if let Some(gift_card_id) = &self.gift_card_id {
59 params.push(format!("gift_card_id={}", gift_card_id));
60 }
61
62 if let Some(gift_card_activity_type) = &self.r#type {
63 params
64 .push(format!("type={}", serde_json::to_string(gift_card_activity_type).unwrap()));
65 }
66
67 if let Some(location_id) = &self.location_id {
68 params.push(format!("location_id={}", location_id));
69 }
70
71 if let Some(begin_time) = &self.begin_time {
72 params.push(format!("begin_time={}", serde_json::to_string(begin_time).unwrap()));
73 }
74
75 if let Some(end_time) = &self.end_time {
76 params.push(format!("end_time={}", serde_json::to_string(end_time).unwrap()));
77 }
78
79 if let Some(limit) = self.limit {
80 params.push(format!("limit={}", limit));
81 }
82
83 if let Some(cursor) = &self.cursor {
84 params.push(format!("cursor={}", cursor));
85 }
86
87 if params.is_empty() {
88 String::new()
89 } else {
90 format!("?{}", params.join("&"))
91 }
92 }
93}