stripe/resources/generated/file_link.rs
1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{FileId, FileLinkId};
7use crate::params::{Expand, Expandable, List, Metadata, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::{File, Scheduled};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "FileLink".
12///
13/// For more details see <https://stripe.com/docs/api/file_links/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct FileLink {
16 /// Unique identifier for the object.
17 pub id: FileLinkId,
18
19 /// Time at which the object was created.
20 ///
21 /// Measured in seconds since the Unix epoch.
22 pub created: Timestamp,
23
24 /// Returns if the link is already expired.
25 pub expired: bool,
26
27 /// Time that the link expires.
28 pub expires_at: Option<Timestamp>,
29
30 /// The file object this link points to.
31 pub file: Expandable<File>,
32
33 /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
34 pub livemode: bool,
35
36 /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
37 ///
38 /// This can be useful for storing additional information about the object in a structured format.
39 pub metadata: Metadata,
40
41 /// The publicly accessible URL to download the file.
42 pub url: Option<String>,
43}
44
45impl FileLink {
46 /// Returns a list of file links.
47 pub fn list(client: &Client, params: &ListFileLinks<'_>) -> Response<List<FileLink>> {
48 client.get_query("/file_links", params)
49 }
50
51 /// Creates a new file link object.
52 pub fn create(client: &Client, params: CreateFileLink<'_>) -> Response<FileLink> {
53 #[allow(clippy::needless_borrows_for_generic_args)]
54 client.post_form("/file_links", ¶ms)
55 }
56
57 /// Retrieves the file link with the given ID.
58 pub fn retrieve(client: &Client, id: &FileLinkId, expand: &[&str]) -> Response<FileLink> {
59 client.get_query(&format!("/file_links/{}", id), Expand { expand })
60 }
61
62 /// Updates an existing file link object.
63 ///
64 /// Expired links can no longer be updated.
65 pub fn update(
66 client: &Client,
67 id: &FileLinkId,
68 params: UpdateFileLink<'_>,
69 ) -> Response<FileLink> {
70 #[allow(clippy::needless_borrows_for_generic_args)]
71 client.post_form(&format!("/file_links/{}", id), ¶ms)
72 }
73}
74
75impl Object for FileLink {
76 type Id = FileLinkId;
77 fn id(&self) -> Self::Id {
78 self.id.clone()
79 }
80 fn object(&self) -> &'static str {
81 "file_link"
82 }
83}
84
85/// The parameters for `FileLink::create`.
86#[derive(Clone, Debug, Serialize)]
87pub struct CreateFileLink<'a> {
88 /// Specifies which fields in the response should be expanded.
89 #[serde(skip_serializing_if = "Expand::is_empty")]
90 pub expand: &'a [&'a str],
91
92 /// The link isn't usable after this future timestamp.
93 #[serde(skip_serializing_if = "Option::is_none")]
94 pub expires_at: Option<Timestamp>,
95
96 /// The ID of the file.
97 ///
98 /// The file's `purpose` must be one of the following: `business_icon`, `business_logo`, `customer_signature`, `dispute_evidence`, `finance_report_run`, `identity_document_downloadable`, `pci_document`, `selfie`, `sigma_scheduled_query`, `tax_document_user_upload`, or `terminal_reader_splashscreen`.
99 pub file: FileId,
100
101 /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
102 ///
103 /// This can be useful for storing additional information about the object in a structured format.
104 /// Individual keys can be unset by posting an empty value to them.
105 /// All keys can be unset by posting an empty value to `metadata`.
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub metadata: Option<Metadata>,
108}
109
110impl<'a> CreateFileLink<'a> {
111 pub fn new(file: FileId) -> Self {
112 CreateFileLink {
113 expand: Default::default(),
114 expires_at: Default::default(),
115 file,
116 metadata: Default::default(),
117 }
118 }
119}
120
121/// The parameters for `FileLink::list`.
122#[derive(Clone, Debug, Serialize, Default)]
123pub struct ListFileLinks<'a> {
124 #[serde(skip_serializing_if = "Option::is_none")]
125 pub created: Option<RangeQuery<Timestamp>>,
126
127 /// A cursor for use in pagination.
128 ///
129 /// `ending_before` is an object ID that defines your place in the list.
130 /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
131 #[serde(skip_serializing_if = "Option::is_none")]
132 pub ending_before: Option<FileLinkId>,
133
134 /// Specifies which fields in the response should be expanded.
135 #[serde(skip_serializing_if = "Expand::is_empty")]
136 pub expand: &'a [&'a str],
137
138 /// Filter links by their expiration status.
139 ///
140 /// By default, Stripe returns all links.
141 #[serde(skip_serializing_if = "Option::is_none")]
142 pub expired: Option<bool>,
143
144 /// Only return links for the given file.
145 #[serde(skip_serializing_if = "Option::is_none")]
146 pub file: Option<FileId>,
147
148 /// A limit on the number of objects to be returned.
149 ///
150 /// Limit can range between 1 and 100, and the default is 10.
151 #[serde(skip_serializing_if = "Option::is_none")]
152 pub limit: Option<u64>,
153
154 /// A cursor for use in pagination.
155 ///
156 /// `starting_after` is an object ID that defines your place in the list.
157 /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
158 #[serde(skip_serializing_if = "Option::is_none")]
159 pub starting_after: Option<FileLinkId>,
160}
161
162impl<'a> ListFileLinks<'a> {
163 pub fn new() -> Self {
164 ListFileLinks {
165 created: Default::default(),
166 ending_before: Default::default(),
167 expand: Default::default(),
168 expired: Default::default(),
169 file: Default::default(),
170 limit: Default::default(),
171 starting_after: Default::default(),
172 }
173 }
174}
175impl Paginable for ListFileLinks<'_> {
176 type O = FileLink;
177 fn set_last(&mut self, item: Self::O) {
178 self.starting_after = Some(item.id());
179 }
180}
181/// The parameters for `FileLink::update`.
182#[derive(Clone, Debug, Serialize, Default)]
183pub struct UpdateFileLink<'a> {
184 /// Specifies which fields in the response should be expanded.
185 #[serde(skip_serializing_if = "Expand::is_empty")]
186 pub expand: &'a [&'a str],
187
188 /// A future timestamp after which the link will no longer be usable, or `now` to expire the link immediately.
189 #[serde(skip_serializing_if = "Option::is_none")]
190 pub expires_at: Option<Scheduled>,
191
192 /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
193 ///
194 /// This can be useful for storing additional information about the object in a structured format.
195 /// Individual keys can be unset by posting an empty value to them.
196 /// All keys can be unset by posting an empty value to `metadata`.
197 #[serde(skip_serializing_if = "Option::is_none")]
198 pub metadata: Option<Metadata>,
199}
200
201impl<'a> UpdateFileLink<'a> {
202 pub fn new() -> Self {
203 UpdateFileLink {
204 expand: Default::default(),
205 expires_at: Default::default(),
206 metadata: Default::default(),
207 }
208 }
209}