### Home Classes Methods

### In Files

- lib/termtter/rubytter_proxy.rb
- lib/plugins/basic.rb
- lib/plugins/whale.rb
- lib/plugins/mongo.rb
- lib/plugins/list_switch.rb

### Parent

Object

### Namespace

- CLASS Termtter::RubytterProxy::FrequentAccessError
- CLASS Termtter::RubytterProxy::LimitManager

### Methods

- ::new
- #access_token
- #cached_status
- #cached_user
- #call_rubytter
- #call_rubytter_or_use_cache
- #call_rubytter_with_list_switch
- #call_rubytter_without_list_switch
- #consumer_token
- #current_limit
- #error_html_message_orig
- #error_html_message_whale
- #method_missing
- #safe
- #store_status_cache
- #store_user_cache

### Included Modules

- Termtter::Hookable

### 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::RubytterProxy

### Attributes

rubytter[R]
safe_mode[RW]

### Public Class Methods

new(*args) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 19
    def initialize(*args)
      @rubytter = OAuthRubytter.new(*args)
      @initial_args = args
    end

### Public Instance Methods

access_token() click to toggle source

XXX: these methods should in oauth_rubytter

    # File lib/termtter/rubytter_proxy.rb, line 172
    def access_token
      @rubytter.instance_variable_get(:@access_token)
    end

cached_status(status_id) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 94
    def cached_status(status_id)
      status = Termtter::Client.memory_cache.get(['status', status_id].join('-'))
      ActiveRubytter.new(status) if status
    end

cached_user(screen_name_or_id) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 89
    def cached_user(screen_name_or_id)
      user = Termtter::Client.memory_cache.get(['user', Termtter::Client.normalize_as_user_name(screen_name_or_id.to_s)].join('-'))
      ActiveRubytter.new(user) if user
    end

call_rubytter(method, *args, &block) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 123
    def call_rubytter(method, *args, &block)
      raise FrequentAccessError if @safe_mode && !self.current_limit.safe?
      config.retry.times do |now|
        begin
          timeout(config.timeout) do
            return @rubytter.__send__(method, *args, &block)
          end
        rescue Rubytter::APIError => e
          if /Status is over 140 characters/ =~ e.message
            len = args[0].charsize
            e2 = Rubytter::APIError.new("#{e.message} (+#{len - 140})")
            e2.set_backtrace(e.backtrace)
            raise e2
          else
            raise
          end
        rescue JSON::ParserError => e
          if message = error_html_message(e)
            puts message
            raise Rubytter::APIError.new(message)
          else
            raise e
          end
        rescue StandardError, TimeoutError => e
          if now + 1 == config.retry
            raise e
          else
            Termtter::Client.logger.debug { "rubytter_proxy: retry (#{e.class.to_s}: #{e.message})" }
          end
        end
      end
    end

Also aliased as: call_rubytter_without_list_switch
call_rubytter_or_use_cache(method, *args, &block) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 64
    def call_rubytter_or_use_cache(method, *args, &block)
      case method
      when :show
        unless status = cached_status(args[0])
          status = call_rubytter(method, *args, &block)
          store_status_cache(status)
        end
        status
      when :user
        unless user = cached_user(args[0])
          user = call_rubytter(method, *args, &block)
          store_user_cache(user)
        end
        user
      when :home_timeline, :user_timeline, :friends_timeline, :search
        statuses = call_rubytter(method, *args, &block)
        statuses.each do |status|
          store_status_cache(status)
        end
        statuses
      else
        call_rubytter(method, *args, &block)
      end
    end

call_rubytter_with_list_switch(method, *args, &block) click to toggle source

    # File lib/plugins/list_switch.rb, line 21
    def call_rubytter_with_list_switch(method, *args, &block)
      Termtter::Plugins::ListSwitch.call_rubytter(self, method, *args, &block)
    end

Also aliased as: call_rubytter
call_rubytter_without_list_switch(method, *args, &block) click to toggle source
Alias for: call_rubytter
consumer_token() click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 176
    def consumer_token
      access_token.consumer
    end

current_limit() click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 119
    def current_limit
      @limit_manager ||= LimitManager.new(@rubytter)
    end

error_html_message_orig(e) click to toggle source
Alias for: error_html_message
error_html_message_whale(e) click to toggle source

    # File lib/plugins/whale.rb, line 5
    def error_html_message_whale(e)
      if %Twitter / Over capacity' =~ e.message
        WHALE
      else
        error_html_message_orig(e)
      end
    end

Also aliased as: error_html_message
method_missing(method, *args, &block) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 24
    def method_missing(method, *args, &block)
      if @rubytter.respond_to?(method)
        result = nil
        begin
          modified_args = args
          hooks = self.class.get_hooks("pre_#{method}")
          hooks.each do |hook|
            modified_args = hook.call(*modified_args)
          end

          from = Time.now if Termtter::Client.logger.debug?
          Termtter::Client.logger.debug {
            "rubytter_proxy: #{method}(#{modified_args.inspect[1...-1]})"
          }
          result = call_rubytter_or_use_cache(method, *modified_args, &block)
          Termtter::Client.logger.debug {
            "rubytter_proxy: #{method}(#{modified_args.inspect[1...-1]}), " +
            "%.2fsec" % (Time.now - from)
          }

          self.class.call_hooks("post_#{method}", *args)
        rescue HookCanceled
        rescue TimeoutError => e
          Termtter::Client.logger.debug {
            "rubytter_proxy: #{method}(#{modified_args.inspect[1...-1]}) " +
            "#{e.message} #{'%.2fsec' % (Time.now - from)}"
          }
          raise e
        rescue => e
          Termtter::Client.logger.debug {
            "rubytter_proxy: #{method}(#{modified_args.inspect[1...-1]}) #{e.message}"
          }
          raise e
        end
        result
      else
        super
      end
    end

safe() click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 110
    def safe
      new_instance = self.class.new(@rubytter)
      new_instance.safe_mode = true
      self.instance_variables.each{ |v|
        new_instance.instance_variable_set(v, self.instance_variable_get(v))
      }
      new_instance
    end

store_status_cache(status) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 99
    def store_status_cache(status)
      Termtter::Client.memory_cache.set(['status', status.id].join('-'), status.to_hash, 3600 * 24 * 14)
      store_user_cache(status.user)
    end

store_user_cache(user) click to toggle source

    # File lib/termtter/rubytter_proxy.rb, line 104
    def store_user_cache(user)
      Termtter::Client.memory_cache.set(['user', user.id.to_i].join('-'), user.to_hash, 3600 * 24)
      Termtter::Client.memory_cache.set(['user', Termtter::Client.normalize_as_user_name(user.screen_name)].join('-'), user.to_hash, 3600 * 24)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.