learn-web 1.4.2 → 1.5.4

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
- SHA1:
3
- metadata.gz: cc308f49592f2e41a32e55ca66775179c0005229
4
- data.tar.gz: d0aeda72be382ddefe580305da9f74980cc12f3a
2
+ SHA256:
3
+ metadata.gz: ec078990d4dcddf3adef7d79ce20173b3fceefa8d532a233815b201a7e438981
4
+ data.tar.gz: 60c81b6a5376959e57bc203435feeab2c6dd67fbbe11c7105165b8c51ec77a5d
5
5
  SHA512:
6
- metadata.gz: 6e8734904056d93f9577dbe8e1abe6f469820196de4c22861a248fe6505b5648946510a345f78843beeacbc42c9f4c445143d73d5de766df2e197982d1e5ec72
7
- data.tar.gz: 2a96746b4ddd6b8d03bc32585cb20ed2030488421a5863e157c8ec647fd5c4f5bba997b8fde51a59c66077f4c19be3b11c249310d759089d9316d8c18c75549a
6
+ metadata.gz: c61fb11426b1d65f09fc352546faad5cc5f4dbad39c295cfdb9cb7361cdc5004fb8de84713e7409f054d6053fdf05c04a06b2411bb068bd54b23c50ce4b21742
7
+ data.tar.gz: 14e1e45098299de376b206b162286620f93c6e1ae26fecf2c34aa95f4a42195a03a216369dd548c2b12af7d338b0669f5ff149ad58d298f1654ce37c92c790e9
data/.gitignore CHANGED
@@ -12,3 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+
16
+ # built copies of the gem
17
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,42 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ # Rails files
16
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
17
+ dsl.watch_spec_files_for(rails.app_files)
18
+ dsl.watch_spec_files_for(rails.views)
19
+
20
+ watch(rails.controllers) do |m|
21
+ [
22
+ rspec.spec.call("routing/#{m[1]}_routing"),
23
+ rspec.spec.call("controllers/#{m[1]}_controller"),
24
+ rspec.spec.call("acceptance/#{m[1]}")
25
+ ]
26
+ end
27
+
28
+ # Rails config changes
29
+ watch(rails.spec_helper) { rspec.spec_dir }
30
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
31
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
32
+
33
+ # Capybara features specs
34
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
35
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
36
+
37
+ # Turnip features and steps
38
+ watch(%r{^spec/acceptance/(.+)\.feature$})
39
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
40
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
41
+ end
42
+ end
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :console do
4
+ require 'pry'
5
+ load 'lib/learn_web.rb'
6
+ Pry.start
7
+ end
@@ -19,7 +19,10 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.7"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "pry", "~> 0.11.3"
23
+ spec.add_development_dependency "rspec", "~> 3.8.0"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.7.0"
22
25
 
23
26
  spec.add_runtime_dependency "faraday", "~> 0.9"
24
- spec.add_runtime_dependency "oj", "~> 2.9"
27
+ spec.add_runtime_dependency "oj", "~> 3.10"
25
28
  end
@@ -6,12 +6,14 @@ require 'learn_web/client/lesson'
6
6
  require 'learn_web/client/validate_repo'
7
7
  require 'learn_web/client/fork'
8
8
  require 'learn_web/client/environment'
9
+ require 'learn_web/client/event'
10
+ require 'learn_web/client/ssh_keys'
9
11
 
10
12
  module LearnWeb
11
13
  class Client
12
14
  attr_reader :token, :conn, :silent_output
13
15
 
14
- LEARN_URL = 'https://learn.co'
16
+ LEARN_URL = ENV.fetch('LEARN_CO_URL', 'https://learn.co').freeze
15
17
  API_ROOT = '/api/v1'
16
18
 
17
19
  include LearnWeb::Client::Request
@@ -22,6 +24,8 @@ module LearnWeb
22
24
  include LearnWeb::Client::Fork
23
25
  include LearnWeb::Client::User
