Class: Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gripst/client.rb

Constant Summary collapse

PATH =
ENV['HOME'] + '/.gripst'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



36
37
38
39
# File 'lib/gripst/client.rb', line 36

def initialize
  @username = get_username
  @password = get_password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



33
34
35
# File 'lib/gripst/client.rb', line 33

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



33
34
35
# File 'lib/gripst/client.rb', line 33

def username
  @username
end

Class Method Details

.get_auth_tokenObject



8
9
10
11
12
# File 'lib/gripst/client.rb', line 8

def get_auth_token
  return oauth_from_file if oauth_from_file
  authorizer = Client.new
  authorizer.authorize
end

.login_with_oauth(oauth_token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gripst/client.rb', line 14

def (oauth_token)
  client = Octokit::Client.new :access_token => oauth_token
  client.user.
  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

Instance Method Details

#authorizeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gripst/client.rb', line 41

def authorize
  begin
    auth_token = client.create_authorization :scopes => ['gists'], :note => 'gripst'
  rescue Octokit::OneTimePasswordRequired
    otp = get_otp
    auth_token = authorize_with_otp otp
  rescue Octokit::Unauthorized
    puts '---'
    puts '---'
    puts '---'
    puts 'Username or password was incorrect'
    exit
  end

  write_auth_token auth_token
  auth_token
end