twilio_rust_openapi/apis/
api20100401_record_api.rs

1/*
2 * Twilio - Api
3 *
4 * This is the public Twilio REST API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: support@twilio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`list_usage_record`]
18#[derive(Clone, Debug)]
19pub struct ListUsageRecordParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the UsageRecord resources to read.
21    pub account_sid: String,
22    /// The [usage category](https://www.twilio.com/docs/usage/api/usage-record#usage-categories) of the UsageRecord resources to read. Only UsageRecord resources in the specified category are retrieved.
23    pub category: Option<String>,
24    /// Only include usage that has occurred on or after this date. Specify the date in GMT and format as `YYYY-MM-DD`. You can also specify offsets from the current date, such as: `-30days`, which will set the start date to be 30 days before the current date.
25    pub start_date: Option<String>,
26    /// Only include usage that occurred on or before this date. Specify the date in GMT and format as `YYYY-MM-DD`.  You can also specify offsets from the current date, such as: `+30days`, which will set the end date to 30 days from the current date.
27    pub end_date: Option<String>,
28    /// Whether to include usage from the master account and all its subaccounts. Can be: `true` (the default) to include usage from the master account and all subaccounts or `false` to retrieve usage from only the specified account.
29    pub include_subaccounts: Option<bool>,
30    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
31    pub page_size: Option<i32>,
32    /// The page index. This value is simply for client state.
33    pub page: Option<i32>,
34    /// The page token. This is provided by the API.
35    pub page_token: Option<String>
36}
37
38
39/// struct for typed errors of method [`list_usage_record`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ListUsageRecordError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Retrieve a list of usage-records belonging to the account used to make the request
48pub async fn list_usage_record(configuration: &configuration::Configuration, params: ListUsageRecordParams) -> Result<models::ListUsageRecordResponse, Error<ListUsageRecordError>> {
49    let local_var_configuration = configuration;
50
51    // unbox the parameters
52    let account_sid = params.account_sid;
53    let category = params.category;
54    let start_date = params.start_date;
55    let end_date = params.end_date;
56    let include_subaccounts = params.include_subaccounts;
57    let page_size = params.page_size;
58    let page = params.page;
59    let page_token = params.page_token;
60
61
62    let local_var_client = &local_var_configuration.client;
63
64    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Usage/Records.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
65    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
66
67    if let Some(ref local_var_str) = category {
68        local_var_req_builder = local_var_req_builder.query(&[("Category", &local_var_str.to_string())]);
69    }
70    if let Some(ref local_var_str) = start_date {
71        local_var_req_builder = local_var_req_builder.query(&[("StartDate", &local_var_str.to_string())]);
72    }
73    if let Some(ref local_var_str) = end_date {
74        local_var_req_builder = local_var_req_builder.query(&[("EndDate", &local_var_str.to_string())]);
75    }
76    if let Some(ref local_var_str) = include_subaccounts {
77        local_var_req_builder = local_var_req_builder.query(&[("IncludeSubaccounts", &local_var_str.to_string())]);
78    }
79    if let Some(ref local_var_str) = page_size {
80        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
81    }
82    if let Some(ref local_var_str) = page {
83        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
84    }
85    if let Some(ref local_var_str) = page_token {
86        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
87    }
88    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90    }
91    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
92        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
93    };
94
95    let local_var_req = local_var_req_builder.build()?;
96    let local_var_resp = local_var_client.execute(local_var_req).await?;
97
98    let local_var_status = local_var_resp.status();
99    let local_var_content = local_var_resp.text().await?;
100
101    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102        serde_json::from_str(&local_var_content).map_err(Error::from)
103    } else {
104        let local_var_entity: Option<ListUsageRecordError> = serde_json::from_str(&local_var_content).ok();
105        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
106        Err(Error::ResponseError(local_var_error))
107    }
108}
109