Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2011 00:19
Show Gist options
  • Save anonymous/902764 to your computer and use it in GitHub Desktop.
Save anonymous/902764 to your computer and use it in GitHub Desktop.
Sanu's code
require 'rubygems'
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
def tweet(message)
if message.length <= 140
@client.update(message)
puts "Tweet Posted."
else
puts "Too long, try again"
end
end
def dm(target, message)
#find the followers screen_name
# find the collection @client.followers, gather up screen_name
followers = @client.followers.users.collect do |user|
user.screen_name
end
if followers.include?(target)
puts "Sending the direct message to #{target}"
tweet "dm #{target} #{message}"
else
puts "Sorry #{target}doesn't follow you"
end
end
def run
command = " "
until command == "q"
printf "Enter command:"
input = gets.chomp
command = input.split.first
if command == "t"
message =input.split[1..-1].join(" ")
tweet(message)
elsif command = "d"
target = input.split[1]
message = input.split[2..-1].join(" ")
dm(target, message)
else
puts "Sorry, I don't know how to (#{command.inspect})"
end
end
end
end
# Script
jst = JSTwitter.new
jst.tweet("this is my tweet")
jst.run
jst.dm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment