Class: Legato::CLI
- Inherits:
-
Object
- Object
- Legato::CLI
- Defined in:
- lib/legato/cli.rb
Instance Method Summary collapse
- #build_access_token ⇒ Object
- #build_config ⇒ Object
- #build_user ⇒ Object
- #client ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #print_yaml ⇒ Object
- #run ⇒ Object
- #setup_irb ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/legato/cli.rb', line 28 def initialize path = File.join(ENV['HOME'], '.legato.yml') if File.exists?(path) @config = YAML.load_file(path) rescue {} else puts "##########################################################" puts "We can auto-load OAuth2 config from ~/.legato.yml" puts "##########################################################" build_config end build_access_token print_yaml end |
Instance Method Details
#build_access_token ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/legato/cli.rb', line 82 def build_access_token if token @access_token = OAuth2::AccessToken.new(client, token) else puts puts "Opening the OAuth2 auth url: #{OAuth2Helpers.auth_url(client)} ..." `open "#{OAuth2Helpers.auth_url(client)}"` puts print 'OAuth2 Code (in the url): ' code = $stdin.gets.strip @access_token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost') @config['token'] = @access_token.token end end |
#build_config ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/legato/cli.rb', line 72 def build_config @config ||= {} puts print 'Your OAuth2 id: ' @config['id'] = $stdin.gets.strip print 'Your OAuth2 secret: ' @config['secret'] = $stdin.gets.strip end |
#build_user ⇒ Object
99 100 101 |
# File 'lib/legato/cli.rb', line 99 def build_user Legato::User.new(@access_token) end |
#client ⇒ Object
64 65 66 |
# File 'lib/legato/cli.rb', line 64 def client @client ||= OAuth2Helpers.build_client(@config['id'], @config['secret']) end |
#print_yaml ⇒ Object
103 104 105 106 107 108 |
# File 'lib/legato/cli.rb', line 103 def print_yaml puts "##########################################################" puts "If you haven't already done so, you can make ~/.legato.yml" puts YAML.dump(@config) puts "##########################################################" end |
#run ⇒ Object
46 47 48 |
# File 'lib/legato/cli.rb', line 46 def run setup_irb end |
#setup_irb ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legato/cli.rb', line 50 def setup_irb IRB.setup(nil) irb = IRB::Irb.new IRB.conf[:MAIN_CONTEXT] = irb.context irb.context.evaluate("require 'irb/completion'", 0) trap("SIGINT") do irb.signal_handle end catch(:IRB_EXIT) do irb.eval_input end end |
#token ⇒ Object
68 69 70 |
# File 'lib/legato/cli.rb', line 68 def token @config['token'] end |