Class: Sredder::GithubAuth

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sredder/github_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sredderc = Sredderc.new) ⇒ GithubAuth

Returns a new instance of GithubAuth.



15
16
17
18
# File 'lib/sredder/github_auth.rb', line 15

def initialize(sredderc = Sredderc.new)
  @sredderc = sredderc
  @sredderc.load
end

Instance Attribute Details

#consumer=(value) ⇒ Object (writeonly)

Sets the attribute consumer

Parameters:

  • value

    the value to set the attribute consumer to.



11
12
13
# File 'lib/sredder/github_auth.rb', line 11

def consumer=(value)
  @consumer = value
end

#sreddercObject

Returns the value of attribute sredderc.



10
11
12
# File 'lib/sredder/github_auth.rb', line 10

def sredderc
  @sredderc
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sredder/github_auth.rb', line 27

def authorized?
  !!credentials[:github_token]
end

#run_oauth_procedureObject



20
21
22
23
24
25
# File 'lib/sredder/github_auth.rb', line 20

def run_oauth_procedure
  print "Please enter your github username: "
  username = $stdin.gets.strip
  val = `curl -u '#{username}' -d '{"scopes":["repo"],"client_id":"#{client_id}","client_secret":"#{client_secret}"}' https://api.github.com/authorizations`
  store_tokens(JSON.parse(val)["token"])
end

#tokenObject



31
32
33
# File 'lib/sredder/github_auth.rb', line 31

def token
  credentials[:github_token]
end