codewars_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +4 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/Rakefile +13 -0
- data/codewars_api.gemspec +34 -0
- data/lib/codewars_api/attempt_solution.rb +31 -0
- data/lib/codewars_api/client.rb +48 -0
- data/lib/codewars_api/deferred_response.rb +81 -0
- data/lib/codewars_api/finalize_solution.rb +26 -0
- data/lib/codewars_api/kata_info.rb +103 -0
- data/lib/codewars_api/request_helper.rb +20 -0
- data/lib/codewars_api/train_next_kata.rb +77 -0
- data/lib/codewars_api/train_specific_kata.rb +77 -0
- data/lib/codewars_api/user.rb +52 -0
- data/lib/codewars_api/version.rb +3 -0
- data/lib/codewars_api.rb +29 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41fb6958694a1781c07f257672406e621041accf
|
4
|
+
data.tar.gz: 4606f434e3e1ae7a43aae9480493e1a763929f26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7442b9282618717c40cb4439bb63026204381d6feafc74848a1ea35f6b0050fbe51143244e0862763145265f5aeadb23f15d79971250318e952f53a71347da09
|
7
|
+
data.tar.gz: 701cb4057bc2897db42111eae1582be5facad09ce1b46d270627dca82b91d3eb5ed037277011ec27886b1acf5f4adf9ba803c8d80940068d98343936b432e334
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Evgeny Morozov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Codewars API Client
|
2
|
+
|
3
|
+
[Codewars API](http://dev.codewars.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile `gem 'codewars_api'`
|
8
|
+
|
9
|
+
And then execute `$ bundle`
|
10
|
+
|
11
|
+
Or install it yourself as `$ gem install codewars_api`
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
http://rdoc.info/gems/codewars_api_client
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
client = CodewarsApi::Client.new(api_key: your_api_key)
|
19
|
+
|
20
|
+
train_next_kata = client.train_next_kata(language: language)
|
21
|
+
train_next_kata.code_setup
|
22
|
+
# => 'function toInteger(n) {}'
|
23
|
+
|
24
|
+
attempt_solution = client.attempt_solution(
|
25
|
+
project_id: train_next_kata.project_id,
|
26
|
+
solution_id: train_next_kata.solution_id,
|
27
|
+
code: solution_code
|
28
|
+
)
|
29
|
+
|
30
|
+
10.times do
|
31
|
+
deferred_response = client.deferred_response(dmid: attempt_solution.dmid)
|
32
|
+
break if deferred_response.success
|
33
|
+
sleep 1
|
34
|
+
end
|
35
|
+
|
36
|
+
if deferred_response.valid
|
37
|
+
client.finalize_solution(
|
38
|
+
project_id: train_next_kata.project_id,
|
39
|
+
solution_id: train_next_kata.solution_id
|
40
|
+
)
|
41
|
+
else
|
42
|
+
warn deferred_response.reason
|
43
|
+
# => '-e: Value is not what was expected (Test::Error)'
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
#### Gem structure
|
48
|
+
|
49
|
+
API endpoint | Wrapper class (in CodewarsApi::) | Client's method to get an instance
|
50
|
+
------------------------------ | -------------------------------- | --------------------------------
|
51
|
+
GET User | User | #user
|
52
|
+
GET Code Challenge | KataInfo | #kata_info
|
53
|
+
POST Train Next Code Challenge | TrainNextKata | #train_next_kata
|
54
|
+
POST Train Code Challenge | TrainSpecificKata | #train_specifc_kata
|
55
|
+
POST Attempt Solution | AttemptSolution | #attempt_solution
|
56
|
+
POST Finalize Solution | FinalizeSolution | #finalize_solution
|
57
|
+
GET Deferred Response | DeferredResponse | #deferred_response
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
#### Check API methods
|
62
|
+
|
63
|
+
API documentation is a bit out of date. Tests in api_spec.rb make real request and check keys of json in a response against fixture/.json files. If you run these tests often (more then twice per second) your IP can be banned.
|
64
|
+
|
65
|
+
Execute to run the tests
|
66
|
+
|
67
|
+
`CHECK_API=true API_KEY=your_key USERNAME=any_user bundle exec rspec spec/api_spec.rb`
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports, pull requests and ideas are welcome!
|
72
|
+
|
73
|
+
Steps to make a pull request:
|
74
|
+
|
75
|
+
1. Fork it ( https://github.com/Evmorov/codewars_api_client/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Make changes
|
78
|
+
4. Add tests for it
|
79
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
7. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
task test: :spec
|
6
|
+
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
|
10
|
+
require 'yard'
|
11
|
+
YARD::Rake::YardocTask.new
|
12
|
+
|
13
|
+
task default: [:spec, :rubocop]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codewars_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'codewars_api'
|
8
|
+
spec.version = CodewarsApi::VERSION
|
9
|
+
spec.authors = ['Evgeny Morozov']
|
10
|
+
spec.email = ['evmorov@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple Ruby wrapper for the Codewars API '
|
13
|
+
spec.homepage = 'https://github.com/Evmorov/codewars_api_client'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.licenses = ['MIT']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
26
|
+
spec.add_development_dependency 'pry-byebug'
|
27
|
+
spec.add_development_dependency 'simplecov'
|
28
|
+
spec.add_development_dependency 'yard'
|
29
|
+
spec.add_development_dependency 'redcarpet'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
|
32
|
+
spec.add_dependency 'httparty', '~> 0.13.7'
|
33
|
+
spec.add_dependency 'andand', '~> 1.3.3'
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class AttemptSolution
|
3
|
+
def initialize(options)
|
4
|
+
api_key = options.delete!(:api_key)
|
5
|
+
project_id = options.delete!(:project_id)
|
6
|
+
solution_id = options.delete!(:solution_id)
|
7
|
+
|
8
|
+
request_options = {}
|
9
|
+
request_options = RequestHelper.add_api_key(request_options, api_key)
|
10
|
+
request_options = RequestHelper.add_body_options(request_options, options)
|
11
|
+
|
12
|
+
@response = RequestHelper.post(
|
13
|
+
"#{CodewarsApi::API_URL}"\
|
14
|
+
"/code-challenges/projects/#{project_id}/solutions/#{solution_id}/attempt",
|
15
|
+
request_options
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def success
|
20
|
+
@response.to_h['success']
|
21
|
+
end
|
22
|
+
|
23
|
+
def dmid
|
24
|
+
@response.to_h['dmid']
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
@response.to_h
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class Client
|
3
|
+
attr_reader :api_key
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@api_key = options[:api_key] if options[:api_key]
|
7
|
+
end
|
8
|
+
|
9
|
+
def user(username)
|
10
|
+
User.new(username)
|
11
|
+
end
|
12
|
+
|
13
|
+
def kata_info(id_or_slug)
|
14
|
+
KataInfo.new(id_or_slug)
|
15
|
+
end
|
16
|
+
|
17
|
+
def train_next_kata(options)
|
18
|
+
add_api_key(options)
|
19
|
+
TrainNextKata.new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def train_specific_kata(options)
|
23
|
+
add_api_key(options)
|
24
|
+
TrainSpecificKata.new(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def attempt_solution(options)
|
28
|
+
add_api_key(options)
|
29
|
+
AttemptSolution.new(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def finalize_solution(options)
|
33
|
+
add_api_key(options)
|
34
|
+
FinalizeSolution.new(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def deferred_response(options)
|
38
|
+
add_api_key(options)
|
39
|
+
DeferredResponse.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def add_api_key(options)
|
45
|
+
options[:api_key] = @api_key
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class DeferredResponse
|
3
|
+
def initialize(options)
|
4
|
+
api_key = options.delete!(:api_key)
|
5
|
+
dmid = options.delete!(:dmid)
|
6
|
+
|
7
|
+
request_options = {}
|
8
|
+
request_options = RequestHelper.add_api_key(request_options, api_key)
|
9
|
+
|
10
|
+
@response = RequestHelper.get("#{CodewarsApi::API_URL}/deferred/#{dmid}", request_options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def success
|
14
|
+
@response.to_h['success']
|
15
|
+
end
|
16
|
+
|
17
|
+
def dmid
|
18
|
+
@response.to_h['dmid']
|
19
|
+
end
|
20
|
+
|
21
|
+
def solution_id
|
22
|
+
@response.to_h['solution_id']
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid
|
26
|
+
@response.to_h['valid']
|
27
|
+
end
|
28
|
+
|
29
|
+
def server_error
|
30
|
+
@response.to_h['server_error']
|
31
|
+
end
|
32
|
+
|
33
|
+
def passed
|
34
|
+
@response.to_h['passed']
|
35
|
+
end
|
36
|
+
|
37
|
+
def errors
|
38
|
+
@response.to_h['errors']
|
39
|
+
end
|
40
|
+
|
41
|
+
def failed
|
42
|
+
@response.to_h['failed']
|
43
|
+
end
|
44
|
+
|
45
|
+
def timed_out
|
46
|
+
@response.to_h['timed_out']
|
47
|
+
end
|
48
|
+
|
49
|
+
def summary_passed
|
50
|
+
@response.to_h['summary'].andand['passed']
|
51
|
+
end
|
52
|
+
|
53
|
+
def summary_failed
|
54
|
+
@response.to_h['summary'].andand['failed']
|
55
|
+
end
|
56
|
+
|
57
|
+
def summary_errors
|
58
|
+
@response.to_h['summary'].andand['errors']
|
59
|
+
end
|
60
|
+
|
61
|
+
def reason
|
62
|
+
@response.to_h['reason']
|
63
|
+
end
|
64
|
+
|
65
|
+
def output
|
66
|
+
@response.to_h['output']
|
67
|
+
end
|
68
|
+
|
69
|
+
def wall_time
|
70
|
+
@response.to_h['wall_time']
|
71
|
+
end
|
72
|
+
|
73
|
+
def status_code
|
74
|
+
@response.to_h['status_code']
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_h
|
78
|
+
@response.to_h
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class FinalizeSolution
|
3
|
+
def initialize(options)
|
4
|
+
api_key = options.delete!(:api_key)
|
5
|
+
project_id = options.delete!(:project_id)
|
6
|
+
solution_id = options.delete!(:solution_id)
|
7
|
+
|
8
|
+
request_options = {}
|
9
|
+
request_options = RequestHelper.add_api_key(request_options, api_key)
|
10
|
+
|
11
|
+
@response = RequestHelper.post(
|
12
|
+
"#{CodewarsApi::API_URL}"\
|
13
|
+
"/code-challenges/projects/#{project_id}/solutions/#{solution_id}/finalize",
|
14
|
+
request_options
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def success
|
19
|
+
@response.to_h['success']
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
@response.to_h
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class KataInfo
|
3
|
+
def initialize(id)
|
4
|
+
@response = RequestHelper.get("#{CodewarsApi::API_URL}/code-challenges/#{id}")
|
5
|
+
end
|
6
|
+
|
7
|
+
def id
|
8
|
+
@response.to_h['id']
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
@response.to_h['name']
|
13
|
+
end
|
14
|
+
|
15
|
+
def slug
|
16
|
+
@response.to_h['slug']
|
17
|
+
end
|
18
|
+
|
19
|
+
def category
|
20
|
+
@response.to_h['category']
|
21
|
+
end
|
22
|
+
|
23
|
+
def published_at
|
24
|
+
@response.to_h['publishedAt']
|
25
|
+
end
|
26
|
+
|
27
|
+
def approved_at
|
28
|
+
@response.to_h['approvedAt']
|
29
|
+
end
|
30
|
+
|
31
|
+
def languages
|
32
|
+
@response.to_h['languages']
|
33
|
+
end
|
34
|
+
|
35
|
+
def url
|
36
|
+
@response.to_h['url']
|
37
|
+
end
|
38
|
+
|
39
|
+
def rank
|
40
|
+
@response.to_h['rank']
|
41
|
+
end
|
42
|
+
|
43
|
+
def created_at
|
44
|
+
@response.to_h['createdAt']
|
45
|
+
end
|
46
|
+
|
47
|
+
def creater_username
|
48
|
+
@response.to_h['createdBy'].andand['username']
|
49
|
+
end
|
50
|
+
|
51
|
+
def creater_url
|
52
|
+
@response.to_h['createdBy'].andand['url']
|
53
|
+
end
|
54
|
+
|
55
|
+
def approver_username
|
56
|
+
@response.to_h['approvedBy'].andand['username']
|
57
|
+
end
|
58
|
+
|
59
|
+
def approver_url
|
60
|
+
@response.to_h['approvedBy'].andand['url']
|
61
|
+
end
|
62
|
+
|
63
|
+
def description
|
64
|
+
@response.to_h['description']
|
65
|
+
end
|
66
|
+
|
67
|
+
def total_attempts
|
68
|
+
@response.to_h['totalAttempts']
|
69
|
+
end
|
70
|
+
|
71
|
+
def total_completed
|
72
|
+
@response.to_h['totalCompleted']
|
73
|
+
end
|
74
|
+
|
75
|
+
def total_stars
|
76
|
+
@response.to_h['totalStars']
|
77
|
+
end
|
78
|
+
|
79
|
+
def vote_score
|
80
|
+
@response.to_h['voteScore']
|
81
|
+
end
|
82
|
+
|
83
|
+
def tags
|
84
|
+
@response.to_h['tags']
|
85
|
+
end
|
86
|
+
|
87
|
+
def contributors_wanted
|
88
|
+
@response.to_h['contributorsWanted']
|
89
|
+
end
|
90
|
+
|
91
|
+
def unresolved_issues
|
92
|
+
@response.to_h['unresolved'].andand['issues']
|
93
|
+
end
|
94
|
+
|
95
|
+
def unresolved_suggestions
|
96
|
+
@response.to_h['unresolved'].andand['suggestions']
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_h
|
100
|
+
@response.to_h
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module CodewarsApi
|
4
|
+
module RequestHelper
|
5
|
+
include HTTParty
|
6
|
+
base_uri CodewarsApi::BASE_URL
|
7
|
+
|
8
|
+
def self.add_api_key(request_options, api_key)
|
9
|
+
request_options = request_options.dup
|
10
|
+
request_options[:headers] = { 'Authorization' => api_key }
|
11
|
+
request_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.add_body_options(request_options, body_options)
|
15
|
+
request_options = request_options.dup
|
16
|
+
request_options[:body] = body_options
|
17
|
+
request_options
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class TrainNextKata
|
3
|
+
def initialize(options)
|
4
|
+
api_key = options.delete!(:api_key)
|
5
|
+
language = options.delete!(:language)
|
6
|
+
|
7
|
+
request_options = {}
|
8
|
+
request_options = RequestHelper.add_api_key(request_options, api_key)
|
9
|
+
request_options = RequestHelper.add_body_options(request_options, options)
|
10
|
+
|
11
|
+
@response = RequestHelper.post(
|
12
|
+
"#{CodewarsApi::API_URL}/code-challenges/#{language}/train",
|
13
|
+
request_options
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def success
|
18
|
+
@response.to_h['success']
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
@response.to_h['name']
|
23
|
+
end
|
24
|
+
|
25
|
+
def slug
|
26
|
+
@response.to_h['slug']
|
27
|
+
end
|
28
|
+
|
29
|
+
def href
|
30
|
+
@response.to_h['href']
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
@response.to_h['description']
|
35
|
+
end
|
36
|
+
|
37
|
+
def author
|
38
|
+
@response.to_h['author']
|
39
|
+
end
|
40
|
+
|
41
|
+
def rank
|
42
|
+
@response.to_h['rank']
|
43
|
+
end
|
44
|
+
|
45
|
+
def average_completion
|
46
|
+
@response.to_h['averageCompletion']
|
47
|
+
end
|
48
|
+
|
49
|
+
def tags
|
50
|
+
@response.to_h['tags']
|
51
|
+
end
|
52
|
+
|
53
|
+
def project_id
|
54
|
+
@response.to_h['session'].andand['projectId']
|
55
|
+
end
|
56
|
+
|
57
|
+
def solution_id
|
58
|
+
@response.to_h['session'].andand['solutionId']
|
59
|
+
end
|
60
|
+
|
61
|
+
def code_setup
|
62
|
+
@response.to_h['session'].andand['setup']
|
63
|
+
end
|
64
|
+
|
65
|
+
def tests_setup
|
66
|
+
@response.to_h['session'].andand['exampleFixture']
|
67
|
+
end
|
68
|
+
|
69
|
+
def code
|
70
|
+
@response.to_h['session'].andand['code']
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_h
|
74
|
+
@response.to_h
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class TrainSpecificKata
|
3
|
+
def initialize(options)
|
4
|
+
api_key = options.delete!(:api_key)
|
5
|
+
language = options.delete!(:language)
|
6
|
+
id_or_slug = options.delete!(:id_or_slug)
|
7
|
+
|
8
|
+
request_options = {}
|
9
|
+
request_options = RequestHelper.add_api_key(request_options, api_key)
|
10
|
+
|
11
|
+
@response = RequestHelper.post(
|
12
|
+
"#{CodewarsApi::API_URL}/code-challenges/#{id_or_slug}/#{language}/train",
|
13
|
+
request_options
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def success
|
18
|
+
@response.to_h['success']
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
@response.to_h['name']
|
23
|
+
end
|
24
|
+
|
25
|
+
def slug
|
26
|
+
@response.to_h['slug']
|
27
|
+
end
|
28
|
+
|
29
|
+
def description
|
30
|
+
@response.to_h['description']
|
31
|
+
end
|
32
|
+
|
33
|
+
def author
|
34
|
+
@response.to_h['author']
|
35
|
+
end
|
36
|
+
|
37
|
+
def rank
|
38
|
+
@response.to_h['rank']
|
39
|
+
end
|
40
|
+
|
41
|
+
def average_completion
|
42
|
+
@response.to_h['averageCompletion']
|
43
|
+
end
|
44
|
+
|
45
|
+
def tags
|
46
|
+
@response.to_h['tags']
|
47
|
+
end
|
48
|
+
|
49
|
+
def project_id
|
50
|
+
@response.to_h['session'].andand['projectId']
|
51
|
+
end
|
52
|
+
|
53
|
+
def solution_id
|
54
|
+
@response.to_h['session'].andand['solutionId']
|
55
|
+
end
|
56
|
+
|
57
|
+
def code_setup
|
58
|
+
@response.to_h['session'].andand['setup']
|
59
|
+
end
|
60
|
+
|
61
|
+
def tests_setup
|
62
|
+
@response.to_h['session'].andand['exampleFixture']
|
63
|
+
end
|
64
|
+
|
65
|
+
def code
|
66
|
+
@response.to_h['session'].andand['code']
|
67
|
+
end
|
68
|
+
|
69
|
+
def recently_attempted
|
70
|
+
@response.to_h['session'].andand['recentlyAttempted']
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_h
|
74
|
+
@response.to_h
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module CodewarsApi
|
2
|
+
class User
|
3
|
+
def initialize(username)
|
4
|
+
fail 'Username is not set' unless username
|
5
|
+
@response = RequestHelper.get("#{CodewarsApi::API_URL}/users/#{username}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def username
|
9
|
+
@response.to_h['username']
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
@response.to_h['name']
|
14
|
+
end
|
15
|
+
|
16
|
+
def honor
|
17
|
+
@response.to_h['honor']
|
18
|
+
end
|
19
|
+
|
20
|
+
def clan
|
21
|
+
@response.to_h['clan']
|
22
|
+
end
|
23
|
+
|
24
|
+
def leaderboard_position
|
25
|
+
@response.to_h['leaderboardPosition']
|
26
|
+
end
|
27
|
+
|
28
|
+
def skills
|
29
|
+
@response.to_h['skills']
|
30
|
+
end
|
31
|
+
|
32
|
+
def rank_overall
|
33
|
+
@response.to_h['ranks'].andand['overall']
|
34
|
+
end
|
35
|
+
|
36
|
+
def rank_languages
|
37
|
+
@response.to_h['ranks'].andand['languages']
|
38
|
+
end
|
39
|
+
|
40
|
+
def katas_authored
|
41
|
+
@response.to_h['codeChallenges'].andand['totalAuthored']
|
42
|
+
end
|
43
|
+
|
44
|
+
def katas_completed
|
45
|
+
@response.to_h['codeChallenges'].andand['totalCompleted']
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_h
|
49
|
+
@response.to_h
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/codewars_api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require 'pry'
|
3
|
+
rescue LoadError
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
module CodewarsApi
|
8
|
+
BASE_URL = 'https://www.codewars.com'
|
9
|
+
API_URL = '/api/v1'
|
10
|
+
end
|
11
|
+
|
12
|
+
class Hash
|
13
|
+
def delete!(key)
|
14
|
+
fetch(key)
|
15
|
+
delete(key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'andand'
|
20
|
+
require 'codewars_api/request_helper'
|
21
|
+
require 'codewars_api/version'
|
22
|
+
require 'codewars_api/client'
|
23
|
+
require 'codewars_api/user'
|
24
|
+
require 'codewars_api/kata_info'
|
25
|
+
require 'codewars_api/train_next_kata'
|
26
|
+
require 'codewars_api/train_specific_kata'
|
27
|
+
require 'codewars_api/attempt_solution'
|
28
|
+
require 'codewars_api/finalize_solution'
|
29
|
+
require 'codewars_api/deferred_response'
|
metadata
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codewars_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evgeny Morozov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.21.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.21.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
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: redcarpet
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: httparty
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.13.7
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.13.7
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: andand
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.3.3
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.3.3
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- evmorov@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- ".rubocop.yml"
|
177
|
+
- ".travis.yml"
|
178
|
+
- ".yardopts"
|
179
|
+
- Gemfile
|
180
|
+
- LICENSE
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- codewars_api.gemspec
|
184
|
+
- lib/codewars_api.rb
|
185
|
+
- lib/codewars_api/attempt_solution.rb
|
186
|
+
- lib/codewars_api/client.rb
|
187
|
+
- lib/codewars_api/deferred_response.rb
|
188
|
+
- lib/codewars_api/finalize_solution.rb
|
189
|
+
- lib/codewars_api/kata_info.rb
|
190
|
+
- lib/codewars_api/request_helper.rb
|
191
|
+
- lib/codewars_api/train_next_kata.rb
|
192
|
+
- lib/codewars_api/train_specific_kata.rb
|
193
|
+
- lib/codewars_api/user.rb
|
194
|
+
- lib/codewars_api/version.rb
|
195
|
+
homepage: https://github.com/Evmorov/codewars_api_client
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
metadata: {}
|
199
|
+
post_install_message:
|
200
|
+
rdoc_options: []
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 2.4.5
|
216
|
+
signing_key:
|
217
|
+
specification_version: 4
|
218
|
+
summary: Simple Ruby wrapper for the Codewars API
|
219
|
+
test_files: []
|
220
|
+
has_rdoc:
|