exercism 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/bin/exercism +4 -1
- data/lib/cli.rb +25 -18
- data/lib/exercism/api.rb +12 -14
- data/lib/exercism/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Client gem for the warmup-exercise app exercism.io.
|
|
4
4
|
|
5
5
|
[![Code Climate](https://codeclimate.com/github/kytrinyx/exercism.png)](https://codeclimate.com/github/kytrinyx/exercism)
|
6
6
|
[![Build Status](https://travis-ci.org/kytrinyx/exercism.png?branch=master)](https://travis-ci.org/kytrinyx/exercism)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/exercism.png)](https://rubygems.org/gems/exercism)
|
7
8
|
|
8
9
|
## Install
|
9
10
|
|
data/bin/exercism
CHANGED
@@ -7,6 +7,9 @@ require 'cli'
|
|
7
7
|
begin
|
8
8
|
Exercism::CLI.start
|
9
9
|
rescue Exception => e
|
10
|
-
|
10
|
+
puts
|
11
|
+
puts "ERROR: Something went wrong. Exiting."
|
12
|
+
puts e.message
|
13
|
+
puts
|
11
14
|
raise e if ENV['EXERCISM_ENV'] =~ /test|development/
|
12
15
|
end
|
data/lib/cli.rb
CHANGED
@@ -17,15 +17,8 @@ class Exercism
|
|
17
17
|
def fetch
|
18
18
|
require 'exercism'
|
19
19
|
|
20
|
-
api = Exercism::Api.new(options[:host], Exercism.user, Exercism.project_dir)
|
21
20
|
assignments = api.fetch
|
22
|
-
|
23
|
-
puts "No assignments fetched."
|
24
|
-
else
|
25
|
-
assignments.each do |assignment|
|
26
|
-
puts "Fetched #{File.join(assignment.assignment_dir)}"
|
27
|
-
end
|
28
|
-
end
|
21
|
+
report(assignments)
|
29
22
|
end
|
30
23
|
|
31
24
|
desc "peek", "Fetch upcoming assignment from exercism.io"
|
@@ -33,15 +26,8 @@ class Exercism
|
|
33
26
|
def peek
|
34
27
|
require 'exercism'
|
35
28
|
|
36
|
-
api = Exercism::Api.new(options[:host], Exercism.user, Exercism.project_dir)
|
37
29
|
assignments = api.peek
|
38
|
-
|
39
|
-
puts "No assignments fetched."
|
40
|
-
else
|
41
|
-
assignments.each do |assignment|
|
42
|
-
puts "Fetched #{File.join(assignment.assignment_dir)}"
|
43
|
-
end
|
44
|
-
end
|
30
|
+
report(assignments)
|
45
31
|
end
|
46
32
|
|
47
33
|
desc "submit FILE", "Submit code to exercism.io on your current assignment"
|
@@ -51,9 +37,10 @@ class Exercism
|
|
51
37
|
|
52
38
|
path = File.join(FileUtils.pwd, file)
|
53
39
|
begin
|
54
|
-
Exercism::Api.new(options[:host], Exercism.user).submit(file)
|
40
|
+
response = Exercism::Api.new(options[:host], Exercism.user).submit(file)
|
55
41
|
puts "Your assignment has been submitted."
|
56
|
-
|
42
|
+
url = submission_url(response.body, options[:host])
|
43
|
+
puts "For feedback on your submission visit #{url}."
|
57
44
|
rescue Exception => e
|
58
45
|
puts "There was an issue with your submission."
|
59
46
|
puts e.message
|
@@ -93,5 +80,25 @@ class Exercism
|
|
93
80
|
puts "You are not logged in."
|
94
81
|
end
|
95
82
|
|
83
|
+
private
|
84
|
+
def api(host = options[:host])
|
85
|
+
Exercism::Api.new(host, Exercism.user, Exercism.project_dir)
|
86
|
+
end
|
87
|
+
|
88
|
+
def submission_url(response_body, host)
|
89
|
+
body = JSON.parse(response_body)
|
90
|
+
"#{host}/user/#{body['language']}/#{body['exercise']}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def report(assignments)
|
94
|
+
if assignments.empty?
|
95
|
+
puts "No assignments fetched."
|
96
|
+
else
|
97
|
+
assignments.each do |assignment|
|
98
|
+
puts "Fetched #{File.join(assignment.assignment_dir)}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
96
103
|
end
|
97
104
|
end
|
data/lib/exercism/api.rb
CHANGED
@@ -11,25 +11,16 @@ class Exercism
|
|
11
11
|
def conn
|
12
12
|
conn = Faraday.new(:url => url) do |c|
|
13
13
|
c.use Faraday::Adapter::NetHttp
|
14
|
+
c.headers['User-Agent'] = user_agent
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
def fetch
|
18
|
-
|
19
|
-
req.url endpoint('current')
|
20
|
-
req.headers['User-Agent'] = user_agent
|
21
|
-
req.params['key'] = user.key
|
22
|
-
end
|
23
|
-
save response.body
|
19
|
+
get_and_save('current')
|
24
20
|
end
|
25
21
|
|
26
22
|
def peek
|
27
|
-
|
28
|
-
req.url endpoint('next')
|
29
|
-
req.headers['User-Agent'] = user_agent
|
30
|
-
req.params['key'] = user.key
|
31
|
-
end
|
32
|
-
save response.body
|
23
|
+
get_and_save('next')
|
33
24
|
end
|
34
25
|
|
35
26
|
def submit(filename)
|
@@ -39,7 +30,6 @@ class Exercism
|
|
39
30
|
req.url endpoint
|
40
31
|
req.headers['Accept'] = 'application/json'
|
41
32
|
req.headers['Content-Type'] = 'application/json'
|
42
|
-
req.headers['User-Agent'] = user_agent
|
43
33
|
req.body = {code: contents, key: user.key, path: path}.to_json
|
44
34
|
end
|
45
35
|
response
|
@@ -47,8 +37,16 @@ class Exercism
|
|
47
37
|
|
48
38
|
private
|
49
39
|
|
40
|
+
def get_and_save(action)
|
41
|
+
response = conn.get do |req|
|
42
|
+
req.url endpoint(action)
|
43
|
+
req.params['key'] = user.key
|
44
|
+
end
|
45
|
+
save response.body
|
46
|
+
end
|
47
|
+
|
50
48
|
def user_agent
|
51
|
-
"exercism
|
49
|
+
"github.com/kytrinyx/exercism CLI v#{Exercism::VERSION}"
|
52
50
|
end
|
53
51
|
|
54
52
|
def endpoint(action = nil)
|
data/lib/exercism/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exercism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|