use super::BoxClient;
use super::Result;
use serde_json;
use Error;
use Kind;
pub use self::types::{CheckOptions, CheckOptionsBuilder, Video, VideoAnalysis, Range, Item,
Nudebox, Facebox, Tagbox, Status};
use super::utils::{delete_with_response, post_form_vars, get_json};
use self::types::{VideoResponse, VideoAnalysisResponse};
pub struct Videobox {
url: String,
}
impl Videobox {
pub fn new(url: &str) -> Videobox {
Videobox {
url: url.to_owned()
}
}
pub fn check_url(&self, video_url: &str, options: CheckOptions) -> Result<Video> {
let url = format!("{}/videobox/check", self.url());
let mut params: Vec<(String,String)> = Vec::new();
params.push(("url".to_owned(), video_url.to_owned()));
for option in options.into_iter() {
params.push(option.clone());
}
let s = post_form_vars(&url, ¶ms)?;
let video_result:VideoResponse = serde_json::from_str(&s)?;
video_result.into()
}
pub fn delete(&self, id: &str) -> Result<()> {
let url = format!("{}/videobox/results/{}", self.url(), id);
let _ = delete_with_response(&url)?;
Ok(())
}
pub fn results(&self, id: &str) -> Result<VideoAnalysis> {
let url = format!("{}/videobox/results/{}", self.url(), id);
let s = get_json(&url)?;
let analysis: VideoAnalysisResponse = serde_json::from_str(&s)?;
analysis.into()
}
pub fn status(&self, id: &str) -> Result<Video> {
let url = format!("{}/videobox/status/{}", self.url(), id);
let s = get_json(&url)?;
let video: VideoResponse = serde_json::from_str(&s)?;
video.into()
}
}
impl BoxClient for Videobox {
fn url(&self) -> &str {
&self.url
}
}
mod types;
#[cfg(test)]
mod tests;