Sha256: 52edd5c341a2655910379eefa6e2223238ed1e45de3682a1b85b5529770493fc

Contents?: true

Size: 992 Bytes

Versions: 16

Compression:

Stored size: 992 Bytes

Contents

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))

class Twitter
  include HTTParty
  base_uri 'twitter.com'
  
  def initialize(u, p)
    @auth = {:username => u, :password => p}
  end
  
  # which can be :friends, :user or :public
  # options[:query] can be things like since, since_id, count, etc.
  def timeline(which=:friends, options={})
    options.merge!({:basic_auth => @auth})
    self.class.get("/statuses/#{which}_timeline.json", options)
  end
  
  def post(text)
    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')
# pp twitter.post('this is a test')

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
alexvollmer-httparty-0.1.5 examples/twitter.rb
francxk-httparty-0.1.3 examples/twitter.rb
francxk-httparty-0.1.4 examples/twitter.rb
jnunemaker-httparty-0.1.1 examples/twitter.rb
jnunemaker-httparty-0.1.4 examples/twitter.rb
jnunemaker-httparty-0.1.5 examples/twitter.rb
jnunemaker-httparty-0.1.6 examples/twitter.rb
jnunemaker-httparty-0.1.7 examples/twitter.rb
jnunemaker-httparty-0.1.8 examples/twitter.rb
httparty-0.1.7 examples/twitter.rb
httparty-0.1.8 examples/twitter.rb
httparty-0.1.3 examples/twitter.rb
httparty-0.1.2 examples/twitter.rb
httparty-0.1.5 examples/twitter.rb
httparty-0.1.1 examples/twitter.rb
httparty-0.1.6 examples/twitter.rb