Skip to content

Commit

Permalink
look ma, no handles
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Oct 28, 2018
1 parent 66f00bd commit 6f9397e
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 373 deletions.
9 changes: 4 additions & 5 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

println!("");
println!("Heterogeneous multi-user lookup:");
Expand All @@ -26,27 +25,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 core.run(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| {
core.run(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| {
core.run(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| {
core.run(user::followers_of(config.user_id, &config.token).with_page_size(5).take(5).for_each(|resp| {
print_user(&resp);
Ok(())
})).unwrap();
Expand Down
5 changes: 2 additions & 3 deletions examples/bearer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ fn main() {
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 = core.run(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();
for tweet in feed {
Expand Down
7 changes: 3 additions & 4 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl Config {
//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) = core.run(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 = core.run(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 = core.run(egg_mode::access_token(con_token, &request_token, pin)).unwrap();

token = tok_result.0;
user_id = tok_result.1;
Expand Down
5 changes: 2 additions & 3 deletions examples/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

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

for (id, convo) in &convos.conversations {
let user = core.run(egg_mode::user::show(id, &c.token, &handle)).unwrap();
let user = core.run(egg_mode::user::show(id, &c.token)).unwrap();
println!("-----");
println!("Conversation with @{}:", user.screen_name);
for msg in convo {
Expand Down
5 changes: 2 additions & 3 deletions examples/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

let result = core.run(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 @@ -30,7 +29,7 @@ fn main() {

let result = core.run(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
7 changes: 3 additions & 4 deletions examples/reciprocal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

println!("");
let mut friends = HashSet::new();
core.run(user::friends_ids(config.user_id, &config.token, &handle)
core.run(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)
core.run(user::followers_ids(config.user_id, &config.token)
.map(|r| r.response)
.for_each(|id| { followers.insert(id); Ok(()) })).unwrap();

Expand All @@ -36,7 +35,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 core.run(user::lookup(&reciprocals, &config.token)).unwrap() {
println!("{} (@{})", user.name, user.screen_name);
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

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

for tweet in &search.statuses {
common::print_tweet(tweet);
Expand Down
7 changes: 3 additions & 4 deletions examples/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

//Thread Reconstruction
//
Expand Down Expand Up @@ -48,22 +47,22 @@ 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 = core.run(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 = core.run(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() {
if let Some(reply_id) = tweet.in_reply_to_status_id {
Expand Down
11 changes: 5 additions & 6 deletions examples/tweets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ fn main() {
let mut core = reactor::Core::new().unwrap();

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

println!("");
println!("Load up an individual tweet:");
let status = core.run(egg_mode::tweet::show(tweet_id, &config.token, &handle)).unwrap();
let status = core.run(egg_mode::tweet::show(tweet_id, &config.token)).unwrap();
common::print_tweet(&status);

println!("");
println!("Loading retweets of an individual tweet:");
for rt in &core.run(egg_mode::tweet::retweets_of(tweet_id, 5, &config.token, &handle)).unwrap() {
for rt in &core.run(egg_mode::tweet::retweets_of(tweet_id, 5, &config.token)).unwrap() {
if let Some(ref user) = rt.user {
println!("{} (@{})", user.name, user.screen_name);
}
}

println!("");
println!("Loading the user's home timeline:");
let home = egg_mode::tweet::home_timeline(&config.token, &handle).with_page_size(5);
let home = egg_mode::tweet::home_timeline(&config.token).with_page_size(5);
let (_home, feed) = core.run(home.start()).unwrap();
for status in feed {
common::print_tweet(&status);
Expand All @@ -39,7 +38,7 @@ fn main() {

println!("");
println!("Loading the user's mentions timeline:");
let mentions = egg_mode::tweet::mentions_timeline(&config.token, &handle).with_page_size(5);
let mentions = egg_mode::tweet::mentions_timeline(&config.token).with_page_size(5);
let (_mentions, feed) = core.run(mentions.start()).unwrap();
for status in feed {
common::print_tweet(&status);
Expand All @@ -49,7 +48,7 @@ fn main() {
println!("");
println!("Loading the user's timeline:");
let user = egg_mode::tweet::user_timeline(config.user_id, true, true,
&config.token, &handle).with_page_size(5);
&config.token).with_page_size(5);
let (_user, feed) = core.run(user.start()).unwrap();
for status in feed {
common::print_tweet(&status);
Expand Down
Loading

0 comments on commit 6f9397e

Please sign in to comment.