Guest User

Untitled

a guest
May 31st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. require('rubygems')
  2. gem('twitter4r', '>=0.3.0')
  3. require('twitter')
  4. require('time') # Will not present timeline if removed!
  5.  
  6. # Helpers
  7.  
  8. def tweetLength tweet
  9. while tweet.length > 140
  10. puts 'Tweet is too long, make it 140 characters or less'
  11. tweet = gets.chomp
  12. end
  13. end
  14.  
  15. # Connect to twitter
  16.  
  17. def authentication
  18. puts "User:"
  19. @username = gets.chomp
  20. puts "Password:"
  21. @passcode = gets.chomp
  22. $client = Twitter::Client.new( :login => @username , :password => @passcode )
  23. end
  24.  
  25. def connectToTwitter
  26. while $client.authenticate?(@username,@passcode) == false
  27. puts "Your credentials appear to be incorrect :O. Please try again"
  28. authentication
  29. end
  30. puts "You have been succesfully logged in =)"
  31.  
  32. stuffToDo
  33. end
  34.  
  35. # Twitter Functions
  36.  
  37. def stuffToDo
  38. # Will ask you what you want to do and depending
  39. # on the number you choose you will be
  40. # send to that determinate method
  41.  
  42. puts 'What you want to do now?, Please choose a number'
  43. puts '1 - Update Status'
  44. puts '2 - Send a message to a friend'
  45. puts '3 - Show my Timeline'
  46. selection = gets.to_i
  47.  
  48. if selection == 1
  49. updateStatus
  50. end
  51. if selection == 2
  52. sendMessage
  53. end
  54. if selection == 3
  55. getTimeline
  56. end
  57. end
  58.  
  59. def updateStatus
  60. puts 'Tweet:'
  61. tweet = gets.chomp
  62. tweetLength tweet
  63. $client.status(:post, tweet)
  64.  
  65. stuffToDo
  66. end
  67.  
  68. def sendMessage
  69. puts 'Who do you want to recieve this message?'
  70. friend = gets.chomp
  71. puts 'Write your message please'
  72. tweet = gets.chomp
  73. tweetLength tweet
  74. $client.message(:post, tweet , friend)
  75.  
  76. stuffToDo
  77. end
  78.  
  79. def getTimeline
  80. $client.timeline_for(:friends) do |status|
  81. puts status.user.screen_name, status.text, "-----------------------------"
  82. end
  83.  
  84. stuffToDo
  85. end
  86.  
  87. authentication
  88. connectToTwitter
Add Comment
Please, Sign In to add comment