Class: Shutwork::Command::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/shutwork/command/token.rb

Instance Method Summary collapse

Methods inherited from Base

#download_file, #initialize

Methods included from Display

#display_account, #display_file, #display_message, #display_room, #format_datetime, #format_filesize, #to_filesize_human

Constructor Details

This class inherits a constructor from Shutwork::Command::Base

Instance Method Details

#parse_args(args) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/shutwork/command/token.rb', line 7

def parse_args args
  opts = OptionParser.new
  opts.program_name = "shutwork #{self.class.name.split(/::/).last.downcase} [TOKEN]"
  opts.on("--skip-verify", "Skips validity check") { @skip_verify = true }
  opts.on("-v", "--verbose", "Verbose") { @verbose = true }
  opts.parse args
end

#run(args = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shutwork/command/token.rb', line 15

def run args = []
  @token = parse_args(args).first&.strip

  if @token
    unless @skip_verify
      verify_token!
    end
    Shutwork::Token.store @token
    say_status "save", Shutwork::Token.token_path, :green
  else
    token_ = Shutwork::Token.from_user_default
    if token_
      puts token_
    else
      puts "(Token is not stored)"
    end
  end

rescue Shutwork::AuthError
  $stderr.puts "Invalid token: #{@token}"
  exit 1
end

#verify_token!Object



38
39
40
41
# File 'lib/shutwork/command/token.rb', line 38

def verify_token!
  @client = Shutwork::Client.new token: @token, verbose: @verbose
  @client.me
end