1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/examples/twitter.rb

32 lines
976 B
Ruby
Raw Normal View History

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
2015-04-18 08:38:40 -04:00
config = YAML.load(File.read(File.join(ENV['HOME'], '.twitter')))
class Twitter
include HTTParty
base_uri 'twitter.com'
2013-04-18 08:09:21 -04:00
def initialize(u, p)
@auth = {username: u, password: p}
end
2013-04-18 08:09:21 -04:00
# which can be :friends, :user or :public
# options[:query] can be things like since, since_id, count, etc.
def timeline(which = :friends, options = {})
2016-11-08 09:20:36 -05:00
options.merge!({ basic_auth: @auth })
self.class.get("/statuses/#{which}_timeline.json", options)
end
2013-04-18 08:09:21 -04:00
def post(text)
2016-11-08 09:20:36 -05:00
options = { query: { status: text }, basic_auth: @auth }
self.class.post('/statuses/update.json', options)
end
end
twitter = Twitter.new(config['email'], config['password'])
pp twitter.timeline
# pp twitter.timeline(:friends, query: {since_id: 868482746})
# pp twitter.timeline(:friends, query: 'since_id=868482746')
2013-04-18 08:09:21 -04:00
# pp twitter.post('this is a test of 0.2.0')