Class: Octokom::Client

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

Constant Summary collapse

KEY =
'api.github.com'
URL =
'https://github.com/mjio/octokom'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/octokom/client.rb', line 8

def token
  @token
end

Class Method Details

.authenticateObject



13
14
15
# File 'lib/octokom/client.rb', line 13

def self.authenticate
  new.authenticate
end

Instance Method Details

#authenticateObject

Use the existing credentials form the ~/.netrc file to verify API requests to GitHub. When no credentials exist, ask for login and password to request a new token from GitHub.



20
21
22
23
24
25
26
27
28
29
# File 'lib/octokom/client.rb', line 20

def authenticate
  _, @token = netrc[KEY]

  unless token
    , password = ask_for_credentials
    create_authorization(, password)
  end

  self
end

#clientObject



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

def client
  require 'octokit'
  Octokit::Client.new(access_token: token)
end