#![feature(core)] //! //! # Usage //! //! ```test_harness //! extern crate "youtube3-dev" as youtube3; //! extern crate hyper; //! //! # #[test] //! # fn test() { //! # // TODO - generate ! //! # } //! ``` use std::marker::PhantomData; use std::cell::RefCell; use std::borrow::BorrowMut; use std::default::Default; use hyper; use oauth2; mod common; pub mod videos; /// Central instance to access all youtube related services pub struct YouTube { client: RefCell, auth: RefCell, _m: PhantomData } impl<'a, C, NC, A> YouTube where NC: hyper::net::NetworkConnector, C: BorrowMut> + 'a, A: oauth2::GetToken { pub fn new(client: C, authenticator: A) -> YouTube { YouTube { client: RefCell::new(client), auth: RefCell::new(authenticator), _m: PhantomData, } } pub fn videos(&'a self) -> videos::Service<'a, C, NC, A> { videos::Service::new(&self) } pub fn channel_sections(&'a self) -> ChannelSectionMethodsBuilder<'a, C, NC, A> { ChannelSectionMethodsBuilder { hub: &self } } } pub fn new(client: C, authenticator: A) -> YouTube where NC: hyper::net::NetworkConnector, C: BorrowMut>, A: oauth2::GetToken { YouTube::new(client, authenticator) } #[cfg(test)] mod tests { use super::*; use hyper; use oauth2; use std::default::Default; #[test] fn instantiate() { let secret = ::default(); let auth = oauth2::Authenticator::new( &secret, oauth2::DefaultAuthenticatorDelegate, hyper::Client::new(), ::default(), None); let yt = YouTube::new(hyper::Client::new(), auth); let v = yt.videos().insert("snippet", &Default::default()); } #[test] fn helper_test() { use std::default::Default; use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; let secret: ApplicationSecret = Default::default(); let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, hyper::Client::new(), ::default(), None); let mut hub = YouTube::new(hyper::Client::new(), auth); let result = hub.channel_sections().insert() .delegate(&mut DefaultDelegate) .doit(); } } pub struct ChannelSectionMethodsBuilder<'a, C, NC, A> where NC: 'a, C: 'a, A: 'a, { hub: &'a YouTube, } impl<'a, C, NC, A> ChannelSectionMethodsBuilder<'a, C, NC, A> { /// Create a builder to help you perform the following task: /// /// Adds a channelSection for the authenticated user's channel. pub fn insert(&self) -> ChannelSectionInsertMethodBuilder<'a, C, NC, A> { ChannelSectionInsertMethodBuilder { hub: self.hub, _delegate: Default::default(), _part: None, } } } pub struct ChannelSectionInsertMethodBuilder<'a, C, NC, A> where NC: 'a, C: 'a, A: 'a, { hub: &'a YouTube, _delegate: Option<&'a mut Delegate>, _part: Option, } impl<'a, C, NC, A> ChannelSectionInsertMethodBuilder<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut> + 'a, A: oauth2::GetToken { /// Perform the operation you have build so far. /// TODO: Build actual call pub fn doit(mut self) -> () { let mut params: Vec<(&str, String)> = Vec::with_capacity(1); if self._part.is_none() { self._part = Some("parts from request value".to_string()); } if self._delegate.is_some() { self._delegate.as_mut().unwrap().connection_error(hyper::HttpError::HttpStatusError); } } pub fn delegate(mut self, new_value: &'a mut Delegate) -> ChannelSectionInsertMethodBuilder<'a, C, NC, A> { self._delegate = Some(new_value); self } } pub trait Delegate { /// Called whenever there is an HttpError, usually if there are network problems. /// /// Return retry information. fn connection_error(&mut self, hyper::HttpError) -> oauth2::Retry { oauth2::Retry::Abort } } #[derive(Default)] pub struct DefaultDelegate; impl Delegate for DefaultDelegate {}