Class: Gitcamp::Github::Auth
- Inherits:
-
Thor
- Object
- Thor
- Gitcamp::Github::Auth
- Includes:
- Thor::Actions
- Defined in:
- lib/gitcamp/github/auth.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/gitcamp/github/auth.rb', line 5 def client @client end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/gitcamp/github/auth.rb', line 5 def username @username end |
Instance Method Details
#login ⇒ Object
8 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 34 35 36 37 38 39 40 |
# File 'lib/gitcamp/github/auth.rb', line 8 def login say 'Authenticating with GitHub', Thor::Shell::Color::YELLOW netrc = Netrc.read if netrc['api.github.com'] @username, oauth_token = netrc['api.github.com'] else @username = ask('Username:') password = ask_password('Password:') begin client = Octokit::Client.new(:login => @username, :password => password) rescue Octokit::Unauthorized => ex puts "Failed to authenticate you with those GitHub credentials" exit false end auth = client.(:scopes => %w[repo]) oauth_token = auth.token unless netrc['api.github.com'] netrc['api.github.com'] = @username, auth.token netrc.save end end client = Octokit::Client.new(:login => @username, :oauth_token => oauth_token) say "Authenticated as #{@username}", Thor::Shell::Color::GREEN client end |