learn-web 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a29bd27bf589876bd18bab7205b1551543eaaf5
4
- data.tar.gz: bc3a4f490cffb940c0d566cdd5c2b03fc5b17135
3
+ metadata.gz: 9bc55f9891c64b1405c9055bbc8d69a0f41b8195
4
+ data.tar.gz: b5c05c586e2386262b0d5536dff54f9801d62347
5
5
  SHA512:
6
- metadata.gz: 2a55c7a1aa9230e7ecd36dabc60dbf585e7632ae4b4c53b314cb1b98dbdc8e3e3fda338a5f3a2baf4b05dfb631c7cff4454b7d4cb67c053bae0bc2bc59383b5e
7
- data.tar.gz: 5c25beac760b0324729c53a3279d3f38e78368f31fb8b05f975fa5a8b2e8d7bb1140cf8d8ac4b5c85d1b781e3f0ef0c9f8b28e026acb358081df1345abc6541f
6
+ metadata.gz: 1980895824514add35d587a5e1267eec635f536cbc270dfc0aad8644da29cb61951bd842dd2b49c510f9505fde146920beaf682450497dd9ba4ce0364fa0e00b
7
+ data.tar.gz: 206fbfe990b713e1d514efde193c45706d086338c1588a1907dc6e1773643c24577cc265e371c0e34739b6729d95eadbe6ded281eb719d0c6241e9166875a85a
@@ -1,3 +1,5 @@
1
+ require 'learn_web/client/request'
2
+ require 'learn_web/client/connection'
1
3
  require 'learn_web/client/user'
2
4
  require 'learn_web/client/pull_request'
3
5
  require 'learn_web/client/lesson'
@@ -12,6 +14,8 @@ module LearnWeb
12
14
  LEARN_URL = 'https://learn.co'
13
15
  API_ROOT = '/api/v1'
14
16
 
17
+ include LearnWeb::Client::Request
18
+ include LearnWeb::Client::Connection
15
19
  include LearnWeb::Client::PullRequest
16
20
  include LearnWeb::Client::Lesson
17
21
  include LearnWeb::Client::ValidateRepo
@@ -0,0 +1,13 @@
1
+ module LearnWeb
2
+ class Client
3
+ module Connection
4
+ def get(url, options = {})
5
+ request :get, url, options
6
+ end
7
+
8
+ def post(url, options = {})
9
+ request :post, url, options
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,9 +8,7 @@ module LearnWeb
8
8
  end
9
9
 
10
10
  def environment_setup_list
11
- response = @conn.get do |req|
12
- req.url environment_setup_list_endpoint
13
- end
11
+ response = get(environment_setup_list_endpoint)
14
12
 
15
13
  LearnWeb::Client::Environment::SetupList.new(response)
16
14
  end
@@ -8,11 +8,11 @@ module LearnWeb
8
8
  end
9
9
 
10
10
  def fork_repo(repo_name:)
11
- response = @conn.post do |req|
12
- req.url fork_endpoint
13
- req.headers['Authorization'] = "Bearer #{token}"
14
- req.params['repo_name'] = repo_name
15
- end
11
+ response = post(
12
+ fork_endpoint,
13
+ headers: { 'Authorization' => "Bearer #{token}" },
14
+ params: { 'repo_name' => repo_name }
15
+ )
16
16
 
17
17
  LearnWeb::Client::Fork::Request.new(response)
18
18
  end
@@ -13,20 +13,20 @@ module LearnWeb
13
13
  end
14
14
 
15
15
  def current_lesson
16
- response = @conn.get do |req|
17
- req.url current_lesson_endpoint
18
- req.headers['Authorization'] = "Bearer #{token}"
19
- end
16
+ response = get(
17
+ current_lesson_endpoint,
18
+ headers: { 'Authorization' => "Bearer #{token}" }
19
+ )
20
20
 
21
21
  LearnWeb::Client::Lesson::CurrentLesson.new(response)
22
22
  end
23
23
 
24
24
  def next_lesson
25
- response = @conn.get do |req|
26
- req.url next_lesson_endpoint
27
- req.headers['Authorization'] = "Bearer #{token}"
28
- req.params['dir_name'] = File.basename(FileUtils.pwd)
29
- end
25
+ response = get(
26
+ next_lesson_endpoint,
27
+ headers: { 'Authorization' => "Bearer #{token}" },
28
+ params: { 'dir_name' => File.basename(FileUtils.pwd) }
29
+ )
30
30
 
31
31
  LearnWeb::Client::Lesson::NextLesson.new(response)
