learn-config 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/learn-config.gemspec +1 -2
- data/lib/learn_config/cli.rb +1 -1
- data/lib/learn_config/setup.rb +4 -7
- data/lib/learn_config/version.rb +1 -1
- data/lib/learn_config.rb +1 -0
- metadata +7 -23
- data/lib/learn_config/learn_web_interactor.rb +0 -35
- data/lib/learn_config/me.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad486c6bd9a01d483e66bb6282b292e2cb0a239d
|
4
|
+
data.tar.gz: 3d35aaaff9d4346fd402014720b26c3fa2d4a649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80a961f07aae047d824fb4efd97b216a0ab6b9d0812162934b816eb26398aa3f8b499fd15acbdf70a365110ca783302cafaa08ad465e5ea3d66e8a6671a827e3
|
7
|
+
data.tar.gz: 4102baeedfd6c607a79bbfb866d7bf50d876609208bb69434edf3b98e4009a6e232905e98930d0e0a4633469fb3a4cf47a87fe3356e45d53eb270bfb5f62dc55
|
data/learn-config.gemspec
CHANGED
@@ -21,6 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
|
23
23
|
spec.add_runtime_dependency "netrc"
|
24
|
-
spec.add_runtime_dependency "
|
25
|
-
spec.add_runtime_dependency "oj", "~> 2.9"
|
24
|
+
spec.add_runtime_dependency "learn-web"
|
26
25
|
end
|
data/lib/learn_config/cli.rb
CHANGED
@@ -40,7 +40,7 @@ page at: https://learn.co/#{github_username ? github_username : 'your-github-use
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def token_valid?
|
43
|
-
learn =
|
43
|
+
learn = LearnWeb::Client.new(token: token, silent_output: true)
|
44
44
|
learn.valid_token?
|
45
45
|
end
|
46
46
|
end
|
data/lib/learn_config/setup.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'oj'
|
3
|
-
|
4
1
|
module LearnConfig
|
5
2
|
class Setup
|
6
3
|
attr_reader :netrc, :args, :reset, :whoami
|
@@ -32,7 +29,7 @@ module LearnConfig
|
|
32
29
|
|
33
30
|
def whoami?
|
34
31
|
_learn, token = netrc.read
|
35
|
-
me =
|
32
|
+
me = LearnWeb::Client.new(token: token).me
|
36
33
|
puts "Name: #{me.full_name}"
|
37
34
|
puts "Username: #{me.username}"
|
38
35
|
puts "Email: #{me.email}"
|
@@ -68,7 +65,7 @@ module LearnConfig
|
|
68
65
|
def setup_learn_config_machine
|
69
66
|
login, password = netrc.read
|
70
67
|
|
71
|
-
if (!login || !password) || !
|
68
|
+
if (!login || !password) || !LearnWeb::Client.new(token: password, silent_output: true).valid_token?
|
72
69
|
github_username, _uid = netrc.read(machine: 'flatiron-push')
|
73
70
|
oauth_token = LearnConfig::CLI.new(github_username).ask_for_oauth_token
|
74
71
|
netrc.write(new_login: 'learn', new_password: oauth_token)
|
@@ -78,7 +75,7 @@ module LearnConfig
|
|
78
75
|
def setup_flatiron_push_config_machine
|
79
76
|
learn_login, token = netrc.read(machine: 'learn-config')
|
80
77
|
|
81
|
-
if (!learn_login || !token) || !
|
78
|
+
if (!learn_login || !token) || !LearnWeb::Client.new(token: token, silent_output: true).valid_token?
|
82
79
|
setup_learn_config_machine
|
83
80
|
else
|
84
81
|
ensure_correct_push_config(token)
|
@@ -86,7 +83,7 @@ module LearnConfig
|
|
86
83
|
end
|
87
84
|
|
88
85
|
def ensure_correct_push_config(token)
|
89
|
-
me =
|
86
|
+
me = LearnWeb::Client.new(token: token).me
|
90
87
|
github_username = me.username
|
91
88
|
github_user_id = me.github_uid
|
92
89
|
|
data/lib/learn_config/version.rb
CHANGED
data/lib/learn_config.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: learn-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flatiron School
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,33 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: learn-web
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.9'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.9'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: oj
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '0'
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '0'
|
83
69
|
description:
|
84
70
|
email:
|
85
71
|
- learn@flatironschool.com
|
@@ -97,8 +83,6 @@ files:
|
|
97
83
|
- learn-config.gemspec
|
98
84
|
- lib/learn_config.rb
|
99
85
|
- lib/learn_config/cli.rb
|
100
|
-
- lib/learn_config/learn_web_interactor.rb
|
101
|
-
- lib/learn_config/me.rb
|
102
86
|
- lib/learn_config/netrc_interactor.rb
|
103
87
|
- lib/learn_config/setup.rb
|
104
88
|
- lib/learn_config/version.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module LearnConfig
|
4
|
-
class LearnWebInteractor
|
5
|
-
attr_reader :token, :conn, :silent_output
|
6
|
-
|
7
|
-
LEARN_URL = 'https://learn.co'
|
8
|
-
API_ROOT = '/api/v1'
|
9
|
-
|
10
|
-
def initialize(token, silent_output: false)
|
11
|
-
@token = token
|
12
|
-
@silent_output = silent_output
|
13
|
-
@conn = Faraday.new(url: LEARN_URL) do |faraday|
|
14
|
-
faraday.adapter Faraday.default_adapter
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def me_endpoint
|
19
|
-
"#{API_ROOT}/users/me"
|
20
|
-
end
|
21
|
-
|
22
|
-
def me
|
23
|
-
response = @conn.get do |req|
|
24
|
-
req.url me_endpoint
|
25
|
-
req.headers['Authorization'] = "Bearer #{token}"
|
26
|
-
end
|
27
|
-
|
28
|
-
LearnConfig::Me.new(response, silent_output: silent_output)
|
29
|
-
end
|
30
|
-
|
31
|
-
def valid_token?
|
32
|
-
!!me.data
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/learn_config/me.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'oj'
|
2
|
-
|
3
|
-
module LearnConfig
|
4
|
-
class Me
|
5
|
-
attr_accessor :response, :id, :first_name, :last_name, :full_name,
|
6
|
-
:username, :email, :github_gravatar, :github_uid, :data,
|
7
|
-
:silent_output
|
8
|
-
|
9
|
-
def initialize(response, silent_output: false)
|
10
|
-
@response = response
|
11
|
-
@silent_output = silent_output
|
12
|
-
|
13
|
-
parse!
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse!
|
17
|
-
if response.status == 200
|
18
|
-
self.data = Oj.load(response.body, symbol_keys: true)
|
19
|
-
|
20
|
-
populate_attributes!
|
21
|
-
elsif silent_output == false
|
22
|
-
case response.status
|
23
|
-
when 401
|
24
|
-
puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
|
25
|
-
exit
|
26
|
-
when 500
|
27
|
-
puts "Something went wrong. Please try again."
|
28
|
-
exit
|
29
|
-
else
|
30
|
-
puts "Something went wrong. Please try again."
|
31
|
-
exit
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def populate_attributes!
|
41
|
-
data.each do |attribute, value|
|
42
|
-
if !self.respond_to?(attribute)
|
43
|
-
class << self
|
44
|
-
attr_accessor attribute
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
self.send("#{attribute}=", value)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|