stripe_core/file/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListFileBuilder {
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    limit: Option<i64>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    purpose: Option<stripe_shared::FilePurpose>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    starting_after: Option<String>,
19}
20impl ListFileBuilder {
21    fn new() -> Self {
22        Self {
23            created: None,
24            ending_before: None,
25            expand: None,
26            limit: None,
27            purpose: None,
28            starting_after: None,
29        }
30    }
31}
32/// Returns a list of the files that your account has access to.
33/// Stripe sorts and returns the files by their creation dates, placing the most recently created files at the top.
34#[derive(Clone, Debug, serde::Serialize)]
35pub struct ListFile {
36    inner: ListFileBuilder,
37}
38impl ListFile {
39    /// Construct a new `ListFile`.
40    pub fn new() -> Self {
41        Self { inner: ListFileBuilder::new() }
42    }
43    /// Only return files that were created during the given date interval.
44    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
45        self.inner.created = Some(created.into());
46        self
47    }
48    /// A cursor for use in pagination.
49    /// `ending_before` is an object ID that defines your place in the list.
50    /// 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.
51    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
52        self.inner.ending_before = Some(ending_before.into());
53        self
54    }
55    /// Specifies which fields in the response should be expanded.
56    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
57        self.inner.expand = Some(expand.into());
58        self
59    }
60    /// A limit on the number of objects to be returned.
61    /// Limit can range between 1 and 100, and the default is 10.
62    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
63        self.inner.limit = Some(limit.into());
64        self
65    }
66    /// Filter queries by the file purpose.
67    /// If you don't provide a purpose, the queries return unfiltered files.
68    pub fn purpose(mut self, purpose: impl Into<stripe_shared::FilePurpose>) -> Self {
69        self.inner.purpose = Some(purpose.into());
70        self
71    }
72    /// A cursor for use in pagination.
73    /// `starting_after` is an object ID that defines your place in the list.
74    /// 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.
75    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
76        self.inner.starting_after = Some(starting_after.into());
77        self
78    }
79}
80impl Default for ListFile {
81    fn default() -> Self {
82        Self::new()
83    }
84}
85impl ListFile {
86    /// Send the request and return the deserialized response.
87    pub async fn send<C: StripeClient>(
88        &self,
89        client: &C,
90    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
91        self.customize().send(client).await
92    }
93
94    /// Send the request and return the deserialized response, blocking until completion.
95    pub fn send_blocking<C: StripeBlockingClient>(
96        &self,
97        client: &C,
98    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
99        self.customize().send_blocking(client)
100    }
101
102    pub fn paginate(
103        &self,
104    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::File>> {
105        stripe_client_core::ListPaginator::new_list("/files", &self.inner)
106    }
107}
108
109impl StripeRequest for ListFile {
110    type Output = stripe_types::List<stripe_shared::File>;
111
112    fn build(&self) -> RequestBuilder {
113        RequestBuilder::new(StripeMethod::Get, "/files").query(&self.inner)
114    }
115}
116#[derive(Clone, Debug, serde::Serialize)]
117struct RetrieveFileBuilder {
118    #[serde(skip_serializing_if = "Option::is_none")]
119    expand: Option<Vec<String>>,
120}
121impl RetrieveFileBuilder {
122    fn new() -> Self {
123        Self { expand: None }
124    }
125}
126/// Retrieves the details of an existing file object.
127/// After you supply a unique file ID, Stripe returns the corresponding file object.
128/// Learn how to [access file contents](https://stripe.com/docs/file-upload#download-file-contents).
129#[derive(Clone, Debug, serde::Serialize)]
130pub struct RetrieveFile {
131    inner: RetrieveFileBuilder,
132    file: stripe_shared::FileId,
133}
134impl RetrieveFile {
135    /// Construct a new `RetrieveFile`.
136    pub fn new(file: impl Into<stripe_shared::FileId>) -> Self {
137        Self { file: file.into(), inner: RetrieveFileBuilder::new() }
138    }
139    /// Specifies which fields in the response should be expanded.
140    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
141        self.inner.expand = Some(expand.into());
142        self
143    }
144}
145impl RetrieveFile {
146    /// Send the request and return the deserialized response.
147    pub async fn send<C: StripeClient>(
148        &self,
149        client: &C,
150    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
151        self.customize().send(client).await
152    }
153
154    /// Send the request and return the deserialized response, blocking until completion.
155    pub fn send_blocking<C: StripeBlockingClient>(
156        &self,
157        client: &C,
158    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
159        self.customize().send_blocking(client)
160    }
161}
162
163impl StripeRequest for RetrieveFile {
164    type Output = stripe_shared::File;
165
166    fn build(&self) -> RequestBuilder {
167        let file = &self.file;
168        RequestBuilder::new(StripeMethod::Get, format!("/files/{file}")).query(&self.inner)
169    }
170}