rusoto_forecastquery/
generated.rs

1// =================================================================
2//
3//                           * WARNING *
4//
5//                    This file is generated!
6//
7//  Changes made to this file will be overwritten. If changes are
8//  required to the generated code, the service_crategen project
9//  must be updated to generate the changes.
10//
11// =================================================================
12
13use std::error::Error;
14use std::fmt;
15
16use async_trait::async_trait;
17use rusoto_core::credential::ProvideAwsCredentials;
18use rusoto_core::region;
19use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
20use rusoto_core::{Client, RusotoError};
21
22use rusoto_core::proto;
23use rusoto_core::request::HttpResponse;
24use rusoto_core::signature::SignedRequest;
25#[allow(unused_imports)]
26use serde::{Deserialize, Serialize};
27
28impl ForecastQueryClient {
29    fn new_signed_request(&self, http_method: &str, request_uri: &str) -> SignedRequest {
30        let mut request = SignedRequest::new(http_method, "forecast", &self.region, request_uri);
31        request.set_endpoint_prefix("forecastquery".to_string());
32
33        request.set_content_type("application/x-amz-json-1.1".to_owned());
34
35        request
36    }
37
38    async fn sign_and_dispatch<E>(
39        &self,
40        request: SignedRequest,
41        from_response: fn(BufferedHttpResponse) -> RusotoError<E>,
42    ) -> Result<HttpResponse, RusotoError<E>> {
43        let mut response = self.client.sign_and_dispatch(request).await?;
44        if !response.status.is_success() {
45            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
46            return Err(from_response(response));
47        }
48
49        Ok(response)
50    }
51}
52
53use serde_json;
54/// <p>The forecast value for a specific date. Part of the <a>Forecast</a> object.</p>
55#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
56#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
57pub struct DataPoint {
58    /// <p>The timestamp of the specific forecast.</p>
59    #[serde(rename = "Timestamp")]
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub timestamp: Option<String>,
62    /// <p>The forecast value.</p>
63    #[serde(rename = "Value")]
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub value: Option<f64>,
66}
67
68/// <p>Provides information about a forecast. Returned as part of the <a>QueryForecast</a> response.</p>
69#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
70#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
71pub struct Forecast {
72    /// <p><p>The forecast.</p> <p>The <i>string</i> of the string-to-array map is one of the following values:</p> <ul> <li> <p>p10</p> </li> <li> <p>p50</p> </li> <li> <p>p90</p> </li> </ul></p>
73    #[serde(rename = "Predictions")]
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub predictions: Option<::std::collections::HashMap<String, Vec<DataPoint>>>,
76}
77
78#[derive(Clone, Debug, Default, PartialEq, Serialize)]
79#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
80pub struct QueryForecastRequest {
81    /// <p>The end date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T20:00:00. </p>
82    #[serde(rename = "EndDate")]
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub end_date: Option<String>,
85    /// <p>The filtering criteria to apply when retrieving the forecast. For example, to get the forecast for <code>client_21</code> in the electricity usage dataset, specify the following:</p> <p> <code>{"item_id" : "client_21"}</code> </p> <p>To get the full forecast, use the <a href="https://docs.aws.amazon.com/en_us/forecast/latest/dg/API_CreateForecastExportJob.html">CreateForecastExportJob</a> operation.</p>
86    #[serde(rename = "Filters")]
87    pub filters: ::std::collections::HashMap<String, String>,
88    /// <p>The Amazon Resource Name (ARN) of the forecast to query.</p>
89    #[serde(rename = "ForecastArn")]
90    pub forecast_arn: String,
91    /// <p>If the result of the previous request was truncated, the response includes a <code>NextToken</code>. To retrieve the next set of results, use the token in the next request. Tokens expire after 24 hours.</p>
92    #[serde(rename = "NextToken")]
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub next_token: Option<String>,
95    /// <p>The start date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T08:00:00.</p>
96    #[serde(rename = "StartDate")]
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub start_date: Option<String>,
99}
100
101#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
102#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
103pub struct QueryForecastResponse {
104    /// <p>The forecast.</p>
105    #[serde(rename = "Forecast")]
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub forecast: Option<Forecast>,
108}
109
110/// Errors returned by QueryForecast
111#[derive(Debug, PartialEq)]
112pub enum QueryForecastError {
113    /// <p>The value is invalid or is too long.</p>
114    InvalidInput(String),
115    /// <p>The token is not valid. Tokens expire after 24 hours.</p>
116    InvalidNextToken(String),
117    /// <p>The limit on the number of requests per second has been exceeded.</p>
118    LimitExceeded(String),
119    /// <p>The specified resource is in use.</p>
120    ResourceInUse(String),
121    /// <p>We can't find that resource. Check the information that you've provided and try again.</p>
122    ResourceNotFound(String),
123}
124
125impl QueryForecastError {
126    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<QueryForecastError> {
127        if let Some(err) = proto::json::Error::parse(&res) {
128            match err.typ.as_str() {
129                "InvalidInputException" => {
130                    return RusotoError::Service(QueryForecastError::InvalidInput(err.msg))
131                }
132                "InvalidNextTokenException" => {
133                    return RusotoError::Service(QueryForecastError::InvalidNextToken(err.msg))
134                }
135                "LimitExceededException" => {
136                    return RusotoError::Service(QueryForecastError::LimitExceeded(err.msg))
137                }
138                "ResourceInUseException" => {
139                    return RusotoError::Service(QueryForecastError::ResourceInUse(err.msg))
140                }
141                "ResourceNotFoundException" => {
142                    return RusotoError::Service(QueryForecastError::ResourceNotFound(err.msg))
143                }
144                "ValidationException" => return RusotoError::Validation(err.msg),
145                _ => {}
146            }
147        }
148        RusotoError::Unknown(res)
149    }
150}
151impl fmt::Display for QueryForecastError {
152    #[allow(unused_variables)]
153    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154        match *self {
155            QueryForecastError::InvalidInput(ref cause) => write!(f, "{}", cause),
156            QueryForecastError::InvalidNextToken(ref cause) => write!(f, "{}", cause),
157            QueryForecastError::LimitExceeded(ref cause) => write!(f, "{}", cause),
158            QueryForecastError::ResourceInUse(ref cause) => write!(f, "{}", cause),
159            QueryForecastError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
160        }
161    }
162}
163impl Error for QueryForecastError {}
164/// Trait representing the capabilities of the Amazon Forecast Query Service API. Amazon Forecast Query Service clients implement this trait.
165#[async_trait]
166pub trait ForecastQuery {
167    /// <p><p>Retrieves a forecast for a single item, filtered by the supplied criteria.</p> <p>The criteria is a key-value pair. The key is either <code>item<em>id</code> (or the equivalent non-timestamp, non-target field) from the <code>TARGET</em>TIME<em>SERIES</code> dataset, or one of the forecast dimensions specified as part of the <code>FeaturizationConfig</code> object.</p> <p>By default, <code>QueryForecast</code> returns the complete date range for the filtered forecast. You can request a specific date range.</p> <p>To get the full forecast, use the &lt;a href=&quot;https://docs.aws.amazon.com/en</em>us/forecast/latest/dg/API_CreateForecastExportJob.html&quot;&gt;CreateForecastExportJob</a> operation.</p> <note> <p>The forecasts generated by Amazon Forecast are in the same timezone as the dataset that was used to create the predictor.</p> </note></p>
168    async fn query_forecast(
169        &self,
170        input: QueryForecastRequest,
171    ) -> Result<QueryForecastResponse, RusotoError<QueryForecastError>>;
172}
173/// A client for the Amazon Forecast Query Service API.
174#[derive(Clone)]
175pub struct ForecastQueryClient {
176    client: Client,
177    region: region::Region,
178}
179
180impl ForecastQueryClient {
181    /// Creates a client backed by the default tokio event loop.
182    ///
183    /// The client will use the default credentials provider and tls client.
184    pub fn new(region: region::Region) -> ForecastQueryClient {
185        ForecastQueryClient {
186            client: Client::shared(),
187            region,
188        }
189    }
190
191    pub fn new_with<P, D>(
192        request_dispatcher: D,
193        credentials_provider: P,
194        region: region::Region,
195    ) -> ForecastQueryClient
196    where
197        P: ProvideAwsCredentials + Send + Sync + 'static,
198        D: DispatchSignedRequest + Send + Sync + 'static,
199    {
200        ForecastQueryClient {
201            client: Client::new_with(credentials_provider, request_dispatcher),
202            region,
203        }
204    }
205
206    pub fn new_with_client(client: Client, region: region::Region) -> ForecastQueryClient {
207        ForecastQueryClient { client, region }
208    }
209}
210
211#[async_trait]
212impl ForecastQuery for ForecastQueryClient {
213    /// <p><p>Retrieves a forecast for a single item, filtered by the supplied criteria.</p> <p>The criteria is a key-value pair. The key is either <code>item<em>id</code> (or the equivalent non-timestamp, non-target field) from the <code>TARGET</em>TIME<em>SERIES</code> dataset, or one of the forecast dimensions specified as part of the <code>FeaturizationConfig</code> object.</p> <p>By default, <code>QueryForecast</code> returns the complete date range for the filtered forecast. You can request a specific date range.</p> <p>To get the full forecast, use the &lt;a href=&quot;https://docs.aws.amazon.com/en</em>us/forecast/latest/dg/API_CreateForecastExportJob.html&quot;&gt;CreateForecastExportJob</a> operation.</p> <note> <p>The forecasts generated by Amazon Forecast are in the same timezone as the dataset that was used to create the predictor.</p> </note></p>
214    async fn query_forecast(
215        &self,
216        input: QueryForecastRequest,
217    ) -> Result<QueryForecastResponse, RusotoError<QueryForecastError>> {
218        let mut request = self.new_signed_request("POST", "/");
219        request.add_header("x-amz-target", "AmazonForecastRuntime.QueryForecast");
220        let encoded = serde_json::to_string(&input).unwrap();
221        request.set_payload(Some(encoded));
222
223        let response = self
224            .sign_and_dispatch(request, QueryForecastError::from_response)
225            .await?;
226        let mut response = response;
227        let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
228        proto::json::ResponsePayload::new(&response).deserialize::<QueryForecastResponse, _>()
229    }
230}