stripe_core/file_link/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListFileLinkBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    created: Option<stripe_types::RangeQueryTs>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    ending_before: Option<String>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    expand: Option<Vec<String>>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    expired: Option<bool>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    file: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    limit: Option<i64>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    starting_after: Option<String>,
21}
22impl ListFileLinkBuilder {
23    fn new() -> Self {
24        Self {
25            created: None,
26            ending_before: None,
27            expand: None,
28            expired: None,
29            file: None,
30            limit: None,
31            starting_after: None,
32        }
33    }
34}
35/// Returns a list of file links.
36#[derive(Clone, Debug, serde::Serialize)]
37pub struct ListFileLink {
38    inner: ListFileLinkBuilder,
39}
40impl ListFileLink {
41    /// Construct a new `ListFileLink`.
42    pub fn new() -> Self {
43        Self { inner: ListFileLinkBuilder::new() }
44    }
45    /// Only return links that were created during the given date interval.
46    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
47        self.inner.created = Some(created.into());
48        self
49    }
50    /// A cursor for use in pagination.
51    /// `ending_before` is an object ID that defines your place in the list.
52    /// 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.
53    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
54        self.inner.ending_before = Some(ending_before.into());
55        self
56    }
57    /// Specifies which fields in the response should be expanded.
58    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
59        self.inner.expand = Some(expand.into());
60        self
61    }
62    /// Filter links by their expiration status. By default, Stripe returns all links.
63    pub fn expired(mut self, expired: impl Into<bool>) -> Self {
64        self.inner.expired = Some(expired.into());
65        self
66    }
67    /// Only return links for the given file.
68    pub fn file(mut self, file: impl Into<String>) -> Self {
69        self.inner.file = Some(file.into());
70        self
71    }
72    /// A limit on the number of objects to be returned.
73    /// Limit can range between 1 and 100, and the default is 10.
74    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
75        self.inner.limit = Some(limit.into());
76        self
77    }
78    /// A cursor for use in pagination.
79    /// `starting_after` is an object ID that defines your place in the list.
80    /// 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.
81    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
82        self.inner.starting_after = Some(starting_after.into());
83        self
84    }
85}
86impl Default for ListFileLink {
87    fn default() -> Self {
88        Self::new()
89    }
90}
91impl ListFileLink {
92    /// Send the request and return the deserialized response.
93    pub async fn send<C: StripeClient>(
94        &self,
95        client: &C,
96    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
97        self.customize().send(client).await
98    }
99
100    /// Send the request and return the deserialized response, blocking until completion.
101    pub fn send_blocking<C: StripeBlockingClient>(
102        &self,
103        client: &C,
104    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
105        self.customize().send_blocking(client)
106    }
107
108    pub fn paginate(
109        &self,
110    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::FileLink>> {
111        stripe_client_core::ListPaginator::new_list("/file_links", &self.inner)
112    }
113}
114
115impl StripeRequest for ListFileLink {
116    type Output = stripe_types::List<stripe_shared::FileLink>;
117
118    fn build(&self) -> RequestBuilder {
119        RequestBuilder::new(StripeMethod::Get, "/file_links").query(&self.inner)
120    }
121}
122#[derive(Clone, Debug, serde::Serialize)]
123struct RetrieveFileLinkBuilder {
124    #[serde(skip_serializing_if = "Option::is_none")]
125    expand: Option<Vec<String>>,
126}
127impl RetrieveFileLinkBuilder {
128    fn new() -> Self {
129        Self { expand: None }
130    }
131}
132/// Retrieves the file link with the given ID.
133#[derive(Clone, Debug, serde::Serialize)]
134pub struct RetrieveFileLink {
135    inner: RetrieveFileLinkBuilder,
136    link: stripe_shared::FileLinkId,
137}
138impl RetrieveFileLink {
139    /// Construct a new `RetrieveFileLink`.
140    pub fn new(link: impl Into<stripe_shared::FileLinkId>) -> Self {
141        Self { link: link.into(), inner: RetrieveFileLinkBuilder::new() }
142    }
143    /// Specifies which fields in the response should be expanded.
144    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
145        self.inner.expand = Some(expand.into());
146        self
147    }
148}
149impl RetrieveFileLink {
150    /// Send the request and return the deserialized response.
151    pub async fn send<C: StripeClient>(
152        &self,
153        client: &C,
154    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
155        self.customize().send(client).await
156    }
157
158    /// Send the request and return the deserialized response, blocking until completion.
159    pub fn send_blocking<C: StripeBlockingClient>(
160        &self,
161        client: &C,
162    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
163        self.customize().send_blocking(client)
164    }
165}
166
167impl StripeRequest for RetrieveFileLink {
168    type Output = stripe_shared::FileLink;
169
170    fn build(&self) -> RequestBuilder {
171        let link = &self.link;
172        RequestBuilder::new(StripeMethod::Get, format!("/file_links/{link}")).query(&self.inner)
173    }
174}
175#[derive(Clone, Debug, serde::Serialize)]
176struct CreateFileLinkBuilder {
177    #[serde(skip_serializing_if = "Option::is_none")]
178    expand: Option<Vec<String>>,
179    #[serde(skip_serializing_if = "Option::is_none")]
180    expires_at: Option<stripe_types::Timestamp>,
181    file: String,
182    #[serde(skip_serializing_if = "Option::is_none")]
183    metadata: Option<std::collections::HashMap<String, String>>,
184}
185impl CreateFileLinkBuilder {
186    fn new(file: impl Into<String>) -> Self {
187        Self { expand: None, expires_at: None, file: file.into(), metadata: None }
188    }
189}
190/// Creates a new file link object.
191#[derive(Clone, Debug, serde::Serialize)]
192pub struct CreateFileLink {
193    inner: CreateFileLinkBuilder,
194}
195impl CreateFileLink {
196    /// Construct a new `CreateFileLink`.
197    pub fn new(file: impl Into<String>) -> Self {
198        Self { inner: CreateFileLinkBuilder::new(file.into()) }
199    }
200    /// Specifies which fields in the response should be expanded.
201    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
202        self.inner.expand = Some(expand.into());
203        self
204    }
205    /// The link isn't usable after this future timestamp.
206    pub fn expires_at(mut self, expires_at: impl Into<stripe_types::Timestamp>) -> Self {
207        self.inner.expires_at = Some(expires_at.into());
208        self
209    }
210    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
211    /// This can be useful for storing additional information about the object in a structured format.
212    /// Individual keys can be unset by posting an empty value to them.
213    /// All keys can be unset by posting an empty value to `metadata`.
214    pub fn metadata(
215        mut self,
216        metadata: impl Into<std::collections::HashMap<String, String>>,
217    ) -> Self {
218        self.inner.metadata = Some(metadata.into());
219        self
220    }
221}
222impl CreateFileLink {
223    /// Send the request and return the deserialized response.
224    pub async fn send<C: StripeClient>(
225        &self,
226        client: &C,
227    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
228        self.customize().send(client).await
229    }
230
231    /// Send the request and return the deserialized response, blocking until completion.
232    pub fn send_blocking<C: StripeBlockingClient>(
233        &self,
234        client: &C,
235    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
236        self.customize().send_blocking(client)
237    }
238}
239
240impl StripeRequest for CreateFileLink {
241    type Output = stripe_shared::FileLink;
242
243    fn build(&self) -> RequestBuilder {
244        RequestBuilder::new(StripeMethod::Post, "/file_links").form(&self.inner)
245    }
246}
247#[derive(Clone, Debug, serde::Serialize)]
248struct UpdateFileLinkBuilder {
249    #[serde(skip_serializing_if = "Option::is_none")]
250    expand: Option<Vec<String>>,
251    #[serde(skip_serializing_if = "Option::is_none")]
252    expires_at: Option<UpdateFileLinkExpiresAt>,
253    #[serde(skip_serializing_if = "Option::is_none")]
254    metadata: Option<std::collections::HashMap<String, String>>,
255}
256impl UpdateFileLinkBuilder {
257    fn new() -> Self {
258        Self { expand: None, expires_at: None, metadata: None }
259    }
260}
261/// A future timestamp after which the link will no longer be usable, or `now` to expire the link immediately.
262#[derive(Copy, Clone, Debug, serde::Serialize)]
263#[serde(rename_all = "snake_case")]
264pub enum UpdateFileLinkExpiresAt {
265    Now,
266    #[serde(untagged)]
267    Timestamp(stripe_types::Timestamp),
268}
269/// Updates an existing file link object. Expired links can no longer be updated.
270#[derive(Clone, Debug, serde::Serialize)]
271pub struct UpdateFileLink {
272    inner: UpdateFileLinkBuilder,
273    link: stripe_shared::FileLinkId,
274}
275impl UpdateFileLink {
276    /// Construct a new `UpdateFileLink`.
277    pub fn new(link: impl Into<stripe_shared::FileLinkId>) -> Self {
278        Self { link: link.into(), inner: UpdateFileLinkBuilder::new() }
279    }
280    /// Specifies which fields in the response should be expanded.
281    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
282        self.inner.expand = Some(expand.into());
283        self
284    }
285    /// A future timestamp after which the link will no longer be usable, or `now` to expire the link immediately.
286    pub fn expires_at(mut self, expires_at: impl Into<UpdateFileLinkExpiresAt>) -> Self {
287        self.inner.expires_at = Some(expires_at.into());
288        self
289    }
290    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
291    /// This can be useful for storing additional information about the object in a structured format.
292    /// Individual keys can be unset by posting an empty value to them.
293    /// All keys can be unset by posting an empty value to `metadata`.
294    pub fn metadata(
295        mut self,
296        metadata: impl Into<std::collections::HashMap<String, String>>,
297    ) -> Self {
298        self.inner.metadata = Some(metadata.into());
299        self
300    }
301}
302impl UpdateFileLink {
303    /// Send the request and return the deserialized response.
304    pub async fn send<C: StripeClient>(
305        &self,
306        client: &C,
307    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
308        self.customize().send(client).await
309    }
310
311    /// Send the request and return the deserialized response, blocking until completion.
312    pub fn send_blocking<C: StripeBlockingClient>(
313        &self,
314        client: &C,
315    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
316        self.customize().send_blocking(client)
317    }
318}
319
320impl StripeRequest for UpdateFileLink {
321    type Output = stripe_shared::FileLink;
322
323    fn build(&self) -> RequestBuilder {
324        let link = &self.link;
325        RequestBuilder::new(StripeMethod::Post, format!("/file_links/{link}")).form(&self.inner)
326    }
327}