Created
June 19, 2012 00:07
-
-
Save dkan/2951571 to your computer and use it in GitHub Desktop.
JSTwitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bitly' | |
require 'jumpstart_auth' | |
require 'klout' | |
class JSTwitter | |
attr_reader :client | |
def initialize | |
puts "Initializing..." | |
@client = JumpstartAuth.twitter | |
@k = Klout.api_key = 'tdm297gad9f7zptv8qhta55m' | |
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 "spam" then spam_my_friends(parts[1..-1].join(" ")) | |
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 tweet(message) | |
if message.length > 140 | |
raise "tweet is longer than 140 characters" | |
else | |
@client.update(message) | |
end | |
end | |
def dm(target,message) | |
puts "Trying to send #{target} this direct message:" | |
screen_names = @client.followers.collect{ |follower| follower.screen_name } | |
if screen_names.include?(target) | |
tweet("d #{target} #{message}") | |
else | |
raise "that person isn't following you" | |
end | |
end | |
def followers_list | |
@screen_names = [] | |
@client.followers.each do |user| | |
@screen_names << user["screen_name"] | |
end | |
end | |
def spam_my_friends(message) | |
followers_list | |
@screen_names.each do |user| | |
dm(user,message) | |
end | |
end | |
def everyones_last_tweet | |
friends = @client.friends | |
friends.sort_by { |f| f.status.created_at }.reverse.each do |friend| | |
puts "#{friend.screen_name} said this at #{friend.status.created_at.strftime("%A, %b %d")}" | |
puts "#{friend.status.text}" | |
puts "" | |
end | |
puts "" | |
end | |
def shorten(original_url) | |
Bitly.use_api_version_3 | |
bitly = Bitly.new('hungryacademy', 'R_430e9f62250186d2612cca76eee2dbc6') | |
puts "Shortening this URL: #{original_url}" | |
bitly.shorten(original_url).short_url | |
end | |
def klout_score | |
friends = @client.friends.collect { |f| f.screen_name } | |
friends.each do |friend| | |
klout_id = Klout::Identity.find_by_screen_name(friend) | |
user = Klout::User.new(klout_id.id) | |
puts friend | |
puts user.score.score.round(2) | |
puts " " | |
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