24
26
  include LearnWeb::Client::Environment
27
+ include LearnWeb::Client::Event
28
+ include LearnWeb::Client::SshKeys
25
29
 
26
30
  def initialize(token:, silent_output: false)
27
31
  @token = token
@@ -0,0 +1,31 @@
1
+ require 'learn_web/client/event/submission'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module Event
6
+ attr_reader :client
7
+
8
+ IRONBROKER_URL = 'http://ironbroker-v2.flatironschool.com'
9
+
10
+ def client
11
+ @client ||= Faraday.new(url: IRONBROKER_URL) do |faraday|
12
+ faraday.adapter Faraday.default_adapter
13
+ end
14
+ end
15
+
16
+ def submission_endpoint
17
+ '/e/learn_gem'
18
+ end
19
+
20
+ def submit_event(params)
21
+ response = post(
22
+ submission_endpoint,
23
+ body: params,
24
+ client: client
25
+ )
26
+
27
+ LearnWeb::Client::Event::Submission.new(response)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module LearnWeb
2
+ class Client
3
+ module Event
4
+ class Submission
5
+ attr_reader :response
6
+ attr_accessor :data
7
+
8
+ include LearnWeb::AttributePopulatable
9
+ include LearnWeb::ResponseParsable
10
+
11
+ def initialize(response)
12
+ @response = response
13
+
14
+ parse!
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -4,7 +4,7 @@ module LearnWeb
4
4
  class CurrentLesson
5
5
  attr_reader :response
6
6
  attr_accessor :data, :id, :title, :link, :github_repo, :forked_repo,
7
- :assessments, :lab
7
+ :clone_repo, :assessments, :lab, :dot_learn
8
8
 
9
9
  include LearnWeb::AttributePopulatable
10
10
  include LearnWeb::ResponseParsable
@@ -4,7 +4,7 @@ module LearnWeb
4
4
  class NextLesson
5
5
  attr_reader :response
6
6
  attr_accessor :data, :id, :title, :link, :github_repo, :forked_repo,
7
- :assessments, :lab
7
+ :clone_repo, :assessments, :lab, :dot_learn
8
8
 
9
9
  include LearnWeb::AttributePopulatable
10
10
  include LearnWeb::ResponseParsable
@@ -6,7 +6,8 @@ module LearnWeb
6
6
 
7
7
  def request(method, url, options = {})
8
8
  begin
9
- @conn.send(method) do |req|
9
+ connection = options[:client] || @conn
10
+ connection.send(method) do |req|
10
11
  req.url url
11
12
  build_request(req, options)
12
13
  end
@@ -18,6 +19,7 @@ module LearnWeb
18
19
  def build_request(request, options)
19
20
  build_headers(request, options[:headers])
20
21
  build_params(request, options[:params])
22
+ build_body(request, options[:body])
21
23
  end
22
24
 
23
25
  def build_headers(request, headers)
@@ -35,6 +37,12 @@ module LearnWeb
35
37
  end
36
38
  end
37
39
  end
40
+
41
+ def build_body(request, body)
42
+ if body
43
+ request.body = Oj.dump(body, mode: :compat)
44
+ end
45
+ end
38
46
  end
39
47
  end
40
48
  end
