stripe/resources/generated/
file.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::FileId;
7use crate::params::{Expand, List, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::FileLink;
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "File".
12///
13/// For more details see <https://stripe.com/docs/api/files/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct File {
16    /// Unique identifier for the object.
17    pub id: FileId,
18
19    /// Time at which the object was created.
20    ///
21    /// Measured in seconds since the Unix epoch.
22    pub created: Timestamp,
23
24    /// The file expires and isn't available at this time in epoch seconds.
25    pub expires_at: Option<Timestamp>,
26
27    /// The suitable name for saving the file to a filesystem.
28    pub filename: Option<String>,
29
30    /// A list of [file links](https://stripe.com/docs/api#file_links) that point at this file.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub links: Option<List<FileLink>>,
33
34    /// The [purpose](https://stripe.com/docs/file-upload#uploading-a-file) of the uploaded file.
35    pub purpose: FilePurpose,
36
37    /// The size of the file object in bytes.
38    pub size: u64,
39
40    /// A suitable title for the document.
41    pub title: Option<String>,
42
43    /// The returned file type (for example, `csv`, `pdf`, `jpg`, or `png`).
44    #[serde(rename = "type")]
45    pub type_: Option<String>,
46
47    /// Use your live secret API key to download the file from this URL.
48    pub url: Option<String>,
49}
50
51impl File {
52    /// Returns a list of the files that your account has access to.
53    ///
54    /// Stripe sorts and returns the files by their creation dates, placing the most recently created files at the top.
55    pub fn list(client: &Client, params: &ListFiles<'_>) -> Response<List<File>> {
56        client.get_query("/files", params)
57    }
58
59    /// Retrieves the details of an existing file object.
60    ///
61    /// After you supply a unique file ID, Stripe returns the corresponding file object.
62    /// Learn how to [access file contents](https://stripe.com/docs/file-upload#download-file-contents).
63    pub fn retrieve(client: &Client, id: &FileId, expand: &[&str]) -> Response<File> {
64        client.get_query(&format!("/files/{}", id), Expand { expand })
65    }
66}
67
68impl Object for File {
69    type Id = FileId;
70    fn id(&self) -> Self::Id {
71        self.id.clone()
72    }
73    fn object(&self) -> &'static str {
74        "file"
75    }
76}
77
78/// The parameters for `File::list`.
79#[derive(Clone, Debug, Serialize, Default)]
80pub struct ListFiles<'a> {
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub created: Option<RangeQuery<Timestamp>>,
83
84    /// A cursor for use in pagination.
85    ///
86    /// `ending_before` is an object ID that defines your place in the list.
87    /// 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.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub ending_before: Option<FileId>,
90
91    /// Specifies which fields in the response should be expanded.
92    #[serde(skip_serializing_if = "Expand::is_empty")]
93    pub expand: &'a [&'a str],
94
95    /// A limit on the number of objects to be returned.
96    ///
97    /// Limit can range between 1 and 100, and the default is 10.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub limit: Option<u64>,
100
101    /// Filter queries by the file purpose.
102    ///
103    /// If you don't provide a purpose, the queries return unfiltered files.
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub purpose: Option<FilePurpose>,
106
107    /// A cursor for use in pagination.
108    ///
109    /// `starting_after` is an object ID that defines your place in the list.
110    /// 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.
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub starting_after: Option<FileId>,
113}
114
115impl<'a> ListFiles<'a> {
116    pub fn new() -> Self {
117        ListFiles {
118            created: Default::default(),
119            ending_before: Default::default(),
120            expand: Default::default(),
121            limit: Default::default(),
122            purpose: Default::default(),
123            starting_after: Default::default(),
124        }
125    }
126}
127impl Paginable for ListFiles<'_> {
128    type O = File;
129    fn set_last(&mut self, item: Self::O) {
130        self.starting_after = Some(item.id());
131    }
132}
133/// An enum representing the possible values of an `ListFiles`'s `purpose` field.
134#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
135#[serde(rename_all = "snake_case")]
136pub enum FilePurpose {
137    AccountRequirement,
138    AdditionalVerification,
139    BusinessIcon,
140    BusinessLogo,
141    CustomerSignature,
142    DisputeEvidence,
143    DocumentProviderIdentityDocument,
144    FinanceReportRun,
145    IdentityDocument,
146    IdentityDocumentDownloadable,
147    PciDocument,
148    Selfie,
149    SigmaScheduledQuery,
150    TaxDocumentUserUpload,
151    TerminalReaderSplashscreen,
152}
153
154impl FilePurpose {
155    pub fn as_str(self) -> &'static str {
156        match self {
157            FilePurpose::AccountRequirement => "account_requirement",
158            FilePurpose::AdditionalVerification => "additional_verification",
159            FilePurpose::BusinessIcon => "business_icon",
160            FilePurpose::BusinessLogo => "business_logo",
161            FilePurpose::CustomerSignature => "customer_signature",
162            FilePurpose::DisputeEvidence => "dispute_evidence",
163            FilePurpose::DocumentProviderIdentityDocument => "document_provider_identity_document",
164            FilePurpose::FinanceReportRun => "finance_report_run",
165            FilePurpose::IdentityDocument => "identity_document",
166            FilePurpose::IdentityDocumentDownloadable => "identity_document_downloadable",
167            FilePurpose::PciDocument => "pci_document",
168            FilePurpose::Selfie => "selfie",
169            FilePurpose::SigmaScheduledQuery => "sigma_scheduled_query",
170            FilePurpose::TaxDocumentUserUpload => "tax_document_user_upload",
171            FilePurpose::TerminalReaderSplashscreen => "terminal_reader_splashscreen",
172        }
173    }
174}
175
176impl AsRef<str> for FilePurpose {
177    fn as_ref(&self) -> &str {
178        self.as_str()
179    }
180}
181
182impl std::fmt::Display for FilePurpose {
183    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
184        self.as_str().fmt(f)
185    }
186}
187impl std::default::Default for FilePurpose {
188    fn default() -> Self {
189        Self::AccountRequirement
190    }
191}