Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Created June 7, 2012 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blairanderson/2886340 to your computer and use it in GitHub Desktop.
Save blairanderson/2886340 to your computer and use it in GitHub Desktop.
This is a JStwitter client lesson
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def run
puts "Welcome to the JSL Twitter Client!"
command = ""
while command != "q"
printf "enter command: "
input = gets.chomp
parts = input.split(" ")
command = parts[0]
case command
when 'q' then puts "Goodbye!"
when 't' then tweet(parts[1..-1].join(" "))
when 'dm' then dm(parts[1], parts[2..-1].join(" "))
when 'elt' then everyones_last_tweet
else
puts "Sorry, I don't know how to #{command}"
end
end
end
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
def tweet(message)
if message.length <=140
@client.update(message)
else
puts "Warning, Tweet is too long."
end
end
def dm(target, message)
screen_names = @client.followers.collect{|follower| follower.screen_name}
screen_names.each do |sn|
puts sn
end
if screen_names.include?(target)
puts "Trying to send #{target} this direct message:"
puts message
a = "d" + " " + target + " " + message
tweet(a)
else
puts "Cannot DM, you can only DM people who follow you."
end
end
#def followers_list
# screen_names = @client.followers.collect{|follower| follower.screen_name}
#end
def everyones_last_tweet
friends = @client.friends
friends.each do |friend|
b = friends.status.text # find each friends last message
puts friend.screen_name # print each friend's screen_name
puts b # print each friend's last message
puts "" # Just print a blank line to separate people
end
end
jst = JSTwitter.new
jst.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment