Sha256: 5e4f85edaa959c72cfb1d4d894d7d029db108f2cace942d7f04532212f6f0d50

Contents?: true

Size: 972 Bytes

Versions: 8

Compression:

Stored size: 972 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 of 0.2.0')

Version data entries

8 entries across 7 versions & 3 rubygems

Version Path
httparty-0.14.0 examples/twitter.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/1.9.1/gems/httparty-0.13.7/examples/twitter.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/2.0.0/gems/httparty-0.13.7/examples/twitter.rb
httparty-0.13.7 examples/twitter.rb
httparty-0.13.6 examples/twitter.rb
httpserious-0.13.5.lstoll1 examples/twitter.rb
httparty-0.13.5 examples/twitter.rb
httparty-0.13.4 examples/twitter.rb