summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Blajda <blajda@hotmail.com>2018-12-09 21:51:41 +0000
committerDavid Blajda <blajda@hotmail.com>2018-12-09 21:51:41 +0000
commit89999751d8b0f6c22766af855628e0a93468cec1 (patch)
treeaaca09a259482860e169d0f0db8febf1ade39b71
parent17c6e1ecf82d5a68eccdd62f7a9d757d101759fb (diff)
clean up reqwest code
-rw-r--r--src/bin/main.rs11
-rw-r--r--src/lib.rs17
2 files changed, 24 insertions, 4 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 8a4c870..08f5abb 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -1,14 +1,23 @@
extern crate twitch_api;
extern crate tokio;
extern crate dotenv;
+extern crate futures;
+extern crate serde;
use twitch_api::TwitchApi;
use std::env;
+use futures::future::Future;
fn main() {
dotenv::dotenv().unwrap();
let mut twitch_api = TwitchApi::new(env::var("TWITCH_API").unwrap());
- let users = twitch_api.users(vec![], vec!["shroud"]);
+ let mut users = twitch_api.users(vec![], vec!["shroud"])
+ .and_then(|json| {
+ println!("{:?}", json);
+ Ok(json)
+ })
+ .map(|_| ())
+ .map_err(|_| ());
tokio::run(users);
}
diff --git a/src/lib.rs b/src/lib.rs
index 6b75ba0..c509379 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,7 +21,7 @@ impl TwitchApi {
}
}
- pub fn users(&mut self, id: Vec<&str>, login: Vec<&str>) -> Box<Future<Item=(), Error=()> + Send> {
+ pub fn users(&mut self, id: Vec<&str>, login: Vec<&str>) -> Box<Future<Item=serde_json::Value, Error=()> + Send> {
let mut headers = header::HeaderMap::new();
let auth_key = &self.client_id;
let header_value = header::HeaderValue::from_str(&auth_key).unwrap();
@@ -65,10 +65,20 @@ impl TwitchApi {
.build().unwrap();
- let mut response = client
+ let mut f = client
.get(&url)
- .send();
+ .send()
+ .map(|mut res| {
+ res.json::<serde_json::Value>()
+ })
+ .and_then(|json| {
+ println!("{:?}", json);
+ json
+ })
+ .map_err(|_| ());
+
+ /*
let f = response
.map_err(|_| ())
.and_then(|res| {
@@ -91,6 +101,7 @@ impl TwitchApi {
})
.map_err(|_| ())
});
+ */
return Box::new(f);
}