### Home Classes Methods

### In Files

- lib/plugins/user_stream.rb

### Parent

Object

### Methods

- ::repack_error
- #process
- #run

### Files

- ChangeLog
- README.rdoc

### Class/Module Index

Quicksearch

- Termtter
- Termtter::API
- Termtter::ActiveRubytter
- Termtter::Client
- Termtter::Client::DirectMessage
- Termtter::Client::Jakigan
- Termtter::Client::SearchEvent
- Termtter::Client::UserSearchEvent
- Termtter::Command
- Termtter::CommandCanceled
- Termtter::CommandLine
- Termtter::CommandNotFound
- Termtter::Config
- Termtter::ConfigSetup
- Termtter::Crypt
- Termtter::English
- Termtter::Event
- Termtter::HTTPpool
- Termtter::Hook
- Termtter::HookCanceled
- Termtter::Hookable
- Termtter::JSONError
- Termtter::MemoryCache
- Termtter::MemoryCache::MemCacheMock
- Termtter::OptParser
- Termtter::Plugin
- Termtter::Plugin::Screen
- Termtter::Plugins
- Termtter::Plugins::Haml
- Termtter::Plugins::ListSwitch
- Termtter::RubytterProxy
- Termtter::RubytterProxy::FrequentAccessError
- Termtter::RubytterProxy::LimitManager
- Termtter::Status
- Termtter::StdOut
- Termtter::Storage
- Termtter::Storage::SQLite3
- Termtter::Storage::Status
- Termtter::Task
- Termtter::TaskManager
- Termtter::TypableIdGenerator
- Termtter::UserStreamReceiver
- Yharian
- Yharian::Alex
- Yharian::Jenifer
- Yharian::Remark
- Yharian::Speaker
- Yharian::Vicki
- Yharian::Yhara
- HatenaKeywordHaiku
- HatenaKeywordHaiku::Word
- OAuth
- OAuth::AccessToken
- Readline
- Readline::LIBREADLINE
- AAMaker
- Array
- BrowserNotFound
- Growl
- IRB
- Object
- Status
- String
- Symbol
- TermColor
- TermtterIrcGateway
- User

No matching classes.

# Termtter::UserStreamReceiver

### Constants

ENDPOINT

### Public Class Methods

repack_error(error, chunk) click to toggle source

    # File lib/plugins/user_stream.rb, line 15
    def self.repack_error(error, chunk)
      new_error = error.class.new("#{error.message} (#{JSON.parse(chunk).inspect})")
      error.instance_variables.each{ |v|
        new_error.instance_variable_set(v, error.instance_variable_get(v))
      }
      new_error
    rescue
      error
    end

### Public Instance Methods

run(&block) click to toggle source

    # File lib/plugins/user_stream.rb, line 4
    def run(&block)
      loop {
        begin
          self.process &block
        rescue => error
          Termtter::Client.handle_error error
          sleep 10
        end
      }
    end

### Protected Instance Methods

process(&block) click to toggle source

    # File lib/plugins/user_stream.rb, line 28
    def process(&block)
      Termtter::Client.logger.info("connecting to UserStream")
      https = Net::HTTP.new(ENDPOINT.host, ENDPOINT.port)
      https.use_ssl = true
      https.verify_mode = OpenSSL::SSL::VERIFY_NONE

      https.start{ |https|
        request = Net::HTTP::Get.new(ENDPOINT.request_uri)
        request.oauth!(https, Termtter::API.twitter.access_token.consumer, Termtter::API.twitter.access_token)
        https.request(request){ |response|
          raise StandardError, response.code.to_i unless response.code.to_i == 200
          raise StandardError, 'Response is not chuncked' unless response.chunked?
          Termtter::Client.logger.info("connected to UserStream")
          response.read_body{ |chunk|
            Termtter::Client.logger.debug("received: #{chunk}")
            yield chunk
          }
        }
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.