Class: Twurl::AliasesController

Inherits:
AbstractCommandController show all
Defined in:
lib/twurl/aliases_controller.rb

Constant Summary collapse

NO_ALIASES_MESSAGE =
"No aliases exist. Set one this way: twurl alias h /1.1/statuses/home_timeline.json"
NO_PATH_PROVIDED_MESSAGE =
"No path was provided to alias. Paths must start with a forward slash (ex. /1.1/statuses/update.json)."

Instance Attribute Summary

Attributes inherited from AbstractCommandController

#client, #options

Instance Method Summary collapse

Methods inherited from AbstractCommandController

dispatch, #initialize

Constructor Details

This class inherits a constructor from Twurl::AbstractCommandController

Instance Method Details

#dispatchObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twurl/aliases_controller.rb', line 5

def dispatch
  case options.subcommands.size
  when 0
    aliases = OAuthClient.rcfile.aliases
    if aliases && !aliases.empty?
      aliases.keys.sort.each do |name|
        CLI.puts "#{name}: #{aliases[name]}"
      end
    else
      CLI.puts NO_ALIASES_MESSAGE
    end
  when 1
    if options.path
      OAuthClient.rcfile.alias(options.subcommands.first, options.path)
    else
      CLI.puts NO_PATH_PROVIDED_MESSAGE
    end
  end
end