rusoto_iot_data/
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::param::{Params, ServiceParams};
23use rusoto_core::proto;
24use rusoto_core::signature::SignedRequest;
25#[allow(unused_imports)]
26use serde::{Deserialize, Serialize};
27/// <p>The input for the DeleteThingShadow operation.</p>
28#[derive(Clone, Debug, Default, PartialEq, Serialize)]
29#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
30pub struct DeleteThingShadowRequest {
31    /// <p>The name of the shadow.</p>
32    #[serde(rename = "shadowName")]
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub shadow_name: Option<String>,
35    /// <p>The name of the thing.</p>
36    #[serde(rename = "thingName")]
37    pub thing_name: String,
38}
39
40/// <p>The output from the DeleteThingShadow operation.</p>
41#[derive(Clone, Debug, Default, PartialEq)]
42pub struct DeleteThingShadowResponse {
43    /// <p>The state information, in JSON format.</p>
44    pub payload: bytes::Bytes,
45}
46
47/// <p>The input for the GetThingShadow operation.</p>
48#[derive(Clone, Debug, Default, PartialEq, Serialize)]
49#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
50pub struct GetThingShadowRequest {
51    /// <p>The name of the shadow.</p>
52    #[serde(rename = "shadowName")]
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub shadow_name: Option<String>,
55    /// <p>The name of the thing.</p>
56    #[serde(rename = "thingName")]
57    pub thing_name: String,
58}
59
60/// <p>The output from the GetThingShadow operation.</p>
61#[derive(Clone, Debug, Default, PartialEq)]
62pub struct GetThingShadowResponse {
63    /// <p>The state information, in JSON format.</p>
64    pub payload: Option<bytes::Bytes>,
65}
66
67#[derive(Clone, Debug, Default, PartialEq, Serialize)]
68#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
69pub struct ListNamedShadowsForThingRequest {
70    /// <p>The token to retrieve the next set of results.</p>
71    #[serde(rename = "nextToken")]
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub next_token: Option<String>,
74    /// <p>The result page size.</p>
75    #[serde(rename = "pageSize")]
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub page_size: Option<i64>,
78    /// <p>The name of the thing.</p>
79    #[serde(rename = "thingName")]
80    pub thing_name: String,
81}
82
83#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
84#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
85pub struct ListNamedShadowsForThingResponse {
86    /// <p>The token for the next set of results, or null if there are no additional results.</p>
87    #[serde(rename = "nextToken")]
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub next_token: Option<String>,
90    /// <p>The list of shadows for the specified thing.</p>
91    #[serde(rename = "results")]
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub results: Option<Vec<String>>,
94    /// <p>The Epoch date and time the response was generated by AWS IoT.</p>
95    #[serde(rename = "timestamp")]
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub timestamp: Option<i64>,
98}
99
100/// <p>The input for the Publish operation.</p>
101#[derive(Clone, Debug, Default, PartialEq, Serialize)]
102#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
103pub struct PublishRequest {
104    /// <p>The state information, in JSON format.</p>
105    #[serde(rename = "payload")]
106    #[serde(
107        deserialize_with = "::rusoto_core::serialization::SerdeBlob::deserialize_blob",
108        serialize_with = "::rusoto_core::serialization::SerdeBlob::serialize_blob",
109        default
110    )]
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub payload: Option<bytes::Bytes>,
113    /// <p>The Quality of Service (QoS) level.</p>
114    #[serde(rename = "qos")]
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub qos: Option<i64>,
117    /// <p>The name of the MQTT topic.</p>
118    #[serde(rename = "topic")]
119    pub topic: String,
120}
121
122/// <p>The input for the UpdateThingShadow operation.</p>
123#[derive(Clone, Debug, Default, PartialEq, Serialize)]
124#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
125pub struct UpdateThingShadowRequest {
126    /// <p>The state information, in JSON format.</p>
127    #[serde(rename = "payload")]
128    #[serde(
129        deserialize_with = "::rusoto_core::serialization::SerdeBlob::deserialize_blob",
130        serialize_with = "::rusoto_core::serialization::SerdeBlob::serialize_blob",
131        default
132    )]
133    pub payload: bytes::Bytes,
134    /// <p>The name of the shadow.</p>
135    #[serde(rename = "shadowName")]
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub shadow_name: Option<String>,
138    /// <p>The name of the thing.</p>
139    #[serde(rename = "thingName")]
140    pub thing_name: String,
141}
142
143/// <p>The output from the UpdateThingShadow operation.</p>
144#[derive(Clone, Debug, Default, PartialEq)]
145pub struct UpdateThingShadowResponse {
146    /// <p>The state information, in JSON format.</p>
147    pub payload: Option<bytes::Bytes>,
148}
149
150/// Errors returned by DeleteThingShadow
151#[derive(Debug, PartialEq)]
152pub enum DeleteThingShadowError {
153    /// <p>An unexpected error has occurred.</p>
154    InternalFailure(String),
155    /// <p>The request is not valid.</p>
156    InvalidRequest(String),
157    /// <p>The specified combination of HTTP verb and URI is not supported.</p>
158    MethodNotAllowed(String),
159    /// <p>The specified resource does not exist.</p>
160    ResourceNotFound(String),
161    /// <p>The service is temporarily unavailable.</p>
162    ServiceUnavailable(String),
163    /// <p>The rate exceeds the limit.</p>
164    Throttling(String),
165    /// <p>You are not authorized to perform this operation.</p>
166    Unauthorized(String),
167    /// <p>The document encoding is not supported.</p>
168    UnsupportedDocumentEncoding(String),
169}
170
171impl DeleteThingShadowError {
172    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeleteThingShadowError> {
173        if let Some(err) = proto::json::Error::parse_rest(&res) {
174            match err.typ.as_str() {
175                "InternalFailureException" => {
176                    return RusotoError::Service(DeleteThingShadowError::InternalFailure(err.msg))
177                }
178                "InvalidRequestException" => {
179                    return RusotoError::Service(DeleteThingShadowError::InvalidRequest(err.msg))
180                }
181                "MethodNotAllowedException" => {
182                    return RusotoError::Service(DeleteThingShadowError::MethodNotAllowed(err.msg))
183                }
184                "ResourceNotFoundException" => {
185                    return RusotoError::Service(DeleteThingShadowError::ResourceNotFound(err.msg))
186                }
187                "ServiceUnavailableException" => {
188                    return RusotoError::Service(DeleteThingShadowError::ServiceUnavailable(
189                        err.msg,
190                    ))
191                }
192                "ThrottlingException" => {
193                    return RusotoError::Service(DeleteThingShadowError::Throttling(err.msg))
194                }
195                "UnauthorizedException" => {
196                    return RusotoError::Service(DeleteThingShadowError::Unauthorized(err.msg))
197                }
198                "UnsupportedDocumentEncodingException" => {
199                    return RusotoError::Service(
200                        DeleteThingShadowError::UnsupportedDocumentEncoding(err.msg),
201                    )
202                }
203                "ValidationException" => return RusotoError::Validation(err.msg),
204                _ => {}
205            }
206        }
207        RusotoError::Unknown(res)
208    }
209}
210impl fmt::Display for DeleteThingShadowError {
211    #[allow(unused_variables)]
212    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
213        match *self {
214            DeleteThingShadowError::InternalFailure(ref cause) => write!(f, "{}", cause),
215            DeleteThingShadowError::InvalidRequest(ref cause) => write!(f, "{}", cause),
216            DeleteThingShadowError::MethodNotAllowed(ref cause) => write!(f, "{}", cause),
217            DeleteThingShadowError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
218            DeleteThingShadowError::ServiceUnavailable(ref cause) => write!(f, "{}", cause),
219            DeleteThingShadowError::Throttling(ref cause) => write!(f, "{}", cause),
220            DeleteThingShadowError::Unauthorized(ref cause) => write!(f, "{}", cause),
221            DeleteThingShadowError::UnsupportedDocumentEncoding(ref cause) => {
222                write!(f, "{}", cause)
223            }
224        }
225    }
226}
227impl Error for DeleteThingShadowError {}
228/// Errors returned by GetThingShadow
229#[derive(Debug, PartialEq)]
230pub enum GetThingShadowError {
231    /// <p>An unexpected error has occurred.</p>
232    InternalFailure(String),
233    /// <p>The request is not valid.</p>
234    InvalidRequest(String),
235    /// <p>The specified combination of HTTP verb and URI is not supported.</p>
236    MethodNotAllowed(String),
237    /// <p>The specified resource does not exist.</p>
238    ResourceNotFound(String),
239    /// <p>The service is temporarily unavailable.</p>
240    ServiceUnavailable(String),
241    /// <p>The rate exceeds the limit.</p>
242    Throttling(String),
243    /// <p>You are not authorized to perform this operation.</p>
244    Unauthorized(String),
245    /// <p>The document encoding is not supported.</p>
246    UnsupportedDocumentEncoding(String),
247}
248
249impl GetThingShadowError {
250    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetThingShadowError> {
251        if let Some(err) = proto::json::Error::parse_rest(&res) {
252            match err.typ.as_str() {
253                "InternalFailureException" => {
254                    return RusotoError::Service(GetThingShadowError::InternalFailure(err.msg))
255                }
256                "InvalidRequestException" => {
257                    return RusotoError::Service(GetThingShadowError::InvalidRequest(err.msg))
258                }
259                "MethodNotAllowedException" => {
260                    return RusotoError::Service(GetThingShadowError::MethodNotAllowed(err.msg))
261                }
262                "ResourceNotFoundException" => {
263                    return RusotoError::Service(GetThingShadowError::ResourceNotFound(err.msg))
264                }
265                "ServiceUnavailableException" => {
266                    return RusotoError::Service(GetThingShadowError::ServiceUnavailable(err.msg))
267                }
268                "ThrottlingException" => {
269                    return RusotoError::Service(GetThingShadowError::Throttling(err.msg))
270                }
271                "UnauthorizedException" => {
272                    return RusotoError::Service(GetThingShadowError::Unauthorized(err.msg))
273                }
274                "UnsupportedDocumentEncodingException" => {
275                    return RusotoError::Service(GetThingShadowError::UnsupportedDocumentEncoding(
276                        err.msg,
277                    ))
278                }
279                "ValidationException" => return RusotoError::Validation(err.msg),
280                _ => {}
281            }
282        }
283        RusotoError::Unknown(res)
284    }
285}
286impl fmt::Display for GetThingShadowError {
287    #[allow(unused_variables)]
288    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
289        match *self {
290            GetThingShadowError::InternalFailure(ref cause) => write!(f, "{}", cause),
291            GetThingShadowError::InvalidRequest(ref cause) => write!(f, "{}", cause),
292            GetThingShadowError::MethodNotAllowed(ref cause) => write!(f, "{}", cause),
293            GetThingShadowError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
294            GetThingShadowError::ServiceUnavailable(ref cause) => write!(f, "{}", cause),
295            GetThingShadowError::Throttling(ref cause) => write!(f, "{}", cause),
296            GetThingShadowError::Unauthorized(ref cause) => write!(f, "{}", cause),
297            GetThingShadowError::UnsupportedDocumentEncoding(ref cause) => write!(f, "{}", cause),
298        }
299    }
300}
301impl Error for GetThingShadowError {}
302/// Errors returned by ListNamedShadowsForThing
303#[derive(Debug, PartialEq)]
304pub enum ListNamedShadowsForThingError {
305    /// <p>An unexpected error has occurred.</p>
306    InternalFailure(String),
307    /// <p>The request is not valid.</p>
308    InvalidRequest(String),
309    /// <p>The specified combination of HTTP verb and URI is not supported.</p>
310    MethodNotAllowed(String),
311    /// <p>The specified resource does not exist.</p>
312    ResourceNotFound(String),
313    /// <p>The service is temporarily unavailable.</p>
314    ServiceUnavailable(String),
315    /// <p>The rate exceeds the limit.</p>
316    Throttling(String),
317    /// <p>You are not authorized to perform this operation.</p>
318    Unauthorized(String),
319}
320
321impl ListNamedShadowsForThingError {
322    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListNamedShadowsForThingError> {
323        if let Some(err) = proto::json::Error::parse_rest(&res) {
324            match err.typ.as_str() {
325                "InternalFailureException" => {
326                    return RusotoError::Service(ListNamedShadowsForThingError::InternalFailure(
327                        err.msg,
328                    ))
329                }
330                "InvalidRequestException" => {
331                    return RusotoError::Service(ListNamedShadowsForThingError::InvalidRequest(
332                        err.msg,
333                    ))
334                }
335                "MethodNotAllowedException" => {
336                    return RusotoError::Service(ListNamedShadowsForThingError::MethodNotAllowed(
337                        err.msg,
338                    ))
339                }
340                "ResourceNotFoundException" => {
341                    return RusotoError::Service(ListNamedShadowsForThingError::ResourceNotFound(
342                        err.msg,
343                    ))
344                }
345                "ServiceUnavailableException" => {
346                    return RusotoError::Service(ListNamedShadowsForThingError::ServiceUnavailable(
347                        err.msg,
348                    ))
349                }
350                "ThrottlingException" => {
351                    return RusotoError::Service(ListNamedShadowsForThingError::Throttling(err.msg))
352                }
353                "UnauthorizedException" => {
354                    return RusotoError::Service(ListNamedShadowsForThingError::Unauthorized(
355                        err.msg,
356                    ))
357                }
358                "ValidationException" => return RusotoError::Validation(err.msg),
359                _ => {}
360            }
361        }
362        RusotoError::Unknown(res)
363    }
364}
365impl fmt::Display for ListNamedShadowsForThingError {
366    #[allow(unused_variables)]
367    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
368        match *self {
369            ListNamedShadowsForThingError::InternalFailure(ref cause) => write!(f, "{}", cause),
370            ListNamedShadowsForThingError::InvalidRequest(ref cause) => write!(f, "{}", cause),
371            ListNamedShadowsForThingError::MethodNotAllowed(ref cause) => write!(f, "{}", cause),
372            ListNamedShadowsForThingError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
373            ListNamedShadowsForThingError::ServiceUnavailable(ref cause) => write!(f, "{}", cause),
374            ListNamedShadowsForThingError::Throttling(ref cause) => write!(f, "{}", cause),
375            ListNamedShadowsForThingError::Unauthorized(ref cause) => write!(f, "{}", cause),
376        }
377    }
378}
379impl Error for ListNamedShadowsForThingError {}
380/// Errors returned by Publish
381#[derive(Debug, PartialEq)]
382pub enum PublishError {
383    /// <p>An unexpected error has occurred.</p>
384    InternalFailure(String),
385    /// <p>The request is not valid.</p>
386    InvalidRequest(String),
387    /// <p>The specified combination of HTTP verb and URI is not supported.</p>
388    MethodNotAllowed(String),
389    /// <p>You are not authorized to perform this operation.</p>
390    Unauthorized(String),
391}
392
393impl PublishError {
394    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<PublishError> {
395        if let Some(err) = proto::json::Error::parse_rest(&res) {
396            match err.typ.as_str() {
397                "InternalFailureException" => {
398                    return RusotoError::Service(PublishError::InternalFailure(err.msg))
399                }
400                "InvalidRequestException" => {
401                    return RusotoError::Service(PublishError::InvalidRequest(err.msg))
402                }
403                "MethodNotAllowedException" => {
404                    return RusotoError::Service(PublishError::MethodNotAllowed(err.msg))
405                }
406                "UnauthorizedException" => {
407                    return RusotoError::Service(PublishError::Unauthorized(err.msg))
408                }
409                "ValidationException" => return RusotoError::Validation(err.msg),
410                _ => {}
411            }
412        }
413        RusotoError::Unknown(res)
414    }
415}
416impl fmt::Display for PublishError {
417    #[allow(unused_variables)]
418    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
419        match *self {
420            PublishError::InternalFailure(ref cause) => write!(f, "{}", cause),
421            PublishError::InvalidRequest(ref cause) => write!(f, "{}", cause),
422            PublishError::MethodNotAllowed(ref cause) => write!(f, "{}", cause),
423            PublishError::Unauthorized(ref cause) => write!(f, "{}", cause),
424        }
425    }
426}
427impl Error for PublishError {}
428/// Errors returned by UpdateThingShadow
429#[derive(Debug, PartialEq)]
430pub enum UpdateThingShadowError {
431    /// <p>The specified version does not match the version of the document.</p>
432    Conflict(String),
433    /// <p>An unexpected error has occurred.</p>
434    InternalFailure(String),
435    /// <p>The request is not valid.</p>
436    InvalidRequest(String),
437    /// <p>The specified combination of HTTP verb and URI is not supported.</p>
438    MethodNotAllowed(String),
439    /// <p>The payload exceeds the maximum size allowed.</p>
440    RequestEntityTooLarge(String),
441    /// <p>The service is temporarily unavailable.</p>
442    ServiceUnavailable(String),
443    /// <p>The rate exceeds the limit.</p>
444    Throttling(String),
445    /// <p>You are not authorized to perform this operation.</p>
446    Unauthorized(String),
447    /// <p>The document encoding is not supported.</p>
448    UnsupportedDocumentEncoding(String),
449}
450
451impl UpdateThingShadowError {
452    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<UpdateThingShadowError> {
453        if let Some(err) = proto::json::Error::parse_rest(&res) {
454            match err.typ.as_str() {
455                "ConflictException" => {
456                    return RusotoError::Service(UpdateThingShadowError::Conflict(err.msg))
457                }
458                "InternalFailureException" => {
459                    return RusotoError::Service(UpdateThingShadowError::InternalFailure(err.msg))
460                }
461                "InvalidRequestException" => {
462                    return RusotoError::Service(UpdateThingShadowError::InvalidRequest(err.msg))
463                }
464                "MethodNotAllowedException" => {
465                    return RusotoError::Service(UpdateThingShadowError::MethodNotAllowed(err.msg))
466                }
467                "RequestEntityTooLargeException" => {
468                    return RusotoError::Service(UpdateThingShadowError::RequestEntityTooLarge(
469                        err.msg,
470                    ))
471                }
472                "ServiceUnavailableException" => {
473                    return RusotoError::Service(UpdateThingShadowError::ServiceUnavailable(
474                        err.msg,
475                    ))
476                }
477                "ThrottlingException" => {
478                    return RusotoError::Service(UpdateThingShadowError::Throttling(err.msg))
479                }
480                "UnauthorizedException" => {
481                    return RusotoError::Service(UpdateThingShadowError::Unauthorized(err.msg))
482                }
483                "UnsupportedDocumentEncodingException" => {
484                    return RusotoError::Service(
485                        UpdateThingShadowError::UnsupportedDocumentEncoding(err.msg),
486                    )
487                }
488                "ValidationException" => return RusotoError::Validation(err.msg),
489                _ => {}
490            }
491        }
492        RusotoError::Unknown(res)
493    }
494}
495impl fmt::Display for UpdateThingShadowError {
496    #[allow(unused_variables)]
497    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
498        match *self {
499            UpdateThingShadowError::Conflict(ref cause) => write!(f, "{}", cause),
500            UpdateThingShadowError::InternalFailure(ref cause) => write!(f, "{}", cause),
501            UpdateThingShadowError::InvalidRequest(ref cause) => write!(f, "{}", cause),
502            UpdateThingShadowError::MethodNotAllowed(ref cause) => write!(f, "{}", cause),
503            UpdateThingShadowError::RequestEntityTooLarge(ref cause) => write!(f, "{}", cause),
504            UpdateThingShadowError::ServiceUnavailable(ref cause) => write!(f, "{}", cause),
505            UpdateThingShadowError::Throttling(ref cause) => write!(f, "{}", cause),
506            UpdateThingShadowError::Unauthorized(ref cause) => write!(f, "{}", cause),
507            UpdateThingShadowError::UnsupportedDocumentEncoding(ref cause) => {
508                write!(f, "{}", cause)
509            }
510        }
511    }
512}
513impl Error for UpdateThingShadowError {}
514/// Trait representing the capabilities of the AWS IoT Data Plane API. AWS IoT Data Plane clients implement this trait.
515#[async_trait]
516pub trait IotData {
517    /// <p>Deletes the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_DeleteThingShadow.html">DeleteThingShadow</a> in the AWS IoT Developer Guide.</p>
518    async fn delete_thing_shadow(
519        &self,
520        input: DeleteThingShadowRequest,
521    ) -> Result<DeleteThingShadowResponse, RusotoError<DeleteThingShadowError>>;
522
523    /// <p>Gets the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_GetThingShadow.html">GetThingShadow</a> in the AWS IoT Developer Guide.</p>
524    async fn get_thing_shadow(
525        &self,
526        input: GetThingShadowRequest,
527    ) -> Result<GetThingShadowResponse, RusotoError<GetThingShadowError>>;
528
529    /// <p>Lists the shadows for the specified thing.</p>
530    async fn list_named_shadows_for_thing(
531        &self,
532        input: ListNamedShadowsForThingRequest,
533    ) -> Result<ListNamedShadowsForThingResponse, RusotoError<ListNamedShadowsForThingError>>;
534
535    /// <p>Publishes state information.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html#http">HTTP Protocol</a> in the AWS IoT Developer Guide.</p>
536    async fn publish(&self, input: PublishRequest) -> Result<(), RusotoError<PublishError>>;
537
538    /// <p>Updates the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_UpdateThingShadow.html">UpdateThingShadow</a> in the AWS IoT Developer Guide.</p>
539    async fn update_thing_shadow(
540        &self,
541        input: UpdateThingShadowRequest,
542    ) -> Result<UpdateThingShadowResponse, RusotoError<UpdateThingShadowError>>;
543}
544/// A client for the AWS IoT Data Plane API.
545#[derive(Clone)]
546pub struct IotDataClient {
547    client: Client,
548    region: region::Region,
549}
550
551impl IotDataClient {
552    /// Creates a client backed by the default tokio event loop.
553    ///
554    /// The client will use the default credentials provider and tls client.
555    pub fn new(region: region::Region) -> IotDataClient {
556        IotDataClient {
557            client: Client::shared(),
558            region,
559        }
560    }
561
562    pub fn new_with<P, D>(
563        request_dispatcher: D,
564        credentials_provider: P,
565        region: region::Region,
566    ) -> IotDataClient
567    where
568        P: ProvideAwsCredentials + Send + Sync + 'static,
569        D: DispatchSignedRequest + Send + Sync + 'static,
570    {
571        IotDataClient {
572            client: Client::new_with(credentials_provider, request_dispatcher),
573            region,
574        }
575    }
576
577    pub fn new_with_client(client: Client, region: region::Region) -> IotDataClient {
578        IotDataClient { client, region }
579    }
580}
581
582#[async_trait]
583impl IotData for IotDataClient {
584    /// <p>Deletes the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_DeleteThingShadow.html">DeleteThingShadow</a> in the AWS IoT Developer Guide.</p>
585    #[allow(unused_mut)]
586    async fn delete_thing_shadow(
587        &self,
588        input: DeleteThingShadowRequest,
589    ) -> Result<DeleteThingShadowResponse, RusotoError<DeleteThingShadowError>> {
590        let request_uri = format!("/things/{thing_name}/shadow", thing_name = input.thing_name);
591
592        let mut request = SignedRequest::new("DELETE", "iotdata", &self.region, &request_uri);
593        request.set_content_type("application/x-amz-json-1.1".to_owned());
594
595        request.set_endpoint_prefix("data.iot".to_string());
596
597        let mut params = Params::new();
598        if let Some(ref x) = input.shadow_name {
599            params.put("name", x);
600        }
601        request.set_params(params);
602
603        let mut response = self
604            .client
605            .sign_and_dispatch(request)
606            .await
607            .map_err(RusotoError::from)?;
608        if response.status.is_success() {
609            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
610
611            let mut result = DeleteThingShadowResponse::default();
612            result.payload = response.body;
613
614            Ok(result)
615        } else {
616            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
617            Err(DeleteThingShadowError::from_response(response))
618        }
619    }
620
621    /// <p>Gets the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_GetThingShadow.html">GetThingShadow</a> in the AWS IoT Developer Guide.</p>
622    #[allow(unused_mut)]
623    async fn get_thing_shadow(
624        &self,
625        input: GetThingShadowRequest,
626    ) -> Result<GetThingShadowResponse, RusotoError<GetThingShadowError>> {
627        let request_uri = format!("/things/{thing_name}/shadow", thing_name = input.thing_name);
628
629        let mut request = SignedRequest::new("GET", "iotdata", &self.region, &request_uri);
630        request.set_content_type("application/x-amz-json-1.1".to_owned());
631
632        request.set_endpoint_prefix("data.iot".to_string());
633
634        let mut params = Params::new();
635        if let Some(ref x) = input.shadow_name {
636            params.put("name", x);
637        }
638        request.set_params(params);
639
640        let mut response = self
641            .client
642            .sign_and_dispatch(request)
643            .await
644            .map_err(RusotoError::from)?;
645        if response.status.is_success() {
646            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
647
648            let mut result = GetThingShadowResponse::default();
649            result.payload = Some(response.body);
650
651            Ok(result)
652        } else {
653            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
654            Err(GetThingShadowError::from_response(response))
655        }
656    }
657
658    /// <p>Lists the shadows for the specified thing.</p>
659    #[allow(unused_mut)]
660    async fn list_named_shadows_for_thing(
661        &self,
662        input: ListNamedShadowsForThingRequest,
663    ) -> Result<ListNamedShadowsForThingResponse, RusotoError<ListNamedShadowsForThingError>> {
664        let request_uri = format!(
665            "/api/things/shadow/ListNamedShadowsForThing/{thing_name}",
666            thing_name = input.thing_name
667        );
668
669        let mut request = SignedRequest::new("GET", "iotdata", &self.region, &request_uri);
670        request.set_content_type("application/x-amz-json-1.1".to_owned());
671
672        request.set_endpoint_prefix("data.iot".to_string());
673
674        let mut params = Params::new();
675        if let Some(ref x) = input.next_token {
676            params.put("nextToken", x);
677        }
678        if let Some(ref x) = input.page_size {
679            params.put("pageSize", x);
680        }
681        request.set_params(params);
682
683        let mut response = self
684            .client
685            .sign_and_dispatch(request)
686            .await
687            .map_err(RusotoError::from)?;
688        if response.status.is_success() {
689            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
690            let result = proto::json::ResponsePayload::new(&response)
691                .deserialize::<ListNamedShadowsForThingResponse, _>()?;
692
693            Ok(result)
694        } else {
695            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
696            Err(ListNamedShadowsForThingError::from_response(response))
697        }
698    }
699
700    /// <p>Publishes state information.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html#http">HTTP Protocol</a> in the AWS IoT Developer Guide.</p>
701    #[allow(unused_mut)]
702    async fn publish(&self, input: PublishRequest) -> Result<(), RusotoError<PublishError>> {
703        let request_uri = format!("/topics/{topic}", topic = input.topic);
704
705        let mut request = SignedRequest::new("POST", "iotdata", &self.region, &request_uri);
706        request.set_content_type("application/x-amz-json-1.1".to_owned());
707
708        request.set_endpoint_prefix("data.iot".to_string());
709        let encoded = if let Some(ref payload) = input.payload {
710            Some(payload.to_owned())
711        } else {
712            None
713        };
714        request.set_payload(encoded);
715
716        let mut params = Params::new();
717        if let Some(ref x) = input.qos {
718            params.put("qos", x);
719        }
720        request.set_params(params);
721
722        let mut response = self
723            .client
724            .sign_and_dispatch(request)
725            .await
726            .map_err(RusotoError::from)?;
727        if response.status.is_success() {
728            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
729            let result = ::std::mem::drop(response);
730
731            Ok(result)
732        } else {
733            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
734            Err(PublishError::from_response(response))
735        }
736    }
737
738    /// <p>Updates the shadow for the specified thing.</p> <p>For more information, see <a href="http://docs.aws.amazon.com/iot/latest/developerguide/API_UpdateThingShadow.html">UpdateThingShadow</a> in the AWS IoT Developer Guide.</p>
739    #[allow(unused_mut)]
740    async fn update_thing_shadow(
741        &self,
742        input: UpdateThingShadowRequest,
743    ) -> Result<UpdateThingShadowResponse, RusotoError<UpdateThingShadowError>> {
744        let request_uri = format!("/things/{thing_name}/shadow", thing_name = input.thing_name);
745
746        let mut request = SignedRequest::new("POST", "iotdata", &self.region, &request_uri);
747        request.set_content_type("application/x-amz-json-1.1".to_owned());
748
749        request.set_endpoint_prefix("data.iot".to_string());
750        let encoded = Some(input.payload.to_owned());
751        request.set_payload(encoded);
752
753        let mut params = Params::new();
754        if let Some(ref x) = input.shadow_name {
755            params.put("name", x);
756        }
757        request.set_params(params);
758
759        let mut response = self
760            .client
761            .sign_and_dispatch(request)
762            .await
763            .map_err(RusotoError::from)?;
764        if response.status.is_success() {
765            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
766
767            let mut result = UpdateThingShadowResponse::default();
768            result.payload = Some(response.body);
769
770            Ok(result)
771        } else {
772            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
773            Err(UpdateThingShadowError::from_response(response))
774        }
775    }
776}