Class: EasyAuto::Authorize

Inherits:
Object
  • Object
show all
Includes:
ConfigManagerWrapper, EasyUtilities, SystemHelper
Defined in:
lib/easy_auto/authorize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigManagerWrapper

#config_manager

Methods included from SystemHelper

#check_install, #cli_send, #os

Methods included from EasyUtilities

#ask, #hidden_input

Instance Attribute Details

#emailObject

Returns the value of attribute email.



11
12
13
# File 'lib/easy_auto/authorize.rb', line 11

def email
  @email
end

#passwordObject

Returns the value of attribute password.



12
13
14
# File 'lib/easy_auto/authorize.rb', line 12

def password
  @password
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/easy_auto/authorize.rb', line 13

def token
  @token
end

Instance Method Details

#generate_tokenObject



43
44
45
# File 'lib/easy_auto/authorize.rb', line 43

def generate_token
  self.token = JSON.parse(github_curl)['token']
end

#get_credentialsObject



28
29
30
31
# File 'lib/easy_auto/authorize.rb', line 28

def get_credentials
  self.email = get_email
  self.password = get_password
end

#get_emailObject



33
34
35
36
# File 'lib/easy_auto/authorize.rb', line 33

def get_email
  puts "what is your github email account?"
  gets.strip
end

#get_passwordObject



38
39
40
41
# File 'lib/easy_auto/authorize.rb', line 38

def get_password
  puts "enter your password for #{email}. this will not be stored."
  hidden_input
end

#github_curlObject



47
48
49
# File 'lib/easy_auto/authorize.rb', line 47

def github_curl
  cli_send %Q(curl -u '#{email}:#{password}' -d '{"scopes": ["repo"], "notes": "Easy Auto"}' https://api.github.com/authorizations)
end

#runObject



15
16
17
18
19
# File 'lib/easy_auto/authorize.rb', line 15

def run
  get_credentials
  generate_token
  store_token
end

#store_tokenObject



21
22
23
24
25
26
# File 'lib/easy_auto/authorize.rb', line 21

def store_token
  GeneralStore.create '~/.easy-auto' do |gs|
    gs.github_email = email
    gs.github_token = token
  end
end