Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created June 19, 2012 01:35
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 kmandreza/2951823 to your computer and use it in GitHub Desktop.
Save kmandreza/2951823 to your computer and use it in GitHub Desktop.
JSTwitter.rb
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
def tweet(message)
if message.length > 140
puts "Your message is too long, please shorten"
else
puts 'Good job!'
@client.update(message)
end
end
def run
puts "Welcome to the JSL Twitter Client"
command = ""
while command != "q"
puts ""
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
when 's' then shorten(parts[1])
when 'turl' then tweet(parts[1..-2].join + ' ' + shorten(parts[-1]))
else
puts "Sorry, I don't know how to #{command}"
end
end
end
def dm(target, message)
puts "Trying to send #{target} this direct message:"
puts message
screen_names = @client.followers.collect{ |follower| follower.screen_name}
puts screen_names
if screen_names.include?(target)
tweet("d #{target} #{message}")
else
puts "Error: You can only direct message people who folow you"
end
end
def followers_list
screen_names = []
@client.followers.users.each do |follower|
screen_names << follower["screen_name"]
end
screen_names
end
def spam_my_friends(message)
followers_list.each do |follower|
tweet("d #{follower} #{message}")
end
end
def everyones_last_tweet
friends = @clients.friends
friends = friends.sort_by { |friend| friend.screen_name.downcase }
friends.each do |friend|
timestamp = friend.status.created_at
puts "#{friend.screen_name} said at #{timestamp.strftime("%A, %b %d")}"
puts "#{friend.status.text}"
end
end
def shorten(original_url)
require 'bitly'
Bitly.use_api_version_3
bitly = Bitly.new('hungryacademy', 'R_430e9f62250186d2612cca76eee2dbc6')
puts bitly.shorten(original_url).short_url
puts "Shortening this URL: #{original_method}"
end
jst = JSTwitter.new
jst.run
@taylor-smith
Copy link

Thanks so much for putting this online. Did you have any issues with twitter's api telling you that you had exceeded your rate limit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment