learn-web 0.0.12 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48a052ec6e555aeefb6ba768e3f9522d62a05431
4
- data.tar.gz: ed7d205c1a2216e15f041b31512980f1c6e51702
3
+ metadata.gz: e70d0afd562568b60b04dd6b98dc3632bfc3a324
4
+ data.tar.gz: 7e0a34bd00481a59d275fe269b5727c01e74922c
5
5
  SHA512:
6
- metadata.gz: 2301e5af64053bf1a955fceed5631e654564979b3c99c8d4042d160e98180e4d10d2d18b9ac2b4e01b821ecc2221f51ff79aaea982cef1d43bcec135b32daf0c
7
- data.tar.gz: c46a08b929411332b04bdf04aeab863e02b8c14374c92ebb6fed9e03ad9e76dba6fe3f713fd00e6bbc05e0f7c7a6cb8f8d1b4a7a65fbda0fb921266a234a55c0
6
+ metadata.gz: ba74673a402c700f519d06645c7616a6e00060736727de585425ea95ea35f4a7c16ddcd8f841393be9de36fc5f2e5e359ea67fffc4faf679efc44f67acdbbb0c
7
+ data.tar.gz: 91cbb33c7c69e3ed11726c585d8ef77b62d403f2ab69ed7be455a556a85bbd444cf4adf8b0e6520bc09a2a50fd40a9520dbb51a53e99172d7937a7291a0c10ad
data/lib/learn_web.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require 'faraday'
2
+ require 'oj'
3
+
1
4
  require 'learn_web/version'
5
+ require 'learn_web/attribute_populatable'
2
6
  require 'learn_web/client'
3
- require 'learn_web/client/me'
4
7
 
5
8
  module LearnWeb
6
9
  end
@@ -0,0 +1,19 @@
1
+ module LearnWeb
2
+ module AttributePopulatable
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def populate_attributes!
6
+ data.each do |attribute, value|
7
+ if !self.respond_to?(attribute)
8
+ self.class.class_eval do
9
+ attr_accessor attribute
10
+ end
11
+ end
12
+
13
+ self.send("#{attribute}=", value)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,8 @@
1
- require 'faraday'
1
+ require 'learn_web/client/user'
2
+ require 'learn_web/client/pull_request'
3
+ require 'learn_web/client/lesson'
4
+ require 'learn_web/client/validate_repo'
5
+ require 'learn_web/client/fork'
2
6
 
3
7
  module LearnWeb
4
8
  class Client
@@ -7,6 +11,12 @@ module LearnWeb
7
11
  LEARN_URL = 'https://learn.co'
8
12
  API_ROOT = '/api/v1'
9
13
 
14
+ include LearnWeb::Client::PullRequest
15
+ include LearnWeb::Client::Lesson
16
+ include LearnWeb::Client::ValidateRepo
17
+ include LearnWeb::Client::Fork
18
+ include LearnWeb::Client::User
19
+
10
20
  def initialize(token:, silent_output: false)
11
21
  @token = token
12
22
  @silent_output = silent_output
@@ -15,19 +25,6 @@ module LearnWeb
15
25
  end
16
26
  end
17
27
 
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
- LearnWeb::Client::Me.new(response, silent_output: silent_output)
29
- end
30
-
31
28
  def valid_token?
32
29
  !!me.data
33
30
  end
