Method: ChangesSince::ApiClient#initialize

Defined in:
lib/changes_since/api_client.rb

#initializeApiClient

Returns a new instance of ApiClient.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/changes_since/api_client.rb', line 9

def initialize
  puts "Please enter your Github credentials:"
  print "Username:"
  username = gets.chomp
  print "Password:"
  password = STDIN.noecho(&:gets).chomp
  puts

  @client = Octokit::Client.new(
    :login => username,
    :password => password
  )

  begin
    fetch_authorization
  rescue Octokit::OneTimePasswordRequired => e
    puts "Enter two factor auth token:"
    otp_token = gets.chomp
    fetch_authorization(otp_token)
  end

  @client = Octokit::Client.new(:access_token => access_token)
  git = Git.open(Dir.pwd)
  @repo = git.remote.url.split(/[:.]/)[-2]
end