class Client
Constants
- PATH
Attributes
password[R]
username[R]
Public Class Methods
get_auth_token()
click to toggle source
# File lib/gripst/client.rb, line 7 def get_auth_token return oauth_from_file if oauth_from_file authorizer = Client.new authorizer.authorize end
login_with_oauth(oauth_token)
click to toggle source
# File lib/gripst/client.rb, line 13 def login_with_oauth(oauth_token) client = Octokit::Client.new :access_token => oauth_token client.user.login client rescue Octokit::Unauthorized puts '---' puts '---' puts '---' puts 'Unable to create personal access token on github. Is the gripst application already set? https://github.com/settings/tokens' exit end
new()
click to toggle source
# File lib/gripst/client.rb, line 35 def initialize @username = get_username @password = get_password end
Private Class Methods
oauth_from_file()
click to toggle source
# File lib/gripst/client.rb, line 27 def oauth_from_file File.open PATH, &:readline if File.exists?(PATH) && !File.zero?(PATH) end
Public Instance Methods
Private Instance Methods
client()
click to toggle source
# File lib/gripst/client.rb, line 81 def client @client ||= Octokit::Client.new :login => username, :password => password end
get_otp()
click to toggle source
# File lib/gripst/client.rb, line 75 def get_otp puts 'Looks like you have 2FA. Smart move.' puts 'Enter the OTP from GitHub' STDIN.gets.chomp end
get_password()
click to toggle source
# File lib/gripst/client.rb, line 64 def get_password begin system "stty -echo" puts 'Enter your GitHub password' puts '(the input will be hidden)' STDIN.gets.chomp ensure system "stty echo" end end
get_username()
click to toggle source
# File lib/gripst/client.rb, line 59 def get_username puts 'Enter your GitHub username' STDIN.gets.chomp end
write_auth_token(oauth_token)
click to toggle source
# File lib/gripst/client.rb, line 99 def write_auth_token(oauth_token) File.new PATH, 'w+' unless File.exists? PATH file = File.open PATH, 'w+' file << oauth_token ensure file.close end