codewars 0.2.1 → 0.3.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 +4 -4
- data/README.md +13 -29
- data/codewars.gemspec +2 -1
- data/lib/codewars.rb +1 -1
- data/lib/codewars/attempt.rb +5 -6
- data/lib/codewars/cli.rb +16 -4
- data/lib/codewars/configuration.rb +1 -1
- data/lib/codewars/description.rb +3 -3
- data/lib/codewars/finalize.rb +2 -6
- data/lib/codewars/language_extensions.rb +1 -1
- data/lib/codewars/runner.rb +0 -2
- data/lib/codewars/train_next.rb +3 -8
- data/lib/codewars/train_specific.rb +8 -14
- data/lib/codewars/version.rb +1 -1
- metadata +27 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd0746ec8b08a3b1b025438cb6e18a8889b03f8
|
4
|
+
data.tar.gz: 8ece0ca9d47fbd804bfa38f72a7a44fff36b7e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df508ffa205cdb6bc6b47b9002458df09d61fd2351c62260e330d0c971d97c3f0a2943c47cc527bcf9338c59eb5dfc83cf63facaacfb0febf0eafa5c8890ec9
|
7
|
+
data.tar.gz: 13e16751a845fbca0d8dcbfa03778ee6892b91e6c365b9cd0ce6dc157663b29a4e9ff3a33548cc529ac9282d9a809d9cf1dc3c8e0b7aedee91626f105b56f2fc
|
data/README.md
CHANGED
@@ -2,44 +2,28 @@
|
|
2
2
|
|
3
3
|
## Installation
|
4
4
|
|
5
|
-
|
5
|
+
1. Make sure that Ruby is installed `ruby -v`
|
6
|
+
2. Run `gem install codewars`
|
6
7
|
|
7
8
|
## Usage
|
8
9
|
|
9
|
-
|
10
|
+
Run `codewars help` to see all available commands.
|
10
11
|
|
11
|
-
1. Set
|
12
|
-
2. Set a language
|
13
|
-
3. Choose a kata
|
14
|
-
4. Start solving
|
15
|
-
5.
|
16
|
-
6.
|
17
|
-
7.
|
18
|
-
8.
|
19
|
-
9.
|
20
|
-
10.
|
21
|
-
11. Look at results of other people, rest and pick up another kata or the same kata but using another language
|
12
|
+
1. Set TOKEN from https://www.codewars.com/users/edit `codewars config key your-secret-key`
|
13
|
+
2. Set a language `codewars config language ruby|javascript|etc`
|
14
|
+
3. Choose a kata `codewars train`
|
15
|
+
4. Start solving `codewars train name-of-kata`
|
16
|
+
5. Open a folder `cd name-of-kata/language/`
|
17
|
+
6. Create tests according on description.md
|
18
|
+
7. Make the tests green
|
19
|
+
8. Attempt the solution on the server `codewars attempt`
|
20
|
+
9. Refactor your code
|
21
|
+
10. Finalize `codewars finalize`
|
22
22
|
|
23
23
|
### Problems
|
24
24
|
|
25
25
|
Not sure for purpose or not but API sometimes caches a request for the next kata. To solve the problem go to the link http://www.codewars.com/dashboard in your browser.
|
26
26
|
|
27
|
-
## Development
|
28
|
-
|
29
|
-
### TO-DO
|
30
|
-
|
31
|
-
- [ ] Refactor anything you can
|
32
|
-
- [ ] Add travis, coveralls, etc
|
33
|
-
- [ ] After `codewars finalize` show a link with the language of submission
|
34
|
-
- [ ] Change the name of commands: attempt and finalize (join them to one command?)
|
35
|
-
- [ ] Rename 'config' command? Maybe to 'set'?
|
36
|
-
- [ ] Add options to commands that can be added: --strategy=something, --language=something, etc.
|
37
|
-
- [ ] Make 100% coverage in simplecov
|
38
|
-
- [ ] Write RSpec module tests
|
39
|
-
- [ ] Divide description.md to task.md + info.yml?
|
40
|
-
- [ ] Refactor features so stubbing (mocking) become more obvious
|
41
|
-
- [ ] Make a bug report "Author's name in an API response is yours name"
|
42
|
-
|
43
27
|
## Contributing
|
44
28
|
|
45
29
|
Bug reports, pull requests and ideas are welcome!
|
data/codewars.gemspec
CHANGED
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
-
spec.add_development_dependency 'webmock', '~> 1.21'
|
24
23
|
spec.add_development_dependency 'aruba', '~> 0.11'
|
25
24
|
spec.add_development_dependency 'pry-byebug'
|
26
25
|
spec.add_development_dependency 'simplecov'
|
27
26
|
spec.add_development_dependency 'rubocop'
|
27
|
+
spec.add_development_dependency 'rspec-mocks'
|
28
|
+
spec.add_development_dependency 'rspec-core'
|
28
29
|
|
29
30
|
spec.add_dependency 'codewars_api', '~> 0.2'
|
30
31
|
spec.add_dependency 'thor', '~> 0.19'
|
data/lib/codewars.rb
CHANGED
data/lib/codewars/attempt.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module Codewars
|
2
2
|
class Attempt < Thor
|
3
|
-
def initialize
|
3
|
+
def initialize(client)
|
4
4
|
api_key = Configuration.option('api_key')
|
5
|
-
|
5
|
+
raise Thor::Error, 'You should set an api-key to use this command' unless api_key
|
6
6
|
|
7
7
|
desc = Description.new
|
8
8
|
project_id = desc.take_value_from_file(/Project ID: (.+)/, 'Project ID')
|
9
9
|
solution_id = desc.take_value_from_file(/Solution ID: (.+)/, 'Solution ID')
|
10
10
|
solution = read_solution_file
|
11
11
|
|
12
|
-
client = CodewarsApi::Client.new(api_key: api_key)
|
13
12
|
attempt = client.attempt_solution(
|
14
13
|
project_id: project_id,
|
15
14
|
solution_id: solution_id,
|
@@ -28,7 +27,7 @@ module Codewars
|
|
28
27
|
file_name = 'solution.*'
|
29
28
|
solution_filename = Dir.glob(file_name).first
|
30
29
|
unless solution_filename
|
31
|
-
|
30
|
+
raise Thor::Error, "The file '#{file_name}' has not been found in the current directory."
|
32
31
|
end
|
33
32
|
File.read File.expand_path(solution_filename)
|
34
33
|
end
|
@@ -45,7 +44,7 @@ module Codewars
|
|
45
44
|
|
46
45
|
def handle_deferred_response(deferred_response)
|
47
46
|
if deferred_response.nil? || !deferred_response.success
|
48
|
-
|
47
|
+
raise Thor::Error, "Can't get a result of tests on the server. Try it again."
|
49
48
|
end
|
50
49
|
|
51
50
|
if deferred_response.valid
|
@@ -53,7 +52,7 @@ module Codewars
|
|
53
52
|
say 'Type to finalize the solution: ' + set_color('codewars finalize', :blue, true)
|
54
53
|
else
|
55
54
|
error 'The solution has not passed tests on the server. Response:'
|
56
|
-
|
55
|
+
raise Thor::Error, set_color(deferred_response.reason, :red)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
data/lib/codewars/cli.rb
CHANGED
@@ -6,20 +6,32 @@ module Codewars
|
|
6
6
|
desc 'train', 'Train a next kata'
|
7
7
|
def train(id_or_slug = nil)
|
8
8
|
if id_or_slug
|
9
|
-
TrainSpecific.new(id_or_slug)
|
9
|
+
TrainSpecific.new(client, id_or_slug)
|
10
10
|
else
|
11
|
-
TrainNext.new
|
11
|
+
TrainNext.new(client)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'attempt', 'Send a solution and get a result'
|
16
16
|
def attempt
|
17
|
-
Attempt.new
|
17
|
+
Attempt.new(client)
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'finalize', 'Finalize the previously attempted solution'
|
21
21
|
def finalize
|
22
|
-
Finalize.new
|
22
|
+
Finalize.new(client)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def client
|
28
|
+
api_key = read_api_key
|
29
|
+
CodewarsApi::Client.new(api_key: api_key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def read_api_key
|
33
|
+
api_key = Configuration.option('api_key')
|
34
|
+
api_key || raise(Thor::Error, 'You should set an api-key to use this command')
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
data/lib/codewars/description.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Codewars
|
2
2
|
class Description < Thor
|
3
|
-
DESCRIPTION_FILE_NAME = 'description.md'
|
3
|
+
DESCRIPTION_FILE_NAME = 'description.md'.freeze
|
4
4
|
|
5
5
|
no_commands do
|
6
6
|
def take_value_from_file(regex_with_group, param_key)
|
7
7
|
@data ||= read_file(DESCRIPTION_FILE_NAME)
|
8
8
|
param = @data.match(regex_with_group)
|
9
9
|
unless param
|
10
|
-
|
10
|
+
raise Thor::Error, "'#{param_key}' has not been found in the 'description.md' file."
|
11
11
|
end
|
12
12
|
param[1]
|
13
13
|
end
|
@@ -29,7 +29,7 @@ module Codewars
|
|
29
29
|
def read_file(file_name)
|
30
30
|
desc_path = File.expand_path(file_name)
|
31
31
|
unless File.exist? desc_path
|
32
|
-
|
32
|
+
raise Thor::Error, "The file '#{file_name}' has not been found in the current directory."
|
33
33
|
end
|
34
34
|
File.read(desc_path)
|
35
35
|
end
|
data/lib/codewars/finalize.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Codewars
|
2
2
|
class Finalize < Thor
|
3
|
-
def initialize
|
4
|
-
api_key = Configuration.option('api_key')
|
5
|
-
fail Thor::Error, 'You should set an api-key to use this command' unless api_key
|
6
|
-
|
3
|
+
def initialize(client)
|
7
4
|
desc = Description.new
|
8
5
|
slug = desc.take_value_from_file(/Slug: (.+)/, 'Slug')
|
9
6
|
project_id = desc.take_value_from_file(/Project ID: (.+)/, 'Project ID')
|
10
7
|
solution_id = desc.take_value_from_file(/Solution ID: (.+)/, 'Solution ID')
|
11
8
|
|
12
|
-
client = CodewarsApi::Client.new(api_key: api_key)
|
13
9
|
result = client.finalize_solution(
|
14
10
|
project_id: project_id,
|
15
11
|
solution_id: solution_id
|
@@ -24,7 +20,7 @@ module Codewars
|
|
24
20
|
say 'Your solution has been finalized.'
|
25
21
|
say "Other solutions can be found here: #{CODEWARS_URL}/kata/#{slug}/solutions/"
|
26
22
|
else
|
27
|
-
|
23
|
+
raise Thor::Error, 'Something went wrong. Try to sumbit the solution again.'
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
data/lib/codewars/runner.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'codewars'
|
2
2
|
|
3
|
-
# to use Webmock we need the Runner class
|
4
|
-
# https://github.com/cucumber/aruba#testing-ruby-cli-programs-without-spawning-a-new-ruby-process
|
5
3
|
module Codewars
|
6
4
|
class Runner
|
7
5
|
def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
|
data/lib/codewars/train_next.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
module Codewars
|
2
2
|
class TrainNext < Thor
|
3
|
-
def initialize
|
4
|
-
message = []
|
5
|
-
api_key = Configuration.option('api_key')
|
6
|
-
message.push 'You should set an api-key to use this command' unless api_key
|
3
|
+
def initialize(client)
|
7
4
|
language = Configuration.option('language')
|
8
|
-
|
9
|
-
fail Thor::Error, message.join("\n") unless message.empty?
|
5
|
+
raise Thor::Error, 'You should set an default language to use this command' unless language
|
10
6
|
|
11
|
-
client = CodewarsApi::Client.new(api_key: api_key)
|
12
7
|
kata = client.train_next_kata(
|
13
8
|
language: language.split(',').first,
|
14
9
|
peek: 'true',
|
@@ -21,7 +16,7 @@ module Codewars
|
|
21
16
|
|
22
17
|
def handle_next_kata(kata)
|
23
18
|
if !kata.success && (kata.reason.eql? 'unauthorized')
|
24
|
-
|
19
|
+
raise Thor::Error, 'Wrong api key'
|
25
20
|
end
|
26
21
|
Description.new.print_kata_desc(kata)
|
27
22
|
end
|
@@ -3,21 +3,15 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module Codewars
|
5
5
|
class TrainSpecific < Thor
|
6
|
-
def initialize(id_or_slug)
|
7
|
-
|
8
|
-
|
9
|
-
message.push 'You should set an api-key to use this command' unless api_key
|
10
|
-
languages = Configuration.option('language')
|
11
|
-
message.push 'You should set an default language to use this command' unless languages
|
12
|
-
fail Thor::Error, message.join("\n") unless message.empty?
|
6
|
+
def initialize(client, id_or_slug)
|
7
|
+
language = Configuration.option('language')
|
8
|
+
raise Thor::Error, 'You should set an default language to use this command' unless language
|
13
9
|
|
10
|
+
language = language.split(',').sample # pick a random language
|
14
11
|
say "Starting the '#{id_or_slug}' kata."
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
kata = client.train_specific_kata(language: language, id_or_slug: id_or_slug) rescue next
|
19
|
-
handle_specific_kata(kata, language)
|
20
|
-
end
|
13
|
+
kata = client.train_specific_kata(language: language, id_or_slug: id_or_slug)
|
14
|
+
handle_specific_kata(kata, language)
|
21
15
|
end
|
22
16
|
|
23
17
|
private
|
@@ -37,7 +31,7 @@ module Codewars
|
|
37
31
|
FileUtils.mkdir_p "#{dir_to_write}/#{language}"
|
38
32
|
file_path = File.expand_path("#{dir_to_write}/#{language}/#{file_name}")
|
39
33
|
relative_path = "./#{slug}/#{language}/#{file_name}"
|
40
|
-
|
34
|
+
raise Thor::Error, "'#{relative_path}' already exists." if File.exist? file_path
|
41
35
|
|
42
36
|
File.write(file_path, content)
|
43
37
|
say "'#{relative_path}' has been created."
|
@@ -49,7 +43,7 @@ module Codewars
|
|
49
43
|
b.local_variable_set(:language, language)
|
50
44
|
b.local_variable_set(:codewars_url, CODEWARS_URL)
|
51
45
|
template_path = File.expand_path("#{File.dirname(__FILE__)}/description_template.erb")
|
52
|
-
ERB.new(File.read
|
46
|
+
ERB.new(File.read(template_path)).result(b)
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
data/lib/codewars/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codewars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Morozov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,35 +39,35 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0.11'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0.11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry-byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,21 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec-mocks
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-core
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|