Class: Twords::TwitterClient

Inherits:
Object
  • Object
show all
Includes:
ConfigAccessible
Defined in:
lib/twords/twitter_client.rb

Overview

Twitter REST API client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigAccessible

config

Constructor Details

#initialize {|Twitter::REST::Client| ... } ⇒ TwitterClient

Initializes a new Twords::TwitterClient object and assigns to the @client instance variable

Twords::TwitterClient.new do |twitter|
  twitter.consumer_key        = "YOUR_CONSUMER_KEY"
  twitter.consumer_secret     = "YOUR_CONSUMER_SECRET"
  twitter.access_token        = "YOUR_ACCESS_TOKEN"
  twitter.access_token_secret = "YOUR_ACCESS_SECRET"
end

for block { |twitter| … }

Yields:

  • (Twitter::REST::Client)

    yields the Twitter::REST::Client for configuration

See Also:



30
31
32
# File 'lib/twords/twitter_client.rb', line 30

def initialize(&block)
  @client = Twitter::REST::Client.new(&block)
end

Instance Attribute Details

#clientTwitter::REST::Client (readonly)

A Twitter::REST::Client that provides a direct interface to the Twitter API

Returns:

  • (Twitter::REST::Client)


14
15
16
# File 'lib/twords/twitter_client.rb', line 14

def client
  @client
end

Instance Method Details

#filter_tweets(screen_names) ⇒ Array<Twitter::Tweet>

Fetches the timelines for an array of screen names and filters them by the configured time range.

Parameters:

  • screen_names (Array<String>)

    the twitter screen names from which to pull the tweets

Returns:

  • (Array<Twitter::Tweet>)


40
41
42
43
44
45
# File 'lib/twords/twitter_client.rb', line 40

def filter_tweets(screen_names)
  full_timeline(screen_names).each_with_object([]) do |tweet, memo|
    next if tweet.created_at > up_to_time
    memo << tweet if age_of_tweet_in_days(tweet) <= range
  end
end