Guest User

Untitled

a guest
Oct 20th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
  2. require File.join(dir, 'httparty')
  3. require 'pp'
  4. config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))
  5.  
  6. class Twitter
  7. include HTTParty
  8. base_uri 'twitter.com'
  9.  
  10. def initialize(u, p)
  11. @auth = {:username => u, :password => p}
  12. end
  13.  
  14. # which can be :friends, :user or :public
  15. # options[:query] can be things like since, since_id, count, etc.
  16. def timeline(which=:friends, options={})
  17. options.merge!({:basic_auth => @auth})
  18. self.class.get("/statuses/#{which}_timeline.json", options)
  19. end
  20.  
  21. def post(text)
  22. options = { :query => {:status => text}, :basic_auth => @auth }
  23. self.class.post('/statuses/update.json', options)
  24. end
  25. end
  26.  
  27. twitter = Twitter.new(config['email'], config['password'])
  28. pp twitter.timeline
  29. # pp twitter.timeline(:friends, :query => {:since_id => 868482746})
  30. # pp twitter.timeline(:friends, :query => 'since_id=868482746')
  31. # pp twitter.post('this is a test of 0.2.0')
Add Comment
Please, Sign In to add comment