@@ -0,0 +1,21 @@
1
+ require 'learn_web/client/fork/request'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module Fork
6
+ def fork_endpoint
7
+ "#{API_ROOT}/fork_requests"
8
+ end
9
+
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
16
+
17
+ LearnWeb::Client::Fork::Request.new(response)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ module LearnWeb
2
+ class Client
3
+ module Fork
4
+ class Request
5
+ attr_reader :response
6
+ attr_accessor :message, :status
7
+
8
+ def initialize(response)
9
+ @response = response
10
+
11
+ parse!
12
+ end
13
+
14
+ private
15
+
16
+ def parse!
17
+ self.status = response.status
18
+
19
+ begin
20
+ body = Oj.load(response.body, symbol_keys: true)
21
+ self.message = body[:message]
22
+ rescue
23
+ self.message = 'Sorry, something went wrong. Please try again.'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'learn_web/client/lesson/current_lesson'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module Lesson
6
+ def current_lesson_endpoint
7
+ "#{API_ROOT}/users/current_lesson"
8
+ end
9
+
10
+ def current_lesson
11
+ response = @conn.get do |req|
12
+ req.url current_lesson_endpoint
13
+ req.headers['Authorization'] = "Bearer #{token}"
14
+ end
15
+
16
+ LearnWeb::Client::Lesson::CurrentLesson.new(response)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ module LearnWeb
2
+ class Client
3
+ module Lesson
4
+ class CurrentLesson
5
+ attr_reader :response
6
+ attr_accessor :data, :id, :title, :link, :github_repo, :forked_repo,
7
+ :assessments, :lab
8
+
9
+ include LearnWeb::AttributePopulatable
10
+
11
+ def initialize(response)
12
+ @response = response
13
+
14
+ parse!
15
+ end
16
+
17
+ def parse!
18
+ case response.status
19
+ when 200
20
+ self.data = Oj.load(response.body, symbol_keys: true)
21
+ populate_attributes!
22
+ when 401
23
+ puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
24
+ exit
25
+ when 500
26
+ puts "Something went wrong. Please try again."
27
+ exit
28
+ else
29
+ puts "Something when wrong. Please try again."
30
+ exit
31
+ end
32
+
33
+ self
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'learn_web/client/pull_request/response'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module PullRequest
6
+ def pr_endpoint
7
+ "#{API_ROOT}/lesson_submissions"
8
+ end
9
+
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
17
+
18
+ LearnWeb::Client::PullRequest::Response.new(response)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module LearnWeb
2
+ class Client
3
+ module PullRequest
4
+ class Response
5
+ attr_accessor :message, :status
6
+ attr_reader :data
7
+
8
+ def initialize(response_data)
9
+ @data = response_data
10
+
11
+ parse!
12
+ end
13
+
14
+ private
15
+
16
+ def parse!
17
+ self.status = data.status
18
+
19
+ begin
20
+ body = Oj.load(data.body, symbol_keys: true)
21
+ self.message = body[:message]
22
+ rescue
23
+ self.message = 'Sorry, something went wrong. Please try again.'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'learn_web/client/user/me'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module User
6
+ def me_endpoint
7
+ "#{API_ROOT}/users/me"
8
+ end
9
+
10
+ def me
11
+ response = @conn.get do |req|
12
+ req.url me_endpoint
13
+ req.headers['Authorization'] = "Bearer #{token}"
14
+ end
15
+
16
+ LearnWeb::Client::User::Me.new(response, silent_output: silent_output)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ module LearnWeb
2
+ class Client
3
+ module User
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
+ include LearnWeb::AttributePopulatable
10
+
11
+ def initialize(response, silent_output: false)
12
+ @response = response
13
+ @silent_output = silent_output
14
+
15
+ parse!
16
+ end
17
+
18
+ def parse!
19
+ if response.status == 200
20
+ self.data = Oj.load(response.body, symbol_keys: true)
21
+
22
+ populate_attributes!
23
+ elsif silent_output == false
24
+ case response.status
25
+ when 401
26
+ puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
27
+ exit
28
+ when 500
29
+ puts "Something went wrong. Please try again."
30
+ exit
31
+ else
32
+ puts "Something went wrong. Please try again."
33
+ exit
34
+ end
35
+ end
36
+
37
+ self
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require 'learn_web/client/validate_repo/slug'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module ValidateRepo
6
+ def validate_repo_slug_endpoint
7
+ "#{API_ROOT}/repo_slug_validations"
8
+ end
9
+
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
16
+
17
+ LearnWeb::Client::ValidateRepo::Slug.new(response)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,51 @@
1
+ module LearnWeb
2
+ class Client
3
+ module ValidateRepo
4
+ class Slug
5
+ attr_accessor :data, :repo_slug, :lab, :lesson_id
6
+ attr_reader :response
7
+
8
+ include AttributePopulatable
9
+
10
+ def initialize(response)
11
+ @response = response
12
+
13
+ parse!
14
+ end
15
+
16
+ private
17
+
18
+ def parse!
19
+ case response.status
20
+ when 200
21
+ self.data = Oj.load(response.body, symbol_keys: true)
22
+ populate_attributes!
23
+ when 401
24
+ puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
25
+ exit
26
+ when 422
27
+ begin
28
+ self.data = Oj.load(response.body, symbol_keys: true)
29
+ if data[:message].match(/Cannot find lesson/)
30
+ puts "Hmm...#{data[:message]}. Please check your input and try again."
31
+ exit
32
+ else
33
+ puts "Sorry, something went wrong. Please try again."
34
+ exit
35
+ end
36
+ rescue
37
+ puts "Sorry, something went wrong. Please try again."
38
+ exit
39
+ end
40
+ when 500
41
+ puts "Sorry, something went wrong. Please try again."
42
+ exit
43
+ else
44
+ puts "Sorry, something went wrong. Please try again."
45
+ exit
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module LearnWeb
2
- VERSION = "0.0.12"
2
+ VERSION = "1.0.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: 0.0.12
4
+ version: 1.0.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-05-22 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,8 +69,7 @@ dependencies:
69
69
  description:
