github_login 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/github_login +6 -0
- data/lib/github_login.rb +2 -34
- data/lib/github_login/null_oauth.rb +5 -0
- data/lib/github_login/token.rb +54 -0
- data/lib/github_login/version.rb +1 -1
- metadata +6 -2
data/bin/github_login
ADDED
data/lib/github_login.rb
CHANGED
@@ -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,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
|
data/lib/github_login/version.rb
CHANGED
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
|
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: []
|