fix(rustup): switch to using io where possible

And adapt to hyper in the same moment
This commit is contained in:
Sebastian Thiel
2015-03-07 13:03:12 +01:00
parent 445675db7f
commit 437a60959b
4 changed files with 13 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
[package]
name = "yup-oauth2"
version = "0.2.1"
version = "0.2.2"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
@@ -20,5 +20,5 @@ rustc-serialize = "*"
[dev-dependencies]
getopts = "*"
yup-hyper-mock = "*"
yup-hyper-mock = ">= 0.1.3"
open = "*"

View File

@@ -10,6 +10,7 @@ use rustc_serialize::json;
use chrono::{DateTime,UTC};
use std::borrow::BorrowMut;
use std::marker::PhantomData;
use std::io::Read;
use common::{Token, FlowType, Flow};
@@ -192,7 +193,8 @@ impl<C, NC> DeviceFlow<C, NC>
// json::Json::from_reader(&mut res)
// .ok()
// .expect("decode must work!"))).unwrap();
let json_str = String::from_utf8(res.read_to_end().unwrap()).unwrap();
let mut json_str = String::new();
res.read_to_string(&mut json_str).ok().expect("string decode must work");
// check for error
match json::decode::<JsonError>(&json_str) {
@@ -267,7 +269,9 @@ impl<C, NC> DeviceFlow<C, NC>
return PollResult::Error(err);
}
Ok(mut res) => {
String::from_utf8(res.read_to_end().unwrap()).unwrap()
let mut json_str = String::new();
res.read_to_string(&mut json_str).ok().expect("string decode must work");
json_str
}
};

View File

@@ -1,4 +1,4 @@
#![feature(old_io, std_misc, core, hash)]
#![feature(io, old_io, std_misc, core, hash)]
//! 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
//! for [refreshing tokens](https://developers.google.com/youtube/v3/guides/authentication#devices)

View File

@@ -8,6 +8,7 @@ use url::form_urlencoded;
use super::Token;
use std::borrow::BorrowMut;
use std::marker::PhantomData;
use std::io::Read;
/// Implements the [Outh2 Refresh Token Flow](https://developers.google.com/youtube/v3/guides/authentication#devices).
///
@@ -82,7 +83,9 @@ impl<C, NC> RefreshFlow<C, NC>
return &self.result;
}
Ok(mut res) => {
String::from_utf8(res.read_to_end().unwrap()).unwrap()
let mut json_str = String::new();
res.read_to_string(&mut json_str).ok().expect("string decode must work");
json_str
}
};