square_api_client/models/list_gift_cards_parameters.rs
1//! Query parameters for the List Gift Cards API
2
3use super::enums::{GiftCardStatus, GiftCardType};
4
5/// This is a model struct for ListGiftCardsParameters (query parameters)
6#[derive(Clone, Debug, Default)]
7pub struct ListGiftCardsParameters {
8 /// If a type is provided, the endpoint returns gift cards of the specified type. Otherwise, the
9 /// endpoint returns gift cards of all types.
10 pub r#type: Option<GiftCardType>,
11 /// If a state is provided, the endpoint returns the gift cards in the specified state.
12 /// Otherwise, the endpoint returns the gift cards of all states.
13 pub state: Option<GiftCardStatus>,
14 /// If a limit is provided, the endpoint returns only the specified number of results per page.
15 /// The maximum value is 50. The default value is 30. For more information, see
16 /// [Pagination](https://developer.squareup.com/docs/working-with-apis/pagination).
17 pub limit: Option<i32>,
18 /// A pagination cursor returned by a previous call to this endpoint. Provide this cursor to
19 /// retrieve the next set of results for the original query. If a cursor is not provided, the
20 /// endpoint returns the first page of the results. For more information, see
21 /// [Pagination](https://developer.squareup.com/docs/basics/api101/pagination).
22 pub cursor: Option<String>,
23 /// If a customer ID is provided, the endpoint returns only the gift cards linked to the
24 /// specified customer.
25 pub customer_id: Option<String>,
26}
27
28impl ListGiftCardsParameters {
29 pub fn to_query_string(&self) -> String {
30 self.to_string()
31 }
32}
33
34impl From<ListGiftCardsParameters> for String {
35 fn from(list_gift_cards_parameters: ListGiftCardsParameters) -> Self {
36 list_gift_cards_parameters.to_string()
37 }
38}
39
40impl ToString for ListGiftCardsParameters {
41 fn to_string(&self) -> String {
42 let mut params = Vec::new();
43
44 if let Some(gift_card_type) = &self.r#type {
45 params.push(format!("type={}", serde_json::to_string(gift_card_type).unwrap()));
46 }
47
48 if let Some(gift_card_status) = &self.state {
49 params.push(format!("state={}", serde_json::to_string(gift_card_status).unwrap()));
50 }
51
52 if let Some(limit) = self.limit {
53 params.push(format!("limit={}", limit));
54 }
55
56 if let Some(cursor) = &self.cursor {
57 params.push(format!("cursor={}", cursor));
58 }
59
60 if let Some(customer_id) = &self.customer_id {
61 params.push(format!("customer_id={}", customer_id));
62 }
63
64 if params.is_empty() {
65 String::new()
66 } else {
67 format!("?{}", params.join("&"))
68 }
69 }
70}