Sha256: b60cd2ea0897226c2b2e3018f555f8dbe023cffa4ab876addba0f3451e41fbbc

Contents?: true

Size: 976 Bytes

Versions: 149

Compression:

Stored size: 976 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

149 entries across 123 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/httparty-0.22.0/examples/twitter.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/httparty-0.22.0/examples/twitter.rb
httparty-0.22.0 examples/twitter.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/twitter.rb