Struct egg_mode::tweet::Timeline [] [src]

pub struct Timeline<'a> {
    pub count: i32,
    pub max_id: Option<u64>,
    pub min_id: Option<u64>,
    // some fields omitted
}

Helper struct to navigate collections of tweets by requesting tweets older or newer than certain IDs.

Using a Timeline to navigate collections of tweets (like a user's timeline, their list of likes, etc) allows you to efficiently cursor through a collection and only load in tweets you need.

To begin, call a method that returns a Timeline, optionally set the page size, and call start to load the first page of results:

let mut timeline = egg_mode::tweet::home_timeline(&token, &handle)
                                   .with_page_size(10);

for tweet in &core.run(timeline.start()).unwrap() {
    println!("<@{}> {}", tweet.user.as_ref().unwrap().screen_name, tweet.text);
}

If you need to load the next set of tweets, call older, which will automatically update the tweet IDs it tracks:

for tweet in &core.run(timeline.older(None)).unwrap() {
    println!("<@{}> {}", tweet.user.as_ref().unwrap().screen_name, tweet.text);
}

...and similarly for newer, which operates in a similar fashion.

If you want to start afresh and reload the newest set of tweets again, you can call start again, which will clear the tracked tweet IDs before loading the newest set of tweets. However, if you've been storing these tweets as you go, and already know the newest tweet ID you have on hand, you can load only those tweets you need like this:

let mut timeline = egg_mode::tweet::home_timeline(&token, &handle)
                                   .with_page_size(10);

core.run(timeline.start()).unwrap();

//keep the max_id for later
let reload_id = timeline.max_id.unwrap();

//simulate scrolling down a little bit
core.run(timeline.older(None)).unwrap();
core.run(timeline.older(None)).unwrap();

//reload the timeline with only what's new
timeline.reset();
core.run(timeline.older(Some(reload_id))).unwrap();

Here, the argument to older means "older than what I just returned, but newer than the given ID". Since we cleared the tracked IDs with reset, that turns into "the newest tweets available that were posted after the given ID". The earlier invocations of older with None do not place a bound on the tweets it loads. newer operates in a similar fashion with its argument, saying "newer than what I just returned, but not newer than this given ID". When called like this, it's possible for these methods to return nothing, which will also clear the Timeline's tracked IDs.

If you want to manually pull tweets between certain IDs, the baseline call function can do that for you. Keep in mind, though, that call doesn't update the min_id or max_id fields, so you'll have to set those yourself if you want to follow up with older or newer.

Fields

The maximum number of tweets to return in a single call. Twitter doesn't guarantee returning exactly this number, as suspended or deleted content is removed after retrieving the initial collection of tweets.

The largest/most recent tweet ID returned in the last call to start, older, or newer.

The smallest/oldest tweet ID returned in the last call to start, older, or newer.

Methods

impl<'a> Timeline<'a>
[src]

[src]

Clear the saved IDs on this timeline.

[src]

Clear the saved IDs on this timeline, and return the most recent set of tweets.

[src]

Return the set of tweets older than the last set pulled, optionally placing a minimum tweet ID to bound with.

[src]

Return the set of tweets newer than the last set pulled, optionall placing a maximum tweet ID to bound with.

[src]

Return the set of tweets between the IDs given.

Note that the range is not fully inclusive; the tweet ID given by since_id will not be returned, but the tweet ID in max_id will be returned.

If the range of tweets given by the IDs would return more than self.count, the newest set of tweets will be returned.

[src]

Helper builder function to set the page size.