Skip to content

Commit

Permalink
fix(rustup): (abf0548b5 2015-04-15) (built 2015-04-15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 17, 2015
1 parent 0222a19 commit 84454d1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "yup-oauth2"
version = "0.3.3"
version = "0.3.4"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
10 changes: 5 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub enum TokenType {
Bearer,
}

impl Str for TokenType {
fn as_slice(&self) -> &'static str {
impl AsRef<str> for TokenType {
fn as_ref(&self) -> &'static str {
match *self {
TokenType::Bearer => "Bearer"
}
Expand Down Expand Up @@ -50,7 +50,7 @@ impl hyper::header::Scheme for Scheme {
}

fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self.token_type.as_slice(), self.access_token)
write!(f, "{} {}", self.token_type.as_ref(), self.access_token)
}
}

Expand Down Expand Up @@ -134,9 +134,9 @@ pub enum FlowType {
Device,
}

impl Str for FlowType {
impl AsRef<str> for FlowType {
/// Converts itself into a URL string
fn as_slice(&self) -> &'static str {
fn as_ref(&self) -> &'static str {
match *self {
FlowType::Device => "https://accounts.google.com/o/oauth2/device/code",
}
Expand Down
16 changes: 8 additions & 8 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<C> DeviceFlow<C>
/// See test-cases in source code for a more complete example.
pub fn request_code<'b, T, I>(&mut self, client_id: &str, client_secret: &str, scopes: I)
-> RequestResult
where T: Str,
where T: AsRef<str>,
I: IntoIterator<Item=&'b T> {
if self.device_code.len() > 0 {
panic!("Must not be called after we have obtained a token and have no error");
Expand All @@ -152,14 +152,14 @@ impl<C> DeviceFlow<C>
let req = form_urlencoded::serialize(
[("client_id", client_id),
("scope", scopes.into_iter()
.map(|s| s.as_slice())
.map(|s| s.as_ref())
.intersperse(" ")
.collect::<String>()
.as_slice())].iter().cloned());
.as_ref())].iter().cloned());

match self.client.borrow_mut().post(FlowType::Device.as_slice())
match self.client.borrow_mut().post(FlowType::Device.as_ref())
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
.body(req.as_slice())
.body(&*req)
.send() {
Err(err) => {
return RequestResult::Error(Rc::new(err));
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<C> DeviceFlow<C>

// We should be ready for a new request
let req = form_urlencoded::serialize(
[("client_id", self.id.as_slice()),
[("client_id", &self.id[..]),
("client_secret", &self.secret),
("code", &self.device_code),
("grant_type", "http://oauth.net/grant_type/device/1.0")]
Expand All @@ -259,7 +259,7 @@ impl<C> DeviceFlow<C>
let json_str =
match self.client.borrow_mut().post(GOOGLE_TOKEN_URL)
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
.body(req.as_slice())
.body(&*req)
.send() {
Err(err) => {
return PollResult::Error(Rc::new(err));
Expand All @@ -280,7 +280,7 @@ impl<C> DeviceFlow<C>
Err(_) => {}, // ignore, move on, it's not an error
Ok(res) => {
pi.server_message = res.error;
self.state = match pi.server_message.as_slice() {
self.state = match pi.server_message.as_ref() {
"access_denied" => PollResult::AccessDenied,
"authorization_pending" => PollResult::AuthorizationPending(pi),
_ => panic!("server message '{}' not understood", pi.server_message),
Expand Down
8 changes: 4 additions & 4 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter::IntoIterator;
use std::borrow::BorrowMut;
use std::collections::HashMap;
use std::hash::{SipHasher, Hash, Hasher};
use std::old_io::timer::sleep;
use std::thread::sleep;
use std::cmp::min;

use common::{Token, FlowType, ApplicationSecret};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct Authenticator<D, S, C> {
/// if no user is involved.
pub trait GetToken {
fn token<'b, I, T>(&mut self, scopes: I) -> Option<Token>
where T: Str + Ord,
where T: AsRef<str> + Ord,
I: IntoIterator<Item=&'b T>;

fn api_key(&mut self) -> Option<String>;
Expand Down Expand Up @@ -186,11 +186,11 @@ impl<D, S, C> GetToken for Authenticator<D, S, C>
/// In any failure case, the returned token will be None, otherwise it is guaranteed to be
/// valid for the given scopes.
fn token<'b, I, T>(&mut self, scopes: I) -> Option<Token>
where T: Str + Ord,
where T: AsRef<str> + Ord,
I: IntoIterator<Item=&'b T> {
let (scope_key, scopes) = {
let mut sv: Vec<&str> = scopes.into_iter()
.map(|s|s.as_slice())
.map(|s|s.as_ref())
.collect::<Vec<&str>>();
sv.sort();
let s = sv.connect(" ");
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(old_io, std_misc, core)]
#![feature(std_misc, thread_sleep)]
#![allow(deprecated)]
//! This library can be used to acquire oauth2.0 authentication for services.
//! At the time of writing, only one way of doing so is implemented, the [device flow](https://developers.google.com/youtube/v3/guides/authentication#devices), along with a flow
Expand Down Expand Up @@ -60,7 +60,6 @@
//! };
//! # }
//! ```
extern crate chrono;

#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ impl<C> RefreshFlow<C>
.iter().cloned());

let json_str =
match self.client.borrow_mut().post(flow_type.as_slice())
match self.client.borrow_mut().post(flow_type.as_ref())
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
.body(req.as_slice())
.body(&*req)
.send() {
Err(err) => {
self.result = RefreshResult::Error(err);
Expand Down

0 comments on commit 84454d1

Please sign in to comment.