Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('rubygems')
- gem('twitter4r', '>=0.3.0')
- require('twitter')
- require('time') # Will not present timeline if removed!
- # Helpers
- def tweetLength tweet
- while tweet.length > 140
- puts 'Tweet is too long, make it 140 characters or less'
- tweet = gets.chomp
- end
- end
- # Connect to twitter
- def authentication
- puts "User:"
- @username = gets.chomp
- puts "Password:"
- @passcode = gets.chomp
- $client = Twitter::Client.new( :login => @username , :password => @passcode )
- end
- def connectToTwitter
- while $client.authenticate?(@username,@passcode) == false
- puts "Your credentials appear to be incorrect :O. Please try again"
- authentication
- end
- puts "You have been succesfully logged in =)"
- stuffToDo
- end
- # Twitter Functions
- def stuffToDo
- # Will ask you what you want to do and depending
- # on the number you choose you will be
- # send to that determinate method
- puts 'What you want to do now?, Please choose a number'
- puts '1 - Update Status'
- puts '2 - Send a message to a friend'
- puts '3 - Show my Timeline'
- selection = gets.to_i
- if selection == 1
- updateStatus
- end
- if selection == 2
- sendMessage
- end
- if selection == 3
- getTimeline
- end
- end
- def updateStatus
- puts 'Tweet:'
- tweet = gets.chomp
- tweetLength tweet
- $client.status(:post, tweet)
- stuffToDo
- end
- def sendMessage
- puts 'Who do you want to recieve this message?'
- friend = gets.chomp
- puts 'Write your message please'
- tweet = gets.chomp
- tweetLength tweet
- $client.message(:post, tweet , friend)
- stuffToDo
- end
- def getTimeline
- $client.timeline_for(:friends) do |status|
- puts status.user.screen_name, status.text, "-----------------------------"
- end
- stuffToDo
- end
- authentication
- connectToTwitter
Add Comment
Please, Sign In to add comment