Class: Akane::CLI
- Inherits:
-
Object
- Object
- Akane::CLI
- Defined in:
- lib/akane/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auth ⇒ Object
- #help ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 |
# File 'lib/akane/cli.rb', line 13 def initialize(args) @args = args @options = nil end |
Class Method Details
.run(*args) ⇒ Object
8 9 10 |
# File 'lib/akane/cli.rb', line 8 def run(*args) self.new(*args).run end |
Instance Method Details
#auth ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/akane/cli.rb', line 24 def auth require 'twitter' consumer = config.consumer request_token = consumer.get_request_token puts "Allow me using this URL: #{request_token.}" print "Then type shown PIN: " pin = $stdin.gets.chomp print "Authorizing... " access_token = request_token.get_access_token(oauth_verifier: pin) twitter = Twitter::REST::Client.new( consumer_key: config[:consumer]['token'], consumer_secret: config[:consumer]['secret'], access_token: access_token.token, access_token_secret: access_token.secret, ) puts "done.\n\n" puts <<-EOY --- accounts: #{twitter.current_user.screen_name}: token: #{access_token.token} secret: #{access_token.secret} EOY end |
#help ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/akane/cli.rb', line 53 def help puts <<-EOH Usage: akane COMMAND [ARGS] Common commands: akane start - start akari Common options: -c, --config=FILE - Specify config file name to use EOH 0 end |
#run ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/akane/cli.rb', line 70 def run if @args.include?('--help') @command = :help else @command = (@args.shift || :help).to_sym end result = if self.respond_to?(@command) self.__send__(@command) else self.help end result.kind_of?(Numeric) ? result : 0 end |