-
-
Save jcasimir/902686 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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(username, message) | |
| if ((username.length + message.length) <= 137) && follows_me?(username) | |
| 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 follows_me?(user_name) | |
| followers = @client.followers.users.collect do |user| | |
| user.screen_name | |
| end | |
| return followers.include?(user_name) | |
| # 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 | |
| if command == "t" | |
| message = input.split[1..-1].join(" ") | |
| tweet(message) | |
| elsif command == "d" | |
| message = input.split[2..-1].join(" ") | |
| username = input.split[1] | |
| direct_message(username, 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