Sha256: d32cdba623d11cbeff703e625c3dc65fd3cbf5b8af76cdbe77cb7ac1becbd3b9

Contents?: true

Size: 1.19 KB

Versions: 40

Compression:

Stored size: 1.19 KB

Contents

module Tw
  class Client::Stream
    def initialize(user=nil)
      user = Tw::Auth.get_or_regist_user user
      UserStream.configure do |config|
        config.consumer_key = Conf['consumer_key']
        config.consumer_secret = Conf['consumer_secret']
        config.oauth_token = user['access_token']
        config.oauth_token_secret = user['access_secret']
      end

      @client = UserStream::Client.new
    end

    def user_stream(&block)
      raise ArgumentError, 'block not given' unless block_given?
      @client.user do |m|
        if data = tweet?(m)
          yield data
        end
      end
    end

    def filter(*track_words, &block)
      raise ArgumentError, 'block not given' unless block_given?
      @client.filter :track => track_words.join(',') do |m|
        if data = tweet?(m)
          yield data
        end
      end
    end

    private
    def tweet?(chunk)
      return false unless chunk.user and chunk.user.screen_name and chunk.text and chunk.created_at and chunk.id
      Tw::Tweet.new(:id => chunk.id,
                    :user => chunk.user.screen_name,
                    :text => chunk.text,
                    :time => (Time.parse chunk.created_at))
    end

  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
tw-1.1.1 lib/tw/client/stream.rb
tw-1.1.0 lib/tw/client/stream.rb
tw-1.0.12 lib/tw/client/stream.rb
tw-1.0.11 lib/tw/client/stream.rb
tw-1.0.10 lib/tw/client/stream.rb
tw-1.0.9 lib/tw/client/stream.rb
tw-1.0.8 lib/tw/client/stream.rb
tw-1.0.7 lib/tw/client/stream.rb
tw-1.0.6 lib/tw/client/stream.rb
tw-1.0.5 lib/tw/client/stream.rb
tw-1.0.4 lib/tw/client/stream.rb
tw-1.0.3 lib/tw/client/stream.rb
tw-1.0.2 lib/tw/client/stream.rb
tw-1.0.1 lib/tw/client/stream.rb
tw-1.0.0 lib/tw/client/stream.rb
tw-0.5.2 lib/tw/client/stream.rb
tw-0.5.1 lib/tw/client/stream.rb
tw-0.5.0 lib/tw/client/stream.rb
tw-0.4.9 lib/tw/client/stream.rb
tw-0.4.8 lib/tw/client/stream.rb