use std::error::Error;
use std::fmt;
use std::io;
#[allow(warnings)]
use futures::future;
use futures::Future;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoFuture};
use rusoto_core::credential::{CredentialsError, ProvideAwsCredentials};
use rusoto_core::request::HttpDispatchError;
use rusoto_core::param::{Params, ServiceParams};
use rusoto_core::signature::SignedRequest;
use serde_json;
use serde_json::from_slice;
use serde_json::Value as SerdeJsonValue;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CdnConfiguration {
#[serde(rename = "AdSegmentUrlPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ad_segment_url_prefix: Option<String>,
#[serde(rename = "ContentSegmentUrlPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub content_segment_url_prefix: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DashConfiguration {
#[serde(rename = "ManifestEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub manifest_endpoint_prefix: Option<String>,
#[serde(rename = "MpdLocation")]
#[serde(skip_serializing_if = "Option::is_none")]
pub mpd_location: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DashConfigurationForPut {
#[serde(rename = "MpdLocation")]
#[serde(skip_serializing_if = "Option::is_none")]
pub mpd_location: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeletePlaybackConfigurationRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeletePlaybackConfigurationResponse {}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Empty {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetPlaybackConfigurationRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetPlaybackConfigurationResponse {
#[serde(rename = "AdDecisionServerUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ad_decision_server_url: Option<String>,
#[serde(rename = "CdnConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cdn_configuration: Option<CdnConfiguration>,
#[serde(rename = "DashConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dash_configuration: Option<DashConfiguration>,
#[serde(rename = "HlsConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hls_configuration: Option<HlsConfiguration>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "PlaybackConfigurationArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_configuration_arn: Option<String>,
#[serde(rename = "PlaybackEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_endpoint_prefix: Option<String>,
#[serde(rename = "SessionInitializationEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub session_initialization_endpoint_prefix: Option<String>,
#[serde(rename = "SlateAdUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub slate_ad_url: Option<String>,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "TranscodeProfileName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcode_profile_name: Option<String>,
#[serde(rename = "VideoContentSourceUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub video_content_source_url: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct HlsConfiguration {
#[serde(rename = "ManifestEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub manifest_endpoint_prefix: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListPlaybackConfigurationsRequest {
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListPlaybackConfigurationsResponse {
#[serde(rename = "Items")]
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Vec<PlaybackConfiguration>>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListTagsForResourceRequest {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListTagsForResourceResponse {
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PlaybackConfiguration {
#[serde(rename = "AdDecisionServerUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ad_decision_server_url: Option<String>,
#[serde(rename = "CdnConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cdn_configuration: Option<CdnConfiguration>,
#[serde(rename = "DashConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dash_configuration: Option<DashConfiguration>,
#[serde(rename = "HlsConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hls_configuration: Option<HlsConfiguration>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "PlaybackConfigurationArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_configuration_arn: Option<String>,
#[serde(rename = "PlaybackEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_endpoint_prefix: Option<String>,
#[serde(rename = "SessionInitializationEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub session_initialization_endpoint_prefix: Option<String>,
#[serde(rename = "SlateAdUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub slate_ad_url: Option<String>,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "TranscodeProfileName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcode_profile_name: Option<String>,
#[serde(rename = "VideoContentSourceUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub video_content_source_url: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct PutPlaybackConfigurationRequest {
#[serde(rename = "AdDecisionServerUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ad_decision_server_url: Option<String>,
#[serde(rename = "CdnConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cdn_configuration: Option<CdnConfiguration>,
#[serde(rename = "DashConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dash_configuration: Option<DashConfigurationForPut>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "SlateAdUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub slate_ad_url: Option<String>,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "TranscodeProfileName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcode_profile_name: Option<String>,
#[serde(rename = "VideoContentSourceUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub video_content_source_url: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PutPlaybackConfigurationResponse {
#[serde(rename = "AdDecisionServerUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ad_decision_server_url: Option<String>,
#[serde(rename = "CdnConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cdn_configuration: Option<CdnConfiguration>,
#[serde(rename = "DashConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dash_configuration: Option<DashConfiguration>,
#[serde(rename = "HlsConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hls_configuration: Option<HlsConfiguration>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "PlaybackConfigurationArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_configuration_arn: Option<String>,
#[serde(rename = "PlaybackEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub playback_endpoint_prefix: Option<String>,
#[serde(rename = "SessionInitializationEndpointPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub session_initialization_endpoint_prefix: Option<String>,
#[serde(rename = "SlateAdUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub slate_ad_url: Option<String>,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "TranscodeProfileName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcode_profile_name: Option<String>,
#[serde(rename = "VideoContentSourceUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub video_content_source_url: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct TagResourceRequest {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
#[serde(rename = "Tags")]
pub tags: ::std::collections::HashMap<String, String>,
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct TagsModel {
pub tags: ::std::collections::HashMap<String, String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UntagResourceRequest {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
#[serde(rename = "TagKeys")]
pub tag_keys: Vec<String>,
}
#[derive(Debug, PartialEq)]
pub enum DeletePlaybackConfigurationError {
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeletePlaybackConfigurationError {
pub fn from_response(res: BufferedHttpResponse) -> DeletePlaybackConfigurationError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ValidationException" => {
return DeletePlaybackConfigurationError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeletePlaybackConfigurationError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeletePlaybackConfigurationError {
fn from(err: serde_json::error::Error) -> DeletePlaybackConfigurationError {
DeletePlaybackConfigurationError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeletePlaybackConfigurationError {
fn from(err: CredentialsError) -> DeletePlaybackConfigurationError {
DeletePlaybackConfigurationError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeletePlaybackConfigurationError {
fn from(err: HttpDispatchError) -> DeletePlaybackConfigurationError {
DeletePlaybackConfigurationError::HttpDispatch(err)
}
}
impl From<io::Error> for DeletePlaybackConfigurationError {
fn from(err: io::Error) -> DeletePlaybackConfigurationError {
DeletePlaybackConfigurationError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeletePlaybackConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeletePlaybackConfigurationError {
fn description(&self) -> &str {
match *self {
DeletePlaybackConfigurationError::Validation(ref cause) => cause,
DeletePlaybackConfigurationError::Credentials(ref err) => err.description(),
DeletePlaybackConfigurationError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DeletePlaybackConfigurationError::ParseError(ref cause) => cause,
DeletePlaybackConfigurationError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetPlaybackConfigurationError {
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetPlaybackConfigurationError {
pub fn from_response(res: BufferedHttpResponse) -> GetPlaybackConfigurationError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ValidationException" => {
return GetPlaybackConfigurationError::Validation(error_message.to_string());
}
_ => {}
}
}
return GetPlaybackConfigurationError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetPlaybackConfigurationError {
fn from(err: serde_json::error::Error) -> GetPlaybackConfigurationError {
GetPlaybackConfigurationError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetPlaybackConfigurationError {
fn from(err: CredentialsError) -> GetPlaybackConfigurationError {
GetPlaybackConfigurationError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetPlaybackConfigurationError {
fn from(err: HttpDispatchError) -> GetPlaybackConfigurationError {
GetPlaybackConfigurationError::HttpDispatch(err)
}
}
impl From<io::Error> for GetPlaybackConfigurationError {
fn from(err: io::Error) -> GetPlaybackConfigurationError {
GetPlaybackConfigurationError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetPlaybackConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetPlaybackConfigurationError {
fn description(&self) -> &str {
match *self {
GetPlaybackConfigurationError::Validation(ref cause) => cause,
GetPlaybackConfigurationError::Credentials(ref err) => err.description(),
GetPlaybackConfigurationError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
GetPlaybackConfigurationError::ParseError(ref cause) => cause,
GetPlaybackConfigurationError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListPlaybackConfigurationsError {
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListPlaybackConfigurationsError {
pub fn from_response(res: BufferedHttpResponse) -> ListPlaybackConfigurationsError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ValidationException" => {
return ListPlaybackConfigurationsError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListPlaybackConfigurationsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListPlaybackConfigurationsError {
fn from(err: serde_json::error::Error) -> ListPlaybackConfigurationsError {
ListPlaybackConfigurationsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListPlaybackConfigurationsError {
fn from(err: CredentialsError) -> ListPlaybackConfigurationsError {
ListPlaybackConfigurationsError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListPlaybackConfigurationsError {
fn from(err: HttpDispatchError) -> ListPlaybackConfigurationsError {
ListPlaybackConfigurationsError::HttpDispatch(err)
}
}
impl From<io::Error> for ListPlaybackConfigurationsError {
fn from(err: io::Error) -> ListPlaybackConfigurationsError {
ListPlaybackConfigurationsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListPlaybackConfigurationsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListPlaybackConfigurationsError {
fn description(&self) -> &str {
match *self {
ListPlaybackConfigurationsError::Validation(ref cause) => cause,
ListPlaybackConfigurationsError::Credentials(ref err) => err.description(),
ListPlaybackConfigurationsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
ListPlaybackConfigurationsError::ParseError(ref cause) => cause,
ListPlaybackConfigurationsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListTagsForResourceError {
BadRequest(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListTagsForResourceError {
pub fn from_response(res: BufferedHttpResponse) -> ListTagsForResourceError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"BadRequestException" => {
return ListTagsForResourceError::BadRequest(String::from(error_message));
}
"ValidationException" => {
return ListTagsForResourceError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListTagsForResourceError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListTagsForResourceError {
fn from(err: serde_json::error::Error) -> ListTagsForResourceError {
ListTagsForResourceError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListTagsForResourceError {
fn from(err: CredentialsError) -> ListTagsForResourceError {
ListTagsForResourceError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListTagsForResourceError {
fn from(err: HttpDispatchError) -> ListTagsForResourceError {
ListTagsForResourceError::HttpDispatch(err)
}
}
impl From<io::Error> for ListTagsForResourceError {
fn from(err: io::Error) -> ListTagsForResourceError {
ListTagsForResourceError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListTagsForResourceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListTagsForResourceError {
fn description(&self) -> &str {
match *self {
ListTagsForResourceError::BadRequest(ref cause) => cause,
ListTagsForResourceError::Validation(ref cause) => cause,
ListTagsForResourceError::Credentials(ref err) => err.description(),
ListTagsForResourceError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
ListTagsForResourceError::ParseError(ref cause) => cause,
ListTagsForResourceError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum PutPlaybackConfigurationError {
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl PutPlaybackConfigurationError {
pub fn from_response(res: BufferedHttpResponse) -> PutPlaybackConfigurationError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ValidationException" => {
return PutPlaybackConfigurationError::Validation(error_message.to_string());
}
_ => {}
}
}
return PutPlaybackConfigurationError::Unknown(res);
}
}
impl From<serde_json::error::Error> for PutPlaybackConfigurationError {
fn from(err: serde_json::error::Error) -> PutPlaybackConfigurationError {
PutPlaybackConfigurationError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for PutPlaybackConfigurationError {
fn from(err: CredentialsError) -> PutPlaybackConfigurationError {
PutPlaybackConfigurationError::Credentials(err)
}
}
impl From<HttpDispatchError> for PutPlaybackConfigurationError {
fn from(err: HttpDispatchError) -> PutPlaybackConfigurationError {
PutPlaybackConfigurationError::HttpDispatch(err)
}
}
impl From<io::Error> for PutPlaybackConfigurationError {
fn from(err: io::Error) -> PutPlaybackConfigurationError {
PutPlaybackConfigurationError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for PutPlaybackConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for PutPlaybackConfigurationError {
fn description(&self) -> &str {
match *self {
PutPlaybackConfigurationError::Validation(ref cause) => cause,
PutPlaybackConfigurationError::Credentials(ref err) => err.description(),
PutPlaybackConfigurationError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
PutPlaybackConfigurationError::ParseError(ref cause) => cause,
PutPlaybackConfigurationError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum TagResourceError {
BadRequest(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl TagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> TagResourceError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"BadRequestException" => {
return TagResourceError::BadRequest(String::from(error_message));
}
"ValidationException" => {
return TagResourceError::Validation(error_message.to_string());
}
_ => {}
}
}
return TagResourceError::Unknown(res);
}
}
impl From<serde_json::error::Error> for TagResourceError {
fn from(err: serde_json::error::Error) -> TagResourceError {
TagResourceError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for TagResourceError {
fn from(err: CredentialsError) -> TagResourceError {
TagResourceError::Credentials(err)
}
}
impl From<HttpDispatchError> for TagResourceError {
fn from(err: HttpDispatchError) -> TagResourceError {
TagResourceError::HttpDispatch(err)
}
}
impl From<io::Error> for TagResourceError {
fn from(err: io::Error) -> TagResourceError {
TagResourceError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for TagResourceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for TagResourceError {
fn description(&self) -> &str {
match *self {
TagResourceError::BadRequest(ref cause) => cause,
TagResourceError::Validation(ref cause) => cause,
TagResourceError::Credentials(ref err) => err.description(),
TagResourceError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
TagResourceError::ParseError(ref cause) => cause,
TagResourceError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UntagResourceError {
BadRequest(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UntagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> UntagResourceError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"BadRequestException" => {
return UntagResourceError::BadRequest(String::from(error_message));
}
"ValidationException" => {
return UntagResourceError::Validation(error_message.to_string());
}
_ => {}
}
}
return UntagResourceError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UntagResourceError {
fn from(err: serde_json::error::Error) -> UntagResourceError {
UntagResourceError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UntagResourceError {
fn from(err: CredentialsError) -> UntagResourceError {
UntagResourceError::Credentials(err)
}
}
impl From<HttpDispatchError> for UntagResourceError {
fn from(err: HttpDispatchError) -> UntagResourceError {
UntagResourceError::HttpDispatch(err)
}
}
impl From<io::Error> for UntagResourceError {
fn from(err: io::Error) -> UntagResourceError {
UntagResourceError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UntagResourceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UntagResourceError {
fn description(&self) -> &str {
match *self {
UntagResourceError::BadRequest(ref cause) => cause,
UntagResourceError::Validation(ref cause) => cause,
UntagResourceError::Credentials(ref err) => err.description(),
UntagResourceError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
UntagResourceError::ParseError(ref cause) => cause,
UntagResourceError::Unknown(_) => "unknown error",
}
}
}
pub trait MediaTailor {
fn delete_playback_configuration(
&self,
input: DeletePlaybackConfigurationRequest,
) -> RusotoFuture<DeletePlaybackConfigurationResponse, DeletePlaybackConfigurationError>;
fn get_playback_configuration(
&self,
input: GetPlaybackConfigurationRequest,
) -> RusotoFuture<GetPlaybackConfigurationResponse, GetPlaybackConfigurationError>;
fn list_playback_configurations(
&self,
input: ListPlaybackConfigurationsRequest,
) -> RusotoFuture<ListPlaybackConfigurationsResponse, ListPlaybackConfigurationsError>;
fn list_tags_for_resource(
&self,
input: ListTagsForResourceRequest,
) -> RusotoFuture<ListTagsForResourceResponse, ListTagsForResourceError>;
fn put_playback_configuration(
&self,
input: PutPlaybackConfigurationRequest,
) -> RusotoFuture<PutPlaybackConfigurationResponse, PutPlaybackConfigurationError>;
fn tag_resource(&self, input: TagResourceRequest) -> RusotoFuture<(), TagResourceError>;
fn untag_resource(&self, input: UntagResourceRequest) -> RusotoFuture<(), UntagResourceError>;
}
#[derive(Clone)]
pub struct MediaTailorClient {
client: Client,
region: region::Region,
}
impl MediaTailorClient {
pub fn new(region: region::Region) -> MediaTailorClient {
MediaTailorClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> MediaTailorClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
MediaTailorClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl MediaTailor for MediaTailorClient {
fn delete_playback_configuration(
&self,
input: DeletePlaybackConfigurationRequest,
) -> RusotoFuture<DeletePlaybackConfigurationResponse, DeletePlaybackConfigurationError> {
let request_uri = format!("/playbackConfiguration/{name}", name = input.name);
let mut request = SignedRequest::new("DELETE", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 204 {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<DeletePlaybackConfigurationResponse>(&body)
.unwrap();
result
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DeletePlaybackConfigurationError::from_response(response))
}))
}
})
}
fn get_playback_configuration(
&self,
input: GetPlaybackConfigurationRequest,
) -> RusotoFuture<GetPlaybackConfigurationResponse, GetPlaybackConfigurationError> {
let request_uri = format!("/playbackConfiguration/{name}", name = input.name);
let mut request = SignedRequest::new("GET", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<GetPlaybackConfigurationResponse>(&body).unwrap();
result
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(GetPlaybackConfigurationError::from_response(response))
}))
}
})
}
fn list_playback_configurations(
&self,
input: ListPlaybackConfigurationsRequest,
) -> RusotoFuture<ListPlaybackConfigurationsResponse, ListPlaybackConfigurationsError> {
let request_uri = "/playbackConfigurations";
let mut request = SignedRequest::new("GET", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
let mut params = Params::new();
if let Some(ref x) = input.max_results {
params.put("MaxResults", x);
}
if let Some(ref x) = input.next_token {
params.put("NextToken", x);
}
request.set_params(params);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<ListPlaybackConfigurationsResponse>(&body)
.unwrap();
result
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(ListPlaybackConfigurationsError::from_response(response))
}))
}
})
}
fn list_tags_for_resource(
&self,
input: ListTagsForResourceRequest,
) -> RusotoFuture<ListTagsForResourceResponse, ListTagsForResourceError> {
let request_uri = format!("/tags/{resource_arn}", resource_arn = input.resource_arn);
let mut request = SignedRequest::new("GET", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<ListTagsForResourceResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(ListTagsForResourceError::from_response(response))
}),
)
}
})
}
fn put_playback_configuration(
&self,
input: PutPlaybackConfigurationRequest,
) -> RusotoFuture<PutPlaybackConfigurationResponse, PutPlaybackConfigurationError> {
let request_uri = "/playbackConfiguration";
let mut request = SignedRequest::new("PUT", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<PutPlaybackConfigurationResponse>(&body).unwrap();
result
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(PutPlaybackConfigurationError::from_response(response))
}))
}
})
}
fn tag_resource(&self, input: TagResourceRequest) -> RusotoFuture<(), TagResourceError> {
let request_uri = format!("/tags/{resource_arn}", resource_arn = input.resource_arn);
let mut request = SignedRequest::new("POST", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 204 {
Box::new(response.buffer().from_err().map(|response| {
let result = ::std::mem::drop(response);
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(TagResourceError::from_response(response))),
)
}
})
}
fn untag_resource(&self, input: UntagResourceRequest) -> RusotoFuture<(), UntagResourceError> {
let request_uri = format!("/tags/{resource_arn}", resource_arn = input.resource_arn);
let mut request = SignedRequest::new("DELETE", "mediatailor", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("api.mediatailor".to_string());
let mut params = Params::new();
for item in input.tag_keys.iter() {
params.put("tagKeys", item);
}
request.set_params(params);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 204 {
Box::new(response.buffer().from_err().map(|response| {
let result = ::std::mem::drop(response);
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UntagResourceError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}