70
70
  email:
71
71
  - learn@flatironschool.com
72
- executables:
73
- - learn-submit
72
+ executables: []
74
73
  extensions: []
75
74
  extra_rdoc_files: []
76
75
  files:
@@ -79,11 +78,20 @@ files:
79
78
  - LICENSE.txt
80
79
  - README.md
81
80
  - Rakefile
82
- - bin/learn-submit
83
81
  - learn-web.gemspec
84
82
  - lib/learn_web.rb
83
+ - lib/learn_web/attribute_populatable.rb
85
84
  - lib/learn_web/client.rb
86
- - lib/learn_web/client/me.rb
85
+ - lib/learn_web/client/fork.rb
86
+ - lib/learn_web/client/fork/request.rb
87
+ - lib/learn_web/client/lesson.rb
88
+ - lib/learn_web/client/lesson/current_lesson.rb
89
+ - lib/learn_web/client/pull_request.rb
90
+ - lib/learn_web/client/pull_request/response.rb
91
+ - lib/learn_web/client/user.rb
92
+ - lib/learn_web/client/user/me.rb
93
+ - lib/learn_web/client/validate_repo.rb
94
+ - lib/learn_web/client/validate_repo/slug.rb
87
95
  - lib/learn_web/version.rb
88
96
  homepage: https://learn.co
89
97
  licenses:
data/bin/learn-submit DELETED
File without changes
@@ -1,54 +0,0 @@
1
- require 'oj'
2
-
3
- module LearnWeb
4
- class Client
5
- class Me
6
- attr_accessor :response, :id, :first_name, :last_name, :full_name,
7
- :username, :email, :github_gravatar, :github_uid, :data,
8
- :silent_output
9
-
10
- def initialize(response, silent_output: false)
11
- @response = response
12
- @silent_output = silent_output
13
-
14
- parse!
15
- end
16
-
17
- def parse!
18
- if response.status == 200
19
- self.data = Oj.load(response.body, symbol_keys: true)
20
-
21
- populate_attributes!
22
- elsif silent_output == false
23
- case response.status
24
- when 401
25
- puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
26
- exit
27
- when 500
28
- puts "Something went wrong. Please try again."
29
- exit
30
- else
31
- puts "Something went wrong. Please try again."
32
- exit
33
- end
34
- end
35
-
36
- self
37
- end
38
-
39
- private
40
-
41
- def populate_attributes!
42
- data.each do |attribute, value|
43
- if !self.respond_to?(attribute)
44
- class << self
45
- attr_accessor attribute
46
- end
47
- end
48
-
49
- self.send("#{attribute}=", value)
50
- end
51
- end
52
- end
53
- end
54
- end