|
57 | 57 | //! ``` |
58 | 58 | //! |
59 | 59 | //! The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities` |
60 | | -//! supports various methods to configure the impending operation. It is made such that all required arguments have to be |
| 60 | +//! supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be |
61 | 61 | //! specified right away (i.e. `(...)`), whereas all optional ones can be [build up][builder-pattern] as desired. |
62 | 62 | //! The `do()` method performs the actual communication with the server and returns the respective result. |
63 | 63 | //! |
64 | 64 | //! # Usage (*TODO*) |
65 | 65 | //! |
66 | 66 | //! ## Instantiating the Hub |
67 | 67 | //! |
| 68 | +//! ```test_harness,no_run |
| 69 | +//! extern crate hyper; |
| 70 | +//! extern crate "yup-oauth2" as oauth2; |
| 71 | +//! extern crate "rustc-serialize" as rustc_serialize; |
| 72 | +//! extern crate youtube3; |
| 73 | +//! |
| 74 | +//! # #[test] fn egal() { |
| 75 | +//! use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; |
| 76 | +//! use std::default::Default; |
| 77 | +//! |
| 78 | +//! use youtube3::YouTube; |
| 79 | +//! |
| 80 | +//! // Get an ApplicationSecret instance by some means. It contains the `client_id` and `client_secret`, |
| 81 | +//! // among other things. |
| 82 | +//! let secret: ApplicationSecret = Default::default(); |
| 83 | +//! // Instantiate the authenticator. It will choose a suitable authentication flow for you, |
| 84 | +//! // unless you replace `None` with the desired Flow |
| 85 | +//! // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about what's going on |
| 86 | +//! // You probably want to bring in your own `TokenStorage` to persist tokens and retrieve them from storage. |
| 87 | +//! let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, |
| 88 | +//! hyper::Client::new(), |
| 89 | +//! <MemoryStorage as Default>::default(), None); |
| 90 | +//! let mut hub = YouTube::new(hyper::Client::new(), auth); |
| 91 | +//! # } |
| 92 | +//! ``` |
| 93 | +//! |
| 94 | +//! **TODO** Example calls - there should soon be a generator able to do that with proper inputs |
68 | 95 | //! ## About error handling |
69 | 96 | //! |
70 | | -//! ## About costumization |
| 97 | +//! ## About Customization/Callbacks |
71 | 98 | //! |
72 | 99 | //! [builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern |
73 | 100 | //! [google-go-api]: https://github.com/google/google-api-go-client |
|
77 | 104 | #![feature(core)] |
78 | 105 | #![allow(non_snake_case)] |
79 | 106 |
|
| 107 | +extern crate hyper; |
80 | 108 | extern crate "rustc-serialize" as rustc_serialize; |
81 | 109 | extern crate "yup-oauth2" as oauth2; |
82 | 110 |
|
83 | 111 | mod cmn; |
84 | 112 |
|
85 | 113 | use std::collections::HashMap; |
| 114 | +use std::marker::PhantomData; |
| 115 | +use std::borrow::BorrowMut; |
| 116 | +use std::cell::RefCell; |
| 117 | + |
| 118 | +pub use cmn::{Hub, Resource, Part, ResponseResult, RequestResult, NestedType}; |
| 119 | + |
| 120 | +// ######## |
| 121 | +// HUB ### |
| 122 | +// ###### |
| 123 | + |
| 124 | +/// Central instance to access all YouTube related resource activities |
| 125 | +/// |
| 126 | +/// # Examples |
| 127 | +/// |
| 128 | +/// Instantiate a new hub |
| 129 | +/// |
| 130 | +/// ```test_harness,no_run |
| 131 | +/// extern crate hyper; |
| 132 | +/// extern crate "yup-oauth2" as oauth2; |
| 133 | +/// extern crate "rustc-serialize" as rustc_serialize; |
| 134 | +/// extern crate youtube3; |
| 135 | +/// |
| 136 | +/// # #[test] fn egal() { |
| 137 | +/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; |
| 138 | +/// use std::default::Default; |
| 139 | +/// |
| 140 | +/// use youtube3::YouTube; |
| 141 | +/// |
| 142 | +/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and `client_secret`, |
| 143 | +/// // among other things. |
| 144 | +/// let secret: ApplicationSecret = Default::default(); |
| 145 | +/// // Instantiate the authenticator. It will choose a suitable authentication flow for you, |
| 146 | +/// // unless you replace `None` with the desired Flow |
| 147 | +/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about what's going on |
| 148 | +/// // You probably want to bring in your own `TokenStorage` to persist tokens and retrieve them from storage. |
| 149 | +/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, |
| 150 | +/// hyper::Client::new(), |
| 151 | +/// <MemoryStorage as Default>::default(), None); |
| 152 | +/// let mut hub = YouTube::new(hyper::Client::new(), auth); |
| 153 | +/// # } |
| 154 | +/// ``` |
| 155 | +/// |
| 156 | +pub struct YouTube<C, NC, A> { |
| 157 | + client: RefCell<C>, |
| 158 | + auth: RefCell<A>, |
| 159 | + _m: PhantomData<NC> |
| 160 | +} |
| 161 | + |
| 162 | +impl<'a, C, NC, A> Hub for YouTube<C, NC, A> {} |
| 163 | + |
| 164 | +impl<'a, C, NC, A> YouTube<C, NC, A> |
| 165 | + where NC: hyper::net::NetworkConnector, |
| 166 | + C: BorrowMut<hyper::Client<NC>> + 'a, |
| 167 | + A: oauth2::GetToken { |
| 168 | + |
| 169 | + pub fn new(client: C, authenticator: A) -> YouTube<C, NC, A> { |
| 170 | + YouTube { |
| 171 | + client: RefCell::new(client), |
| 172 | + auth: RefCell::new(authenticator), |
| 173 | + _m: PhantomData, |
| 174 | + } |
| 175 | + } |
| 176 | +} |
86 | 177 |
|
87 | | -pub use cmn::{Resource, Part, ResponseResult, RequestResult, NestedType}; |
88 | 178 |
|
89 | 179 | // ############ |
90 | 180 | // SCHEMAS ### |
|
0 commit comments