Module: Twitter::API::Timelines

Included in:
Client
Defined in:
lib/twitter/api/timelines.rb

Overview

Note:

Inspired from twitter-4.5.0/spec/twitter/api/timelines_spec.rb

Instance Method Summary collapse

Instance Method Details

#last_tweet(screen_name) ⇒ Tweet

Get the last tweet given a twitter screen name (the last status)

Examples:

Twitter::Client.new.last_tweet('DolarBlue')
#=> #<Twitter::Tweet:0x011.. @id="308609..., @text="Dolar Paralelo: $7,84.....

Parameters:

  • screen_name (String)

    the twitter user slug

Returns:

  • (Tweet)

    the Tweet object



38
39
40
41
# File 'lib/twitter/api/timelines.rb', line 38

def last_tweet(screen_name)
  tweets = user_timeline(screen_name, count: 1)
  tweets.first
end

#user_timeline(screen_name, opts) ⇒ Array<Tweet>

Get some user timeline by screen name (last statuses)

Examples:

Twitter::Client.new.user_timeline('DolarBlue', count: 1)
#=> [#<Twitter::Tweet:0x011.. @id="308609..., @text="Dolar Paralelo: $7,84.....

Parameters:

  • screen_name (String)

    the twitter user slug

  • opts (Hash)

    the options to retrieve the statuses

Options Hash (opts):

  • :count (Integer)

    The number of statuses to retrieve

Returns:

  • (Array<Tweet>)

    the tweets collection array



20
21
22
23
24
25
26
27
# File 'lib/twitter/api/timelines.rb', line 20

def user_timeline(screen_name, opts)
  # Sanitize arguments
  count = opts[:count] || 1
  screen_name = screen_name.to_s
  # Work out
  results = get_user_timeline_results(screen_name, count)
  Twitter::Tweet.build_tweets(results)
end