diff --git a/src/lib.rs b/src/lib.rs index 4dfe23431..6f16aa9f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,8 +51,7 @@ //! use oauth2::{RefreshFlow, AuthenticationType, RefreshResult}; //! //! # #[test] fn refresh() { -//! let mut c = hyper::Client::new(); -//! let mut f = RefreshFlow::new(&mut c); +//! let mut f = RefreshFlow::new(hyper::Client::new()); //! let new_token = match *f.refresh_token(AuthenticationType::Device, //! "my_client_id", "my_secret", //! "my_refresh_token") { diff --git a/src/refresh.rs b/src/refresh.rs index 83fc37180..07d30310e 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -6,15 +6,19 @@ use hyper::header::ContentType; use rustc_serialize::json; use url::form_urlencoded; use super::Token; +use std::borrow::BorrowMut; +use std::marker::PhantomData; /// Implements the [Outh2 Refresh Token Flow](https://developers.google.com/youtube/v3/guides/authentication#devices). /// /// Refresh an expired access token, as obtained by any other authentication flow. /// This flow is useful when your `Token` is expired and allows to obtain a new /// and valid access token. -pub struct RefreshFlow<'a, NC> where NC: 'a { - client: &'a mut hyper::Client, +pub struct RefreshFlow + where C: BorrowMut> { + client: C, result: RefreshResult, + _m: PhantomData, } @@ -28,13 +32,15 @@ pub enum RefreshResult { Success(Token), } -impl<'a, NC> RefreshFlow<'a, NC> - where NC: hyper::net::NetworkConnector { +impl RefreshFlow + where NC: hyper::net::NetworkConnector, + C: BorrowMut> { - pub fn new(client: &'a mut hyper::Client) -> RefreshFlow { + pub fn new(client: C) -> RefreshFlow { RefreshFlow { client: client, result: RefreshResult::Error(hyper::HttpError::HttpStatusError), + _m: PhantomData, } } @@ -67,7 +73,7 @@ impl<'a, NC> RefreshFlow<'a, NC> .iter().cloned()); let json_str = - match self.client.post(auth_type.as_slice()) + match self.client.borrow_mut().post(auth_type.as_slice()) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) .body(req.as_slice()) .send() {