@@ -0,0 +1,22 @@
1
+ require 'learn_web/client/ssh_keys/add'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ module SshKeys
6
+ def add_ssh_key_endpoint
7
+ "#{API_ROOT}/ssh_keys"
8
+ end
9
+
10
+ def add_ssh_key(key:, key_title: nil, client: nil)
11
+ response = post(
12
+ add_ssh_key_endpoint,
13
+ headers: { 'Authorization' => "Bearer #{token}" },
14
+ params: { 'key' => key, key_title: key_title }.reject { |_, v| v.nil? },
15
+ client: client
16
+ )
17
+
18
+ LearnWeb::Client::SshKeys::Add.new(response).parse!
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module LearnWeb
2
+ class Client
3
+ module SshKeys
4
+ class Add
5
+ attr_reader :response
6
+ attr_accessor :data
7
+
8
+ include LearnWeb::AttributePopulatable
9
+
10
+ def initialize(response)
11
+ @response = response
12
+ end
13
+
14
+ def parse!
15
+ if response.status == 200
16
+ self.data = Oj.load(response.body, symbol_keys: true)
17
+
18
+ populate_attributes!
19
+ self
20
+ else
21
+ case response.status
22
+ when 304
23
+ puts "This key is already in use."
24
+ when 422
25
+ puts "Something went wrong. Please try again."
26
+ else
27
+ puts "Something went wrong. Please try again."
28
+ end
29
+ :error
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,7 +2,8 @@ module LearnWeb
2
2
  class Client
3
3
  module ValidateRepo
4
4
  class Slug
5
- attr_accessor :data, :repo_slug, :lab, :lesson_id, :later_lesson
5
+ attr_accessor :data, :repo_slug, :lab, :lesson_id, :later_lesson,
6
+ :repo_name, :dot_learn
6
7
  attr_reader :response
7
8
 
8
9
  include AttributePopulatable
@@ -1,3 +1,3 @@
1
1
  module LearnWeb
2
- VERSION = '1.4.2'
2
+ VERSION = '1.5.4'
3
3
  end
@@ -0,0 +1,73 @@
1
+ require 'json'
2
+
3
+ RSpec.describe LearnWeb::Client do
4
+ context "Constants" do
5
+ it "sets the LEARN_URL to learn.co" do
6
+ expect(LearnWeb::Client::LEARN_URL).to eq("https://learn.co")
7
+ end
8
+
9
+ it "sets the API_ROOT to the root" do
10
+ expect(LearnWeb::Client::API_ROOT).to eq("/api/v1")
11
+ end
12
+ end
13
+
14
+ context "Adding an ssh key" do
15
+ let(:headers) { {} }
16
+ let(:params) { {} }
17
+ let(:req_double) { double("request double", headers: headers, params: params) } # Faraday's weird api
18
+ let(:web_client) { double }
19
+ let(:client) { LearnWeb::Client.new(token: "mytoken") }
20
+
21
+ before do
22
+ allow(req_double).to receive(:url).with("/api/v1/ssh_keys")
23
+ end
24
+
25
+ it "correctly makes the request" do
26
+ expect(web_client).to receive(:post)
27
+ .and_yield(req_double)
28
+ .and_return(double(status: 200, body: {message: "Success"}.to_json))
29
+ client.add_ssh_key(key: "a valid ssh key", key_title: "LearnWeb Test Suite", client: web_client)
30
+
31
+ expect(headers).to eq({"Authorization"=>"Bearer mytoken"})
32
+ expect(params).to eq({"key"=>"a valid ssh key", :key_title=>"LearnWeb Test Suite"})
33
+ end
34
+
35
+ it "does not send a key title if not provided" do
36
+ expect(web_client).to receive(:post)
37
+ .and_yield(req_double)
38
+ .and_return(double(status: 200, body: {message: "Success"}.to_json))
39
+
40
+ client.add_ssh_key(key: "a valid ssh key", client: web_client)
41
+
42
+ expect(headers).to eq({"Authorization"=>"Bearer mytoken"})
43
+ expect(params).to eq({"key"=>"a valid ssh key"})
44
+ end
45
+
46
+ it "prints info on 304" do
47
+ expect(web_client).to receive(:post)
48
+ .and_yield(req_double)
49
+ .and_return(double(status: 304, body: {message: "womp"}.to_json))
50
+ expect do
51
+ client.add_ssh_key(key: "a valid ssh key", client: web_client)
52
+ end.to output("This key is already in use.\n").to_stdout
53
+
54
+ end
55
+ it "prints info on 422" do
56
+ expect(web_client).to receive(:post)
57
+ .and_yield(req_double)
58
+ .and_return(double(status: 422, body: {message: "womp"}.to_json))
59
+ expect do
60
+ client.add_ssh_key(key: "a valid ssh key", client: web_client)
61
+ end.to output("Something went wrong. Please try again.\n").to_stdout
62
+ end
63
+
64
+ it "prints info on anything else" do
65
+ expect(web_client).to receive(:post)
66
+ .and_yield(req_double)
67
+ .and_return(double(status: 418, body: {message: "womp"}.to_json))
68
+ expect do
69
+ client.add_ssh_key(key: "a valid ssh key", client: web_client)
70
+ end.to output("Something went wrong. Please try again.\n").to_stdout
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ $: << '.'
2
+ require 'lib/learn_web'
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.shared_context_metadata_behavior = :apply_to_host_groups
13
+ 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.4.2
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flatiron School
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.8.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.7.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.7.0
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: faraday
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -58,15 +100,15 @@ dependencies:
58
100
  requirements:
59
101
  - - "~>"
60
102
  - !ruby/object:Gem::Version
61
- version: '2.9'
103
+ version: '3.10'
62
104
  type: :runtime
63
105
  prerelease: false
64
106
  version_requirements: !ruby/object:Gem::Requirement
65
107
  requirements:
66
108
  - - "~>"
67
109
  - !ruby/object:Gem::Version
68
- version: '2.9'
69
- description:
110
+ version: '3.10'
111
+ description:
70
112
  email:
71
113
  - learn@flatironschool.com
72
114
  executables: []
@@ -74,7 +116,9 @@ extensions: []
74
116
  extra_rdoc_files: []
75
117
  files:
76
118
  - ".gitignore"
119
+ - ".rspec"
77
120
  - Gemfile
121
+ - Guardfile
78
122
  - LICENSE.txt
79
123
  - README.md
80
124
  - Rakefile
@@ -86,6 +130,8 @@ files:
86
130
  - lib/learn_web/client/environment.rb
87
131
  - lib/learn_web/client/environment/setup_list.rb
88
132
  - lib/learn_web/client/environment/verification.rb
133
+ - lib/learn_web/client/event.rb
134
+ - lib/learn_web/client/event/submission.rb
89
135
  - lib/learn_web/client/fork.rb
90
136
  - lib/learn_web/client/fork/request.rb
91
137
  - lib/learn_web/client/lesson.rb
@@ -95,17 +141,21 @@ files:
95
141
  - lib/learn_web/client/pull_request.rb
96
142
  - lib/learn_web/client/pull_request/response.rb
97
143
  - lib/learn_web/client/request.rb
144
+ - lib/learn_web/client/ssh_keys.rb
145
+ - lib/learn_web/client/ssh_keys/add.rb
98
146
  - lib/learn_web/client/user.rb
99
147
  - lib/learn_web/client/user/me.rb
100
148
  - lib/learn_web/client/validate_repo.rb
101
149
  - lib/learn_web/client/validate_repo/slug.rb
102
150
  - lib/learn_web/response_parsable.rb
103
151
  - lib/learn_web/version.rb
152
+ - spec/learn_web/client_spec.rb
153
+ - spec/spec_helper.rb
104
154
  homepage: https://learn.co
105
155
  licenses:
106
156
  - MIT
107
157
  metadata: {}
108
- post_install_message:
158
+ post_install_message:
109
159
  rdoc_options: []
110
160
  require_paths:
111
161
  - lib
@@ -120,9 +170,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
170
  - !ruby/object:Gem::Version
121
171
  version: '0'
122
172
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.4.8
125
- signing_key:
173
+ rubygems_version: 3.0.6
174
+ signing_key:
126
175
  specification_version: 4
127
176
  summary: An interface to Learn.co
128
- test_files: []
177
+ test_files:
178
+ - spec/learn_web/client_spec.rb
179
+ - spec/spec_helper.rb