32
32
  end
@@ -8,12 +8,11 @@ module LearnWeb
8
8
  end
9
9
 
10
10
  def issue_pull_request(repo_name:, branch_name:)
11
- response = @conn.post do |req|
12
- req.url pr_endpoint
13
- req.headers['Authorization'] = "Bearer #{token}"
14
- req.params['repo_name'] = repo_name
15
- req.params['branch_name'] = branch_name
16
- end
11
+ response = post(
12
+ pr_endpoint,
13
+ headers: { 'Authorization' => "Bearer #{token}" },
14
+ params: { 'repo_name' => repo_name, 'branch_name' => branch_name }
15
+ )
17
16
 
18
17
  LearnWeb::Client::PullRequest::Response.new(response)
19
18
  end
@@ -0,0 +1,40 @@
1
+ module LearnWeb
2
+ class Client
3
+ module Request
4
+
5
+ private
6
+
7
+ def request(method, url, options = {})
8
+ begin
9
+ @conn.send(method) do |req|
10
+ req.url url
11
+ build_request(req, options)
12
+ end
13
+ rescue Faraday::ConnectionFailed
14
+ puts "Connection error. Please try again."
15
+ end
16
+ end
17
+
18
+ def build_request(request, options)
19
+ build_headers(request, options[:headers])
20
+ build_params(request, options[:params])
21
+ end
22
+
23
+ def build_headers(request, headers)
24
+ if headers
25
+ headers.each do |header, value|
26
+ request.headers[header] = value
27
+ end
28
+ end
29
+ end
30
+
31
+ def build_params(request, params)
32
+ if params
33
+ params.each do |param, value|
34
+ request.params[param] = value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -8,10 +8,10 @@ module LearnWeb
8
8
  end
9
9
 
10
10
  def me
11
- response = @conn.get do |req|
12
- req.url me_endpoint
13
- req.headers['Authorization'] = "Bearer #{token}"
14
- end
11
+ response = get(
12
+ me_endpoint,
13
+ headers: { 'Authorization' => "Bearer #{token}" }
14
+ )
15
15
 
16
16
  LearnWeb::Client::User::Me.new(response, silent_output: silent_output)
17
17
  end
@@ -24,13 +24,13 @@ module LearnWeb
24
24
  case response.status
25
25
  when 401
26
26
  puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
27
- exit
27
+ exit 1
28
28
  when 500
29
29
  puts "Something went wrong. Please try again."
30
- exit
30
+ exit 1
31
31
  else
32
32
  puts "Something went wrong. Please try again."
33
- exit
33
+ exit 1
34
34
  end
35
35
  end
36
36
 
@@ -8,11 +8,11 @@ module LearnWeb
8
8
  end
9
9
 
10
10
  def validate_repo_slug(repo_slug:)
11
- response = @conn.post do |req|
12
- req.url validate_repo_slug_endpoint
13
- req.headers['Authorization'] = "Bearer #{token}"
14
- req.params['repo_slug'] = repo_slug
15
- end
11
+ response = post(
12
+ validate_repo_slug_endpoint,
13
+ headers: { 'Authorization' => "Bearer #{token}" },
14
+ params: { 'repo_slug' => repo_slug }
15
+ )
16
16
 
17
17
  LearnWeb::Client::ValidateRepo::Slug.new(response)
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module LearnWeb
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
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-06-10 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - lib/learn_web.rb
83
83
  - lib/learn_web/attribute_populatable.rb
84
84
  - lib/learn_web/client.rb
85
+ - lib/learn_web/client/connection.rb
85
86
  - lib/learn_web/client/environment.rb
86
87
  - lib/learn_web/client/environment/setup_list.rb
87
88
  - lib/learn_web/client/fork.rb
@@ -91,6 +92,7 @@ files:
91
92
  - lib/learn_web/client/lesson/next_lesson.rb
92
93
  - lib/learn_web/client/pull_request.rb
93
94
  - lib/learn_web/client/pull_request/response.rb
95
+ - lib/learn_web/client/request.rb
94
96
  - lib/learn_web/client/user.rb
95
97
  - lib/learn_web/client/user/me.rb
96
98
  - lib/learn_web/client/validate_repo.rb
@@ -116,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version: '0'
117
119
  requirements: []
118
120
  rubyforge_project:
119
- rubygems_version: 2.4.5
121
+ rubygems_version: 2.4.8
120
122
  signing_key:
121
123
  specification_version: 4
122
124
  summary: An interface to Learn.co