module Termtter::Plugins::ListSwitch

Attributes

active[R]
list_name[R]
list_user_id[R]
list_user_name[R]

Public Instance Methods

call_rubytter(rubytter_proxy, method, *args, &block) click to toggle source
# File lib/plugins/list_switch.rb, line 33
def call_rubytter(rubytter_proxy, method, *args, &block)
  if active
    case method
    when :home_timeline
      # => list_statuses(user_name, slug, options)
      method, args = :list_statuses, [list_user_name, list_name, *args]
    when :follow
      # => add_member_to_list(slug, user.id)
      method, args = :add_member_to_list, [list_name, *args]
    when :leave
      # => remove_member_from_list(slug, user.id)
      method, args = :remove_member_from_list, [list_name, *args]
    end
  end
  rubytter_proxy.call_rubytter_without_list_switch(method, *args, &block)
end
list_switch(full_name) click to toggle source
# File lib/plugins/list_switch.rb, line 50
def list_switch(full_name)
  @active = true
  @list_user_name, @list_name = split_list_name(full_name)
  user = Termtter::API.twitter.cached_user(list_user_name) ||
            Termtter::API.twitter.user(list_user_name)
  @list_user_id = user.id
  # TODO: やっつけなのでちゃんとやる
  config.prompt = full_name + '> '
end
restore() click to toggle source
# File lib/plugins/list_switch.rb, line 60
def restore
  @active = false
  # TODO: やっつけなのでちゃんとやる
  config.prompt = '> '
end
split_list_name(list_name) click to toggle source
# File lib/plugins/list_switch.rb, line 66
def split_list_name(list_name)
  if /([^\/]+)\/([^\/]+)/ =~ list_name
    [Termtter::Client.normalize_as_user_name($1), $2]
  else
    [config.user_name, $2]
  end
end