github_login 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'github_login'
4
+
5
+ token = GithubLogin::Token.new
6
+ token.save
@@ -1,39 +1,7 @@
1
1
  require "github_login/version"
2
+ require "github_login/token"
3
+ require "github_login/null_oauth"
2
4
  require 'github_api'
3
5
 
4
6
  module GithubLogin
5
- def create!
6
- File.open(file_path, 'w+') { |file| file.write token}
7
- end
8
-
9
- private
10
-
11
- def token
12
- oauth.token
13
- end
14
-
15
- def oauth
16
- github.oauth.create 'scopes' => ['repo']
17
- end
18
-
19
- def github
20
- Github.new login: login, password: password
21
- end
22
-
23
- def login
24
- print "Github username: "
25
- $stdin.gets.strip
26
- end
27
-
28
- def password
29
- print "Github password: "
30
- `stty -echo`
31
- $stdin.gets.strip
32
- ensure
33
- `stty echo`
34
- end
35
-
36
- def file_path
37
- '~/.github_token'
38
- end
39
7
  end
@@ -0,0 +1,5 @@
1
+ class GithubLogin::NullOauth
2
+ def token
3
+ ""
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ class GithubLogin::Token
2
+ def save
3
+ File.open(file_path, 'w+') { |file| file.write token}
4
+ end
5
+
6
+ def load
7
+ @token = file_content unless file_content.to_s.empty?
8
+ end
9
+
10
+ def fetch
11
+ load or save
12
+ token
13
+ end
14
+
15
+ private
16
+
17
+ def token
18
+ @token ||= oauth.token
19
+ end
20
+
21
+ def oauth
22
+ github.oauth.create 'scopes' => ['repo']
23
+ rescue Github::Error::Unauthorized
24
+ puts "\nWrong credentials"
25
+ GithubLogin::NullOauth.new
26
+ end
27
+
28
+ def github
29
+ Github.new login: login, password: password
30
+ end
31
+
32
+ def login
33
+ print "Github username: "
34
+ $stdin.gets.strip
35
+ end
36
+
37
+ def password
38
+ print "Github password: "
39
+ `stty -echo`
40
+ $stdin.gets.strip
41
+ ensure
42
+ `stty echo`
43
+ print "\n"
44
+ end
45
+
46
+ def file_path
47
+ File.expand_path("~/.github_token")
48
+ end
49
+
50
+ def file_content
51
+ File.read(file_path) if File.exists?(file_path)
52
+ end
53
+
54
+ end
@@ -1,3 +1,3 @@
1
1
  module GithubLogin
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_login
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -31,7 +31,8 @@ description: Console app that allows you to login into github using login and pa
31
31
  It stores token at disk, so it can be used by another apps.
32
32
  email:
33
33
  - stanislaw.kolarzowski@gmail.com
34
- executables: []
34
+ executables:
35
+ - github_login
35
36
  extensions: []
36
37
  extra_rdoc_files: []
37
38
  files:
@@ -40,8 +41,11 @@ files:
40
41
  - LICENSE
41
42
  - README.md
42
43
  - Rakefile
44
+ - bin/github_login
43
45
  - github_login.gemspec
44
46
  - lib/github_login.rb
47
+ - lib/github_login/null_oauth.rb
48
+ - lib/github_login/token.rb
45
49
  - lib/github_login/version.rb
46
50
  homepage: ''
47
51
  licenses: []