Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 19, 2012 01:06
Show Gist options
  • Save perspectivezoom/2951724 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2951724 to your computer and use it in GitHub Desktop.
require 'jumpstart_auth'
require 'bitly'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
def tweet(message)
@client.update(message)
end
def dm(target,message)
puts "Trying to send #{target} this direct message:"
puts message
a_string = "d #{target} #{message}"
screen_names = @client.followers.collect {|follower| follower.screen_name }
if screen_names.include?(target)
tweet(a_string)
else
puts "Error: This person does not follow you"
end
end
def everyones_last_tweet
friends = @client.friends
friends = friends.sort_by { |friend| friend.screen_name.downcase }
friends.each do |friend|
timestamp = friend.status.created_at
# find each friends last message
puts "#{friend.screen_name} said this on #{timestamp.strftime("%A, %b %d") }"# print each friend's screen_name
puts friend.status.text# print each friend's last message
puts "" # Just print a blank line to separate people
end
end
def shorten(original_url)
#shortening code
puts "Shortening this URL: #{original_url}"
Bitly.use_api_version_3
bitly = Bitly.new('hungryacademy', 'R_430e9f62250186d2612cca76eee2dbc6')
short = bitly.shorten(original_url).short_url
puts short
return short
end
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 'c' 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
end
jst = JSTwitter.new
jst.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment