Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search for terms instead!

  • Loading branch information...
commit 79c82a53c914e22e91ef4d7530f9e21dd67738df 1 parent 952be47
@pcreux authored
Showing with 15 additions and 22 deletions.
  1. +12 −19 lib/caw.rb
  2. +3 −3 lib/caw/cli.rb
View
31 lib/caw.rb
@@ -11,10 +11,10 @@
module Caw
class Maestro
- def play(key, secret, token, token_secret)
- tweets = TwitterStream.new(key, secret, token, token_secret)
+ def play(search)
+ tweets = TwitterStream.new(search)
until 1 + 1 == 3
- tweet = tweets.pop!
+ p tweet = tweets.pop!
tweet.text = enhance_text(tweet.text)
Mimic.say(tweet)
end
@@ -33,8 +33,8 @@ def enhance_text(text)
class TwitterStream
- def initialize(key, secret, token, token_secret)
- setup_twitter(key, secret, token, token_secret)
+ def initialize(search_term)
+ @search_term = search_term
@queue = Queue.new
start!
end
@@ -46,15 +46,6 @@ def pop!
protected
- def setup_twitter(key, secret, token, token_secret)
- Twitter.configure do |config|
- config.consumer_key = key
- config.consumer_secret = secret
- config.oauth_token = token
- config.oauth_token_secret = token_secret
- end
- end
-
def start!
Thread.new do
while run?
@@ -77,7 +68,9 @@ def enqueue_new_tweets
# Return new tweets last comes first
def new_tweets
- tweets = @last_id ? client.home_timeline(:since_id => @last_id) : client.home_timeline
+ q = search.q(@search_term)
+ q = q.since_id(@last_id) if @last_id
+ tweets = q.fetch
tweets.reverse!
@last_id = tweets.last.id_str if tweets.last
@@ -85,8 +78,8 @@ def new_tweets
tweets
end
- def client
- @client ||= Twitter::Client.new
+ def search
+ @search ||= Twitter::Search.new
end
end # class TwitterStream
@@ -103,11 +96,11 @@ def self.mimic
VOICES = %w(Bruce Fred Junior Ralph)
def announce(tweet)
- say(tweet.user.name)
+ say(tweet.from_user)
end
def mimic(tweet)
- say(tweet.text, voice_for(tweet.user.name))
+ say(tweet.text, voice_for(tweet.from_user))
end
protected
View
6 lib/caw/cli.rb
@@ -1,12 +1,12 @@
module Caw
class CLI
def self.run!
- if ARGV[0] && ARGV[1] && ARGV[2] && ARGV[3]
- Maestro.new.play(ARGV[0], ARGV[1], ARGV[2], ARGV[3])
+ if ARGV[0]
+ Maestro.new.play(ARGV[0])
else
puts <<-EOF
Usage:
- caw YOUR_TWITTER_KEY YOUR_TWITTER_SECRET YOUR_OAUTH_TOKEN YOUR_OAUTH_TOKEN_SECRET
+ caw SEARCH
EOF
end
Please sign in to comment.
Something went wrong with that request. Please try again.