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::signature::SignedRequest;
use serde_json;
use serde_json::from_slice;
use serde_json::Value as SerdeJsonValue;
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateVocabularyRequest {
#[serde(rename = "LanguageCode")]
pub language_code: String,
#[serde(rename = "Phrases")]
pub phrases: Vec<String>,
#[serde(rename = "VocabularyName")]
pub vocabulary_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateVocabularyResponse {
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LastModifiedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified_time: Option<f64>,
#[serde(rename = "VocabularyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_name: Option<String>,
#[serde(rename = "VocabularyState")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_state: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteTranscriptionJobRequest {
#[serde(rename = "TranscriptionJobName")]
pub transcription_job_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteVocabularyRequest {
#[serde(rename = "VocabularyName")]
pub vocabulary_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetTranscriptionJobRequest {
#[serde(rename = "TranscriptionJobName")]
pub transcription_job_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetTranscriptionJobResponse {
#[serde(rename = "TranscriptionJob")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job: Option<TranscriptionJob>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetVocabularyRequest {
#[serde(rename = "VocabularyName")]
pub vocabulary_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetVocabularyResponse {
#[serde(rename = "DownloadUri")]
#[serde(skip_serializing_if = "Option::is_none")]
pub download_uri: Option<String>,
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LastModifiedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified_time: Option<f64>,
#[serde(rename = "VocabularyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_name: Option<String>,
#[serde(rename = "VocabularyState")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_state: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListTranscriptionJobsRequest {
#[serde(rename = "JobNameContains")]
#[serde(skip_serializing_if = "Option::is_none")]
pub job_name_contains: Option<String>,
#[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>,
#[serde(rename = "Status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListTranscriptionJobsResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "Status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(rename = "TranscriptionJobSummaries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job_summaries: Option<Vec<TranscriptionJobSummary>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListVocabulariesRequest {
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NameContains")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name_contains: Option<String>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "StateEquals")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state_equals: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListVocabulariesResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "Status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(rename = "Vocabularies")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabularies: Option<Vec<VocabularyInfo>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Media {
#[serde(rename = "MediaFileUri")]
#[serde(skip_serializing_if = "Option::is_none")]
pub media_file_uri: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Settings {
#[serde(rename = "ChannelIdentification")]
#[serde(skip_serializing_if = "Option::is_none")]
pub channel_identification: Option<bool>,
#[serde(rename = "MaxSpeakerLabels")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_speaker_labels: Option<i64>,
#[serde(rename = "ShowSpeakerLabels")]
#[serde(skip_serializing_if = "Option::is_none")]
pub show_speaker_labels: Option<bool>,
#[serde(rename = "VocabularyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_name: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct StartTranscriptionJobRequest {
#[serde(rename = "LanguageCode")]
pub language_code: String,
#[serde(rename = "Media")]
pub media: Media,
#[serde(rename = "MediaFormat")]
pub media_format: String,
#[serde(rename = "MediaSampleRateHertz")]
#[serde(skip_serializing_if = "Option::is_none")]
pub media_sample_rate_hertz: Option<i64>,
#[serde(rename = "OutputBucketName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub output_bucket_name: Option<String>,
#[serde(rename = "Settings")]
#[serde(skip_serializing_if = "Option::is_none")]
pub settings: Option<Settings>,
#[serde(rename = "TranscriptionJobName")]
pub transcription_job_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct StartTranscriptionJobResponse {
#[serde(rename = "TranscriptionJob")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job: Option<TranscriptionJob>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Transcript {
#[serde(rename = "TranscriptFileUri")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcript_file_uri: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct TranscriptionJob {
#[serde(rename = "CompletionTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_time: Option<f64>,
#[serde(rename = "CreationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time: Option<f64>,
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "Media")]
#[serde(skip_serializing_if = "Option::is_none")]
pub media: Option<Media>,
#[serde(rename = "MediaFormat")]
#[serde(skip_serializing_if = "Option::is_none")]
pub media_format: Option<String>,
#[serde(rename = "MediaSampleRateHertz")]
#[serde(skip_serializing_if = "Option::is_none")]
pub media_sample_rate_hertz: Option<i64>,
#[serde(rename = "Settings")]
#[serde(skip_serializing_if = "Option::is_none")]
pub settings: Option<Settings>,
#[serde(rename = "Transcript")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcript: Option<Transcript>,
#[serde(rename = "TranscriptionJobName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job_name: Option<String>,
#[serde(rename = "TranscriptionJobStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job_status: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct TranscriptionJobSummary {
#[serde(rename = "CompletionTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_time: Option<f64>,
#[serde(rename = "CreationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time: Option<f64>,
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "OutputLocationType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub output_location_type: Option<String>,
#[serde(rename = "TranscriptionJobName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job_name: Option<String>,
#[serde(rename = "TranscriptionJobStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transcription_job_status: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UpdateVocabularyRequest {
#[serde(rename = "LanguageCode")]
pub language_code: String,
#[serde(rename = "Phrases")]
pub phrases: Vec<String>,
#[serde(rename = "VocabularyName")]
pub vocabulary_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateVocabularyResponse {
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LastModifiedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified_time: Option<f64>,
#[serde(rename = "VocabularyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_name: Option<String>,
#[serde(rename = "VocabularyState")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_state: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct VocabularyInfo {
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LastModifiedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified_time: Option<f64>,
#[serde(rename = "VocabularyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_name: Option<String>,
#[serde(rename = "VocabularyState")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vocabulary_state: Option<String>,
}
#[derive(Debug, PartialEq)]
pub enum CreateVocabularyError {
BadRequest(String),
Conflict(String),
InternalFailure(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateVocabularyError {
pub fn from_response(res: BufferedHttpResponse) -> CreateVocabularyError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return CreateVocabularyError::BadRequest(String::from(error_message));
}
"ConflictException" => {
return CreateVocabularyError::Conflict(String::from(error_message));
}
"InternalFailureException" => {
return CreateVocabularyError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return CreateVocabularyError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return CreateVocabularyError::Validation(error_message.to_string());
}
_ => {}
}
}
return CreateVocabularyError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateVocabularyError {
fn from(err: serde_json::error::Error) -> CreateVocabularyError {
CreateVocabularyError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateVocabularyError {
fn from(err: CredentialsError) -> CreateVocabularyError {
CreateVocabularyError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateVocabularyError {
fn from(err: HttpDispatchError) -> CreateVocabularyError {
CreateVocabularyError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateVocabularyError {
fn from(err: io::Error) -> CreateVocabularyError {
CreateVocabularyError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateVocabularyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateVocabularyError {
fn description(&self) -> &str {
match *self {
CreateVocabularyError::BadRequest(ref cause) => cause,
CreateVocabularyError::Conflict(ref cause) => cause,
CreateVocabularyError::InternalFailure(ref cause) => cause,
CreateVocabularyError::LimitExceeded(ref cause) => cause,
CreateVocabularyError::Validation(ref cause) => cause,
CreateVocabularyError::Credentials(ref err) => err.description(),
CreateVocabularyError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
CreateVocabularyError::ParseError(ref cause) => cause,
CreateVocabularyError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteTranscriptionJobError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteTranscriptionJobError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteTranscriptionJobError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return DeleteTranscriptionJobError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return DeleteTranscriptionJobError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return DeleteTranscriptionJobError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return DeleteTranscriptionJobError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteTranscriptionJobError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteTranscriptionJobError {
fn from(err: serde_json::error::Error) -> DeleteTranscriptionJobError {
DeleteTranscriptionJobError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteTranscriptionJobError {
fn from(err: CredentialsError) -> DeleteTranscriptionJobError {
DeleteTranscriptionJobError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteTranscriptionJobError {
fn from(err: HttpDispatchError) -> DeleteTranscriptionJobError {
DeleteTranscriptionJobError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteTranscriptionJobError {
fn from(err: io::Error) -> DeleteTranscriptionJobError {
DeleteTranscriptionJobError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteTranscriptionJobError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteTranscriptionJobError {
fn description(&self) -> &str {
match *self {
DeleteTranscriptionJobError::BadRequest(ref cause) => cause,
DeleteTranscriptionJobError::InternalFailure(ref cause) => cause,
DeleteTranscriptionJobError::LimitExceeded(ref cause) => cause,
DeleteTranscriptionJobError::Validation(ref cause) => cause,
DeleteTranscriptionJobError::Credentials(ref err) => err.description(),
DeleteTranscriptionJobError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DeleteTranscriptionJobError::ParseError(ref cause) => cause,
DeleteTranscriptionJobError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteVocabularyError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
NotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteVocabularyError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteVocabularyError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return DeleteVocabularyError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return DeleteVocabularyError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return DeleteVocabularyError::LimitExceeded(String::from(error_message));
}
"NotFoundException" => {
return DeleteVocabularyError::NotFound(String::from(error_message));
}
"ValidationException" => {
return DeleteVocabularyError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteVocabularyError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteVocabularyError {
fn from(err: serde_json::error::Error) -> DeleteVocabularyError {
DeleteVocabularyError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteVocabularyError {
fn from(err: CredentialsError) -> DeleteVocabularyError {
DeleteVocabularyError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteVocabularyError {
fn from(err: HttpDispatchError) -> DeleteVocabularyError {
DeleteVocabularyError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteVocabularyError {
fn from(err: io::Error) -> DeleteVocabularyError {
DeleteVocabularyError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteVocabularyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteVocabularyError {
fn description(&self) -> &str {
match *self {
DeleteVocabularyError::BadRequest(ref cause) => cause,
DeleteVocabularyError::InternalFailure(ref cause) => cause,
DeleteVocabularyError::LimitExceeded(ref cause) => cause,
DeleteVocabularyError::NotFound(ref cause) => cause,
DeleteVocabularyError::Validation(ref cause) => cause,
DeleteVocabularyError::Credentials(ref err) => err.description(),
DeleteVocabularyError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteVocabularyError::ParseError(ref cause) => cause,
DeleteVocabularyError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetTranscriptionJobError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
NotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetTranscriptionJobError {
pub fn from_response(res: BufferedHttpResponse) -> GetTranscriptionJobError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return GetTranscriptionJobError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return GetTranscriptionJobError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return GetTranscriptionJobError::LimitExceeded(String::from(error_message));
}
"NotFoundException" => {
return GetTranscriptionJobError::NotFound(String::from(error_message));
}
"ValidationException" => {
return GetTranscriptionJobError::Validation(error_message.to_string());
}
_ => {}
}
}
return GetTranscriptionJobError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetTranscriptionJobError {
fn from(err: serde_json::error::Error) -> GetTranscriptionJobError {
GetTranscriptionJobError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetTranscriptionJobError {
fn from(err: CredentialsError) -> GetTranscriptionJobError {
GetTranscriptionJobError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetTranscriptionJobError {
fn from(err: HttpDispatchError) -> GetTranscriptionJobError {
GetTranscriptionJobError::HttpDispatch(err)
}
}
impl From<io::Error> for GetTranscriptionJobError {
fn from(err: io::Error) -> GetTranscriptionJobError {
GetTranscriptionJobError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetTranscriptionJobError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetTranscriptionJobError {
fn description(&self) -> &str {
match *self {
GetTranscriptionJobError::BadRequest(ref cause) => cause,
GetTranscriptionJobError::InternalFailure(ref cause) => cause,
GetTranscriptionJobError::LimitExceeded(ref cause) => cause,
GetTranscriptionJobError::NotFound(ref cause) => cause,
GetTranscriptionJobError::Validation(ref cause) => cause,
GetTranscriptionJobError::Credentials(ref err) => err.description(),
GetTranscriptionJobError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
GetTranscriptionJobError::ParseError(ref cause) => cause,
GetTranscriptionJobError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetVocabularyError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
NotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetVocabularyError {
pub fn from_response(res: BufferedHttpResponse) -> GetVocabularyError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return GetVocabularyError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return GetVocabularyError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return GetVocabularyError::LimitExceeded(String::from(error_message));
}
"NotFoundException" => {
return GetVocabularyError::NotFound(String::from(error_message));
}
"ValidationException" => {
return GetVocabularyError::Validation(error_message.to_string());
}
_ => {}
}
}
return GetVocabularyError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetVocabularyError {
fn from(err: serde_json::error::Error) -> GetVocabularyError {
GetVocabularyError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetVocabularyError {
fn from(err: CredentialsError) -> GetVocabularyError {
GetVocabularyError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetVocabularyError {
fn from(err: HttpDispatchError) -> GetVocabularyError {
GetVocabularyError::HttpDispatch(err)
}
}
impl From<io::Error> for GetVocabularyError {
fn from(err: io::Error) -> GetVocabularyError {
GetVocabularyError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetVocabularyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetVocabularyError {
fn description(&self) -> &str {
match *self {
GetVocabularyError::BadRequest(ref cause) => cause,
GetVocabularyError::InternalFailure(ref cause) => cause,
GetVocabularyError::LimitExceeded(ref cause) => cause,
GetVocabularyError::NotFound(ref cause) => cause,
GetVocabularyError::Validation(ref cause) => cause,
GetVocabularyError::Credentials(ref err) => err.description(),
GetVocabularyError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
GetVocabularyError::ParseError(ref cause) => cause,
GetVocabularyError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListTranscriptionJobsError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListTranscriptionJobsError {
pub fn from_response(res: BufferedHttpResponse) -> ListTranscriptionJobsError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return ListTranscriptionJobsError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return ListTranscriptionJobsError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return ListTranscriptionJobsError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return ListTranscriptionJobsError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListTranscriptionJobsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListTranscriptionJobsError {
fn from(err: serde_json::error::Error) -> ListTranscriptionJobsError {
ListTranscriptionJobsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListTranscriptionJobsError {
fn from(err: CredentialsError) -> ListTranscriptionJobsError {
ListTranscriptionJobsError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListTranscriptionJobsError {
fn from(err: HttpDispatchError) -> ListTranscriptionJobsError {
ListTranscriptionJobsError::HttpDispatch(err)
}
}
impl From<io::Error> for ListTranscriptionJobsError {
fn from(err: io::Error) -> ListTranscriptionJobsError {
ListTranscriptionJobsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListTranscriptionJobsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListTranscriptionJobsError {
fn description(&self) -> &str {
match *self {
ListTranscriptionJobsError::BadRequest(ref cause) => cause,
ListTranscriptionJobsError::InternalFailure(ref cause) => cause,
ListTranscriptionJobsError::LimitExceeded(ref cause) => cause,
ListTranscriptionJobsError::Validation(ref cause) => cause,
ListTranscriptionJobsError::Credentials(ref err) => err.description(),
ListTranscriptionJobsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
ListTranscriptionJobsError::ParseError(ref cause) => cause,
ListTranscriptionJobsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListVocabulariesError {
BadRequest(String),
InternalFailure(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListVocabulariesError {
pub fn from_response(res: BufferedHttpResponse) -> ListVocabulariesError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return ListVocabulariesError::BadRequest(String::from(error_message));
}
"InternalFailureException" => {
return ListVocabulariesError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return ListVocabulariesError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return ListVocabulariesError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListVocabulariesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListVocabulariesError {
fn from(err: serde_json::error::Error) -> ListVocabulariesError {
ListVocabulariesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListVocabulariesError {
fn from(err: CredentialsError) -> ListVocabulariesError {
ListVocabulariesError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListVocabulariesError {
fn from(err: HttpDispatchError) -> ListVocabulariesError {
ListVocabulariesError::HttpDispatch(err)
}
}
impl From<io::Error> for ListVocabulariesError {
fn from(err: io::Error) -> ListVocabulariesError {
ListVocabulariesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListVocabulariesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListVocabulariesError {
fn description(&self) -> &str {
match *self {
ListVocabulariesError::BadRequest(ref cause) => cause,
ListVocabulariesError::InternalFailure(ref cause) => cause,
ListVocabulariesError::LimitExceeded(ref cause) => cause,
ListVocabulariesError::Validation(ref cause) => cause,
ListVocabulariesError::Credentials(ref err) => err.description(),
ListVocabulariesError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListVocabulariesError::ParseError(ref cause) => cause,
ListVocabulariesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum StartTranscriptionJobError {
BadRequest(String),
Conflict(String),
InternalFailure(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl StartTranscriptionJobError {
pub fn from_response(res: BufferedHttpResponse) -> StartTranscriptionJobError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return StartTranscriptionJobError::BadRequest(String::from(error_message));
}
"ConflictException" => {
return StartTranscriptionJobError::Conflict(String::from(error_message));
}
"InternalFailureException" => {
return StartTranscriptionJobError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return StartTranscriptionJobError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return StartTranscriptionJobError::Validation(error_message.to_string());
}
_ => {}
}
}
return StartTranscriptionJobError::Unknown(res);
}
}
impl From<serde_json::error::Error> for StartTranscriptionJobError {
fn from(err: serde_json::error::Error) -> StartTranscriptionJobError {
StartTranscriptionJobError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for StartTranscriptionJobError {
fn from(err: CredentialsError) -> StartTranscriptionJobError {
StartTranscriptionJobError::Credentials(err)
}
}
impl From<HttpDispatchError> for StartTranscriptionJobError {
fn from(err: HttpDispatchError) -> StartTranscriptionJobError {
StartTranscriptionJobError::HttpDispatch(err)
}
}
impl From<io::Error> for StartTranscriptionJobError {
fn from(err: io::Error) -> StartTranscriptionJobError {
StartTranscriptionJobError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for StartTranscriptionJobError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for StartTranscriptionJobError {
fn description(&self) -> &str {
match *self {
StartTranscriptionJobError::BadRequest(ref cause) => cause,
StartTranscriptionJobError::Conflict(ref cause) => cause,
StartTranscriptionJobError::InternalFailure(ref cause) => cause,
StartTranscriptionJobError::LimitExceeded(ref cause) => cause,
StartTranscriptionJobError::Validation(ref cause) => cause,
StartTranscriptionJobError::Credentials(ref err) => err.description(),
StartTranscriptionJobError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
StartTranscriptionJobError::ParseError(ref cause) => cause,
StartTranscriptionJobError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UpdateVocabularyError {
BadRequest(String),
Conflict(String),
InternalFailure(String),
LimitExceeded(String),
NotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UpdateVocabularyError {
pub fn from_response(res: BufferedHttpResponse) -> UpdateVocabularyError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"BadRequestException" => {
return UpdateVocabularyError::BadRequest(String::from(error_message));
}
"ConflictException" => {
return UpdateVocabularyError::Conflict(String::from(error_message));
}
"InternalFailureException" => {
return UpdateVocabularyError::InternalFailure(String::from(error_message));
}
"LimitExceededException" => {
return UpdateVocabularyError::LimitExceeded(String::from(error_message));
}
"NotFoundException" => {
return UpdateVocabularyError::NotFound(String::from(error_message));
}
"ValidationException" => {
return UpdateVocabularyError::Validation(error_message.to_string());
}
_ => {}
}
}
return UpdateVocabularyError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UpdateVocabularyError {
fn from(err: serde_json::error::Error) -> UpdateVocabularyError {
UpdateVocabularyError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UpdateVocabularyError {
fn from(err: CredentialsError) -> UpdateVocabularyError {
UpdateVocabularyError::Credentials(err)
}
}
impl From<HttpDispatchError> for UpdateVocabularyError {
fn from(err: HttpDispatchError) -> UpdateVocabularyError {
UpdateVocabularyError::HttpDispatch(err)
}
}
impl From<io::Error> for UpdateVocabularyError {
fn from(err: io::Error) -> UpdateVocabularyError {
UpdateVocabularyError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UpdateVocabularyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UpdateVocabularyError {
fn description(&self) -> &str {
match *self {
UpdateVocabularyError::BadRequest(ref cause) => cause,
UpdateVocabularyError::Conflict(ref cause) => cause,
UpdateVocabularyError::InternalFailure(ref cause) => cause,
UpdateVocabularyError::LimitExceeded(ref cause) => cause,
UpdateVocabularyError::NotFound(ref cause) => cause,
UpdateVocabularyError::Validation(ref cause) => cause,
UpdateVocabularyError::Credentials(ref err) => err.description(),
UpdateVocabularyError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
UpdateVocabularyError::ParseError(ref cause) => cause,
UpdateVocabularyError::Unknown(_) => "unknown error",
}
}
}
pub trait Transcribe {
fn create_vocabulary(
&self,
input: CreateVocabularyRequest,
) -> RusotoFuture<CreateVocabularyResponse, CreateVocabularyError>;
fn delete_transcription_job(
&self,
input: DeleteTranscriptionJobRequest,
) -> RusotoFuture<(), DeleteTranscriptionJobError>;
fn delete_vocabulary(
&self,
input: DeleteVocabularyRequest,
) -> RusotoFuture<(), DeleteVocabularyError>;
fn get_transcription_job(
&self,
input: GetTranscriptionJobRequest,
) -> RusotoFuture<GetTranscriptionJobResponse, GetTranscriptionJobError>;
fn get_vocabulary(
&self,
input: GetVocabularyRequest,
) -> RusotoFuture<GetVocabularyResponse, GetVocabularyError>;
fn list_transcription_jobs(
&self,
input: ListTranscriptionJobsRequest,
) -> RusotoFuture<ListTranscriptionJobsResponse, ListTranscriptionJobsError>;
fn list_vocabularies(
&self,
input: ListVocabulariesRequest,
) -> RusotoFuture<ListVocabulariesResponse, ListVocabulariesError>;
fn start_transcription_job(
&self,
input: StartTranscriptionJobRequest,
) -> RusotoFuture<StartTranscriptionJobResponse, StartTranscriptionJobError>;
fn update_vocabulary(
&self,
input: UpdateVocabularyRequest,
) -> RusotoFuture<UpdateVocabularyResponse, UpdateVocabularyError>;
}
#[derive(Clone)]
pub struct TranscribeClient {
client: Client,
region: region::Region,
}
impl TranscribeClient {
pub fn new(region: region::Region) -> TranscribeClient {
TranscribeClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> TranscribeClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
TranscribeClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl Transcribe for TranscribeClient {
fn create_vocabulary(
&self,
input: CreateVocabularyRequest,
) -> RusotoFuture<CreateVocabularyResponse, CreateVocabularyError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.CreateVocabulary");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<CreateVocabularyResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateVocabularyError::from_response(response))),
)
}
})
}
fn delete_transcription_job(
&self,
input: DeleteTranscriptionJobRequest,
) -> RusotoFuture<(), DeleteTranscriptionJobError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.DeleteTranscriptionJob");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(future::ok(::std::mem::drop(response)))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(DeleteTranscriptionJobError::from_response(response))
}),
)
}
})
}
fn delete_vocabulary(
&self,
input: DeleteVocabularyRequest,
) -> RusotoFuture<(), DeleteVocabularyError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.DeleteVocabulary");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(future::ok(::std::mem::drop(response)))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteVocabularyError::from_response(response))),
)
}
})
}
fn get_transcription_job(
&self,
input: GetTranscriptionJobRequest,
) -> RusotoFuture<GetTranscriptionJobResponse, GetTranscriptionJobError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.GetTranscriptionJob");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<GetTranscriptionJobResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(GetTranscriptionJobError::from_response(response))
}),
)
}
})
}
fn get_vocabulary(
&self,
input: GetVocabularyRequest,
) -> RusotoFuture<GetVocabularyResponse, GetVocabularyError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.GetVocabulary");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<GetVocabularyResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetVocabularyError::from_response(response))),
)
}
})
}
fn list_transcription_jobs(
&self,
input: ListTranscriptionJobsRequest,
) -> RusotoFuture<ListTranscriptionJobsResponse, ListTranscriptionJobsError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.ListTranscriptionJobs");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<ListTranscriptionJobsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(ListTranscriptionJobsError::from_response(response))
}),
)
}
})
}
fn list_vocabularies(
&self,
input: ListVocabulariesRequest,
) -> RusotoFuture<ListVocabulariesResponse, ListVocabulariesError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.ListVocabularies");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<ListVocabulariesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListVocabulariesError::from_response(response))),
)
}
})
}
fn start_transcription_job(
&self,
input: StartTranscriptionJobRequest,
) -> RusotoFuture<StartTranscriptionJobResponse, StartTranscriptionJobError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.StartTranscriptionJob");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<StartTranscriptionJobResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(StartTranscriptionJobError::from_response(response))
}),
)
}
})
}
fn update_vocabulary(
&self,
input: UpdateVocabularyRequest,
) -> RusotoFuture<UpdateVocabularyResponse, UpdateVocabularyError> {
let mut request = SignedRequest::new("POST", "transcribe", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "Transcribe.UpdateVocabulary");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<UpdateVocabularyResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UpdateVocabularyError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}