learn-web 1.5.0 → 1.5.5

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: ac81838b897625bf99d52ec8bfbc4e247e92c783
4
- data.tar.gz: 2d939ba9e0d3a4a5f399e5665c3059a9c8d49490
2
+ SHA256:
3
+ metadata.gz: d9cb3dada51469d7f0fb2a8672c4cff6b1bbc37edcf0ac7f185b4a021e26a134
4
+ data.tar.gz: 3cebac24981963507ea4dff2a68aed6d34a3f0cbb877a0413ffa9cd572c18e1b
5
5
  SHA512:
6
- metadata.gz: cef560c5e879d2608ada091e3634683312c69ecc4ed02fe6fdc1eda6253f1f3938cfc586de9be40e2fb052d0ce2163157d14697e79c26e19ac77b65fd25b2b37
7
- data.tar.gz: 6ab8a648f17ae299ec0d9daad1a1abf6aa923e402efda058ca562085e2c663fe568f296bb8023f0561add9e68765be0f5acbd72ae75b696bd0bfd01109459f69
6
+ metadata.gz: 28c85ced0af8763149ac3f03fe9d63a9a38d0452776195a4d81bf03ddb75472bab1d4081ef22b78d364886baec907d5144659d70bebc7a268b7641d02be243c1
7
+ data.tar.gz: f0b0cffc30be553ddbffd15118c49f42ed3f5bd9a129e8e5cffc29a4dd549e2209c0db1fadb461a6049fef21237fecb760490497e88a2094906a398c2a8eebb7
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
- spec.add_runtime_dependency "faraday", "~> 0.9"
24
- spec.add_runtime_dependency "oj", "~> 2.9"
26
+ spec.add_runtime_dependency "faraday", "~> 1.0"
27
+ spec.add_runtime_dependency "oj", "~> 3.10"
25
28
  end
@@ -7,12 +7,13 @@ require 'learn_web/client/validate_repo'
7
7
  require 'learn_web/client/fork'
8
8
  require 'learn_web/client/environment'
9
9
  require 'learn_web/client/event'
10
+ require 'learn_web/client/ssh_keys'
10
11
 
11
12
  module LearnWeb
12
13
  class Client
13
14
  attr_reader :token, :conn, :silent_output
14
15
 
15
- LEARN_URL = 'https://learn.co'
16
+ LEARN_URL = ENV.fetch('LEARN_CO_URL', 'https://learn.co').freeze
16
17
  API_ROOT = '/api/v1'
17
18
 
18
19
  include LearnWeb::Client::Request
@@ -24,6 +25,7 @@ module LearnWeb
24
25
  include LearnWeb::Client::User
25
26
  include LearnWeb::Client::Environment
26
27
  include LearnWeb::Client::Event
28
+ include LearnWeb::Client::SshKeys
27
29
 
28
30
  def initialize(token:, silent_output: false)
29
31
  @token = token
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LearnWeb
2
- VERSION = '1.5.0'
2
+ VERSION = '1.5.5'
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.5.0
4
+ version: 1.5.5
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: 2016-07-14 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,35 +38,77 @@ 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
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '0.9'
89
+ version: '1.0'
48
90
  type: :runtime
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '0.9'
96
+ version: '1.0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: oj
57
99
  requirement: !ruby/object:Gem::Requirement
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
@@ -97,17 +141,21 @@ files:
97
141
  - lib/learn_web/client/pull_request.rb
98
142
  - lib/learn_web/client/pull_request/response.rb
99
143
  - lib/learn_web/client/request.rb
144
+ - lib/learn_web/client/ssh_keys.rb
145
+ - lib/learn_web/client/ssh_keys/add.rb
100
146
  - lib/learn_web/client/user.rb
101
147
  - lib/learn_web/client/user/me.rb
102
148
  - lib/learn_web/client/validate_repo.rb
103
149
  - lib/learn_web/client/validate_repo/slug.rb
104
150
  - lib/learn_web/response_parsable.rb
105
151
  - lib/learn_web/version.rb
152
+ - spec/learn_web/client_spec.rb
153
+ - spec/spec_helper.rb
106
154
  homepage: https://learn.co
107
155
  licenses:
108
156
  - MIT
109
157
  metadata: {}
110
- post_install_message:
158
+ post_install_message:
111
159
  rdoc_options: []
112
160
  require_paths:
113
161
  - lib
@@ -122,9 +170,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
170
  - !ruby/object:Gem::Version
123
171
  version: '0'
124
172
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.4.8
127
- signing_key:
173
+ rubygems_version: 3.0.6
174
+ signing_key:
128
175
  specification_version: 4
129
176
  summary: An interface to Learn.co
130
- test_files: []
177
+ test_files:
178
+ - spec/learn_web/client_spec.rb
179
+ - spec/spec_helper.rb