Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2011 23:01
Show Gist options
  • Select an option

  • Save anonymous/902656 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/902656 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing JSTwitter..."
@client = JumpstartAuth.twitter
end
def tweet(message)
if message.length <= 140
@client.update(message)
puts "The tweet was posted!"
else
extra = message.length
over_count = []
over_count << extra - 137
puts "Your message is #{over_count} characters too long."
puts "Please try again!"
end
end
def direct_message(message)
if message.length <= 137
find_followers(message.split.first)
tweet("dm #{message}")
puts "Your DM to #{message.split.first} has been sent!"
else
extra = message.length
over_count = []
over_count << extra - 137
puts "Your DM to #{message.split.first} is #{over_count} characters too long."
puts "Please try again."
end
end
def find_followers(user_name)
followers = @client.followers.users.collect do |user|
user.screen_name
end
if followers.include(user_name)
#pass confirmation on to direct_message
else
#give error message and end direct_message method
puts "Sorry, #{user_name} does not follow you."
end
end
def run
puts "Welcome to the JSL Twitter Client"
command = ""
until command == "q"
puts "Enter command:"
input = gets.chomp
command = input.split.first
message = input.split[1..-1].join(" ")
if
command == "t"
tweet(message)
elsif
command == "d"
direct_message(message)
else
puts "Sorry, I don't know how to (#{command}"
end
end
end
end
# Script
jst = JSTwitter.new
jst.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment