Skip to content

Commit

Permalink
Merge pull request egg-mode-rs#49 from QuietMisdreavus/hyper-12
Browse files Browse the repository at this point in the history
upgrade hyper/hyper-tls/native-tls/tokio
  • Loading branch information
QuietMisdreavus authored Oct 28, 2018
2 parents ef7d57c + 9fb3ecb commit b45554c
Show file tree
Hide file tree
Showing 30 changed files with 642 additions and 653 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ travis-ci = { repository = "QuietMisdreavus/twitter-rs" }
appveyor = { repository = "QuietMisdreavus/twitter-rs" }

[dependencies]
hyper = "0.11.2"
hyper-tls = "0.1.2"
native-tls = "0.1.4"
hyper = "0.12.13"
hyper-tls = "0.3.1"
native-tls = "0.2.2"
futures = "0.1.14"
tokio-core = "0.1.6"
tokio = "0.1.11"
url = "1.5.1"
rand = "0.3.16"
hmac = "0.4.2"
Expand Down
15 changes: 6 additions & 9 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;
use common::futures::Stream;

use egg_mode::user;

//IMPORTANT: see common.rs for instructions on making sure this properly authenticates with
//Twitter.
fn main() {
let mut core = reactor::Core::new().unwrap();

let config = common::Config::load(&mut core);
let handle = core.handle();
let config = common::Config::load();

println!("");
println!("Heterogeneous multi-user lookup:");
Expand All @@ -26,27 +23,27 @@ fn main() {
users.push(config.user_id.into());
users.push("SwiftOnSecurity".into());

for user in core.run(user::lookup(&users, &config.token, &handle)).unwrap().response.iter() {
for user in block_on_all(user::lookup(&users, &config.token)).unwrap().response.iter() {
print_user(user)
}

println!("");
println!("Searching based on a term: (here, it's 'rustlang')");
core.run(user::search("rustlang", &config.token, &handle).with_page_size(5).take(5).for_each(|resp| {
block_on_all(user::search("rustlang", &config.token).with_page_size(5).take(5).for_each(|resp| {
print_user(&resp);
Ok(())
})).unwrap();

println!("");
println!("Who do you follow?");
core.run(user::friends_of(config.user_id, &config.token, &handle).with_page_size(5).take(5).for_each(|resp| {
block_on_all(user::friends_of(config.user_id, &config.token).with_page_size(5).take(5).for_each(|resp| {
print_user(&resp);
Ok(())
})).unwrap();

println!("");
println!("Who follows you?");
core.run(user::followers_of(config.user_id, &config.token, &handle).with_page_size(5).take(5).for_each(|resp| {
block_on_all(user::followers_of(config.user_id, &config.token).with_page_size(5).take(5).for_each(|resp| {
print_user(&resp);
Ok(())
})).unwrap();
Expand Down
11 changes: 4 additions & 7 deletions examples/bearer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;

fn main() {
let con_key = include_str!("common/consumer_key").trim();
let con_secret = include_str!("common/consumer_secret").trim();

let con_token = egg_mode::KeyPair::new(con_key, con_secret);

let mut core = reactor::Core::new().unwrap();
let handle = core.handle();

println!("Pulling up the bearer token...");
let token = core.run(egg_mode::bearer_token(&con_token, &handle)).unwrap();
let token = block_on_all(egg_mode::bearer_token(&con_token)).unwrap();

println!("Pulling up a user timeline...");
let timeline = egg_mode::tweet::user_timeline("rustlang", false, true, &token, &handle).with_page_size(5);
let timeline = egg_mode::tweet::user_timeline("rustlang", false, true, &token).with_page_size(5);

let (_timeline, feed) = core.run(timeline.start()).unwrap();
let (_timeline, feed) = block_on_all(timeline.start()).unwrap();
for tweet in feed {
println!("");
common::print_tweet(&tweet);
Expand Down
15 changes: 7 additions & 8 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
//to prevent conflicts with examples, i'll import things here and let examples use it from here if
//they need it
pub extern crate chrono;
pub extern crate tokio_core;
pub extern crate tokio;
pub extern crate futures;

use std;
use std::io::{Write, Read};
use egg_mode;

use self::tokio_core::reactor::Core;
use self::tokio::runtime::current_thread::block_on_all;

//This is not an example that can be built with cargo! This is some helper code for the other
//examples so they can load access keys from the same place.
Expand All @@ -28,12 +28,11 @@ pub struct Config {
}

impl Config {
pub fn load(core: &mut Core) -> Self {
pub fn load() -> Self {
//IMPORTANT: make an app for yourself at apps.twitter.com and get your
//key/secret into these files; these examples won't work without them
let consumer_key = include_str!("consumer_key").trim();
let consumer_secret = include_str!("consumer_secret").trim();
let handle = core.handle();

let con_token = egg_mode::KeyPair::new(consumer_key, consumer_secret);

Expand All @@ -57,15 +56,15 @@ impl Config {
access: access_token,
};

if let Err(err) = core.run(egg_mode::verify_tokens(&token, &handle)) {
if let Err(err) = block_on_all(egg_mode::verify_tokens(&token)) {
println!("We've hit an error using your old tokens: {:?}", err);
println!("We'll have to reauthenticate before continuing.");
std::fs::remove_file("twitter_settings").unwrap();
} else {
println!("Welcome back, {}!", username);
}
} else {
let request_token = core.run(egg_mode::request_token(&con_token, "oob", &handle)).unwrap();
let request_token = block_on_all(egg_mode::request_token(&con_token, "oob")).unwrap();

println!("Go to the following URL, sign in, and give me the PIN that comes back:");
println!("{}", egg_mode::authorize_url(&request_token));
Expand All @@ -74,7 +73,7 @@ impl Config {
std::io::stdin().read_line(&mut pin).unwrap();
println!("");

let tok_result = core.run(egg_mode::access_token(con_token, &request_token, pin, &handle)).unwrap();
let tok_result = block_on_all(egg_mode::access_token(con_token, &request_token, pin)).unwrap();

token = tok_result.0;
user_id = tok_result.1;
Expand Down Expand Up @@ -107,7 +106,7 @@ impl Config {
screen_name: username,
}
} else {
Self::load(core)
Self::load()
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions examples/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ extern crate chrono;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;

fn main() {
let mut core = reactor::Core::new().unwrap();
let c = common::Config::load();

let c = common::Config::load(&mut core);
let handle = core.handle();

let convos = egg_mode::direct::conversations(&c.token, &handle);
let convos = core.run(convos.newest()).unwrap();
let convos = egg_mode::direct::conversations(&c.token);
let convos = block_on_all(convos.newest()).unwrap();

for (id, convo) in &convos.conversations {
let user = core.run(egg_mode::user::show(id, &c.token, &handle)).unwrap();
let user = block_on_all(egg_mode::user::show(id, &c.token)).unwrap();
println!("-----");
println!("Conversation with @{}:", user.screen_name);
for msg in convo {
Expand Down
15 changes: 6 additions & 9 deletions examples/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;

use egg_mode::place::PlaceType;

fn main() {
let mut core = reactor::Core::new().unwrap();
let config = common::Config::load();

let config = common::Config::load(&mut core);
let handle = core.handle();

let result = core.run(egg_mode::place::search_query("columbia")
let result = block_on_all(egg_mode::place::search_query("columbia")
.granularity(PlaceType::Admin)
.max_results(10)
.call(&config.token, &handle)).unwrap();
.call(&config.token)).unwrap();

println!("{} results for \"columbia\", administrative regions or larger:", result.results.len());

Expand All @@ -28,9 +25,9 @@ fn main() {
}
println!("");

let result = core.run(egg_mode::place::reverse_geocode(51.507222, -0.1275)
let result = block_on_all(egg_mode::place::reverse_geocode(51.507222, -0.1275)
.granularity(PlaceType::City)
.call(&config.token, &handle)).unwrap();
.call(&config.token)).unwrap();

println!("{} results for reverse-geocoding {}, {}:", result.results.len(),
51.507222, -0.1275);
Expand Down
13 changes: 5 additions & 8 deletions examples/reciprocal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;
use common::futures::Stream;

use std::collections::HashSet;
Expand All @@ -15,19 +15,16 @@ use egg_mode::user;
//IMPORTANT: see common.rs for instructions on making sure this properly authenticates with
//Twitter.
fn main() {
let mut core = reactor::Core::new().unwrap();

let config = common::Config::load(&mut core);
let handle = core.handle();
let config = common::Config::load();

println!("");
let mut friends = HashSet::new();
core.run(user::friends_ids(config.user_id, &config.token, &handle)
block_on_all(user::friends_ids(config.user_id, &config.token)
.map(|r| r.response)
.for_each(|id| { friends.insert(id); Ok(()) })).unwrap();

let mut followers = HashSet::new();
core.run(user::followers_ids(config.user_id, &config.token, &handle)
block_on_all(user::followers_ids(config.user_id, &config.token)
.map(|r| r.response)
.for_each(|id| { followers.insert(id); Ok(()) })).unwrap();

Expand All @@ -36,7 +33,7 @@ fn main() {
println!("{} accounts that you follow follow you back.", reciprocals_ct);

if reciprocals_ct > 0 {
for user in core.run(user::lookup(&reciprocals, &config.token, &handle)).unwrap() {
for user in block_on_all(user::lookup(&reciprocals, &config.token)).unwrap() {
println!("{} (@{})", user.name, user.screen_name);
}
}
Expand Down
15 changes: 6 additions & 9 deletions examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;

use egg_mode::search::{self, ResultType};

fn main() {
let mut core = reactor::Core::new().unwrap();

let config = common::Config::load(&mut core);
let handle = core.handle();
let config = common::Config::load();

//rust tweets around dallas
let search = core.run(search::search("rustlang")
.result_type(ResultType::Recent)
.count(10)
.call(&config.token, &handle)).unwrap();
let search = block_on_all(search::search("rustlang")
.result_type(ResultType::Recent)
.count(10)
.call(&config.token)).unwrap();

for tweet in &search.statuses {
common::print_tweet(tweet);
Expand Down
15 changes: 6 additions & 9 deletions examples/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ extern crate egg_mode;

mod common;

use common::tokio_core::reactor;
use common::tokio::runtime::current_thread::block_on_all;

use std::collections::{VecDeque, HashSet};
use egg_mode::tweet;

fn main() {
let mut core = reactor::Core::new().unwrap();

let c = common::Config::load(&mut core);
let handle = core.handle();
let c = common::Config::load();

//Thread Reconstruction
//
Expand Down Expand Up @@ -48,24 +45,24 @@ fn main() {
let mut thread = VecDeque::with_capacity(21);
let mut thread_ids = HashSet::new();

let start_tweet = core.run(tweet::show(start_id, &c.token, &handle)).unwrap();
let start_tweet = block_on_all(tweet::show(start_id, &c.token)).unwrap();
let thread_user = start_tweet.user.as_ref().unwrap().id;
thread_ids.insert(start_tweet.id);
thread.push_front(start_tweet.response);

for _ in 0..10 {
if let Some(id) = thread.front().and_then(|t| t.in_reply_to_status_id) {
let parent = core.run(tweet::show(id, &c.token, &handle)).unwrap();
let parent = block_on_all(tweet::show(id, &c.token)).unwrap();
thread_ids.insert(parent.id);
thread.push_front(parent.response);
} else {
break;
}
}

let replies = tweet::user_timeline(thread_user, true, false, &c.token, &handle);
let replies = tweet::user_timeline(thread_user, true, false, &c.token);

for tweet in core.run(replies.call(Some(start_id), None)).unwrap().into_iter().rev() {
for tweet in block_on_all(replies.call(Some(start_id), None)).unwrap().into_iter().rev() {
if let Some(reply_id) = tweet.in_reply_to_status_id {
if thread_ids.contains(&reply_id) {
thread_ids.insert(tweet.id);
Expand Down
Loading

0 comments on commit b45554c

Please sign in to comment.