From 3f965c8fea1f341809be97364cbaa570b986f2c4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Feb 2015 20:15:28 +0100 Subject: [PATCH] feat(device): BorrowMut for client --- src/device.rs | 22 ++++++++++++++-------- src/refresh.rs | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/device.rs b/src/device.rs index 34d3b21..26a475b 100644 --- a/src/device.rs +++ b/src/device.rs @@ -10,6 +10,8 @@ use url::form_urlencoded; use itertools::Itertools; use rustc_serialize::json; use chrono::{DateTime,UTC}; +use std::borrow::BorrowMut; +use std::marker::PhantomData; use common::{Token, AuthenticationType, Flow}; @@ -19,15 +21,17 @@ pub const GOOGLE_TOKEN_URL: &'static str = "https://accounts.google.com/o/oauth2 /// It operates in two steps: /// * obtain a code to show to the user /// * (repeatedly) poll for the user to authenticate your application -pub struct DeviceFlow { - client: hyper::Client, +pub struct DeviceFlow { + client: C, device_code: String, state: PollResult, secret: String, id: String, + + _m: PhantomData, } -impl Flow for DeviceFlow { +impl Flow for DeviceFlow { fn type_id() -> AuthenticationType { AuthenticationType::Device } @@ -99,8 +103,9 @@ impl Default for PollResult { } } -impl DeviceFlow - where NC: hyper::net::NetworkConnector { +impl DeviceFlow + where C: BorrowMut>, + NC: hyper::net::NetworkConnector { /// # Examples /// ```test_harness @@ -112,13 +117,14 @@ impl DeviceFlow /// let mut f = DeviceFlow::new(hyper::Client::new()); /// # } /// ``` - pub fn new(client: hyper::Client) -> DeviceFlow { + pub fn new(client: C) -> DeviceFlow { DeviceFlow { client: client, device_code: Default::default(), secret: Default::default(), id: Default::default(), state: Default::default(), + _m: PhantomData, } } @@ -156,7 +162,7 @@ impl DeviceFlow .collect::() .as_slice())].iter().cloned()); - match self.client.post(AuthenticationType::Device.as_slice()) + match self.client.borrow_mut().post(AuthenticationType::Device.as_slice()) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) .body(req.as_slice()) .send() { @@ -255,7 +261,7 @@ impl DeviceFlow .iter().cloned()); let json_str = - match self.client.post(GOOGLE_TOKEN_URL) + match self.client.borrow_mut().post(GOOGLE_TOKEN_URL) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) .body(req.as_slice()) .send() { diff --git a/src/refresh.rs b/src/refresh.rs index 07d3031..90ea9b6 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -14,10 +14,10 @@ use std::marker::PhantomData; /// 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 - where C: BorrowMut> { +pub struct RefreshFlow { client: C, result: RefreshResult, + _m: PhantomData, }