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.



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

def initialize
  @username = get_username
  @password = get_password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.get_auth_tokenObject



7
8
9
10
11
# 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) ⇒ Object



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

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



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

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