exercism 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,6 +25,14 @@ This retrieves the README and test suite for your current assignment.
25
25
 
26
26
  This submits `example.rb` on your current assignment.
27
27
 
28
+ $ exercism stash save example.rb
29
+
30
+ This saves 'example.rb' to exercism.io as an unfinished "stash" file that can be retrieved later. Helpful for use on multiple computers: stash the file you're working on at computer 1, then retrieve it with the loot command on computer 2.
31
+
32
+ $ exercism stash apply example.rb
33
+
34
+ This retrieves the most recent stash file, if one exists, and saves it to the current directory.
35
+
28
36
  $ export EXERCISM_ENV=development
29
37
 
30
38
  Reveals stack traces on errors.
data/lib/cli.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'rubygems' if RUBY_VERSION == '1.8.7'
2
2
  require 'thor'
3
+ require 'exercism/cli/stash.rb'
3
4
 
4
5
  class Exercism
6
+
5
7
  class CLI < Thor
6
8
 
7
9
  desc "version", "Output current version of gem"
@@ -120,6 +122,16 @@ class Exercism
120
122
  puts "You are not logged in."
121
123
  end
122
124
 
125
+ desc "stash [SUBCOMMAND]", "Stash or apply code that is in-progress"
126
+ subcommand "stash", Stash
127
+
128
+ desc "dir", "Display the project path"
129
+ def dir
130
+ require 'exercism'
131
+
132
+ puts Exercism.config.project_dir
133
+ end
134
+
123
135
  private
124
136
 
125
137
  def username
@@ -155,4 +167,6 @@ class Exercism
155
167
  end
156
168
  end
157
169
  end
170
+
171
+
158
172
  end
@@ -18,6 +18,7 @@ require 'exercism/user'
18
18
  require 'exercism/assignment'
19
19
  require 'exercism/submission'
20
20
  require 'exercism/api'
21
+ require 'exercism/stash'
21
22
 
22
23
  class Exercism
23
24
 
@@ -46,8 +46,41 @@ class Exercism
46
46
  })
47
47
  end
48
48
 
49
+ def save_stash(action, filename)
50
+ path = File.join(filename)
51
+ contents = File.read path
52
+ response = conn.post do |req|
53
+ req.url endpoint(action)
54
+ req.headers['Accept'] = 'application/json'
55
+ req.headers['Content-Type'] = 'application/json'
56
+ req.body = {:code => contents, :key => user.key, :filename => path}.to_json
57
+ end
58
+ response
59
+ end
60
+
61
+ def apply_stash(action, filename)
62
+ get_stash(action, filename)
63
+ end
64
+
65
+ def list_stash(action)
66
+ response = conn.get do |req|
67
+ req.url endpoint(action)
68
+ req.params['key'] = user.key
69
+ end
70
+ JSON.parse(response.body)
71
+ end
72
+
49
73
  private
50
74
 
75
+ def get_stash(action, filename)
76
+ response = conn.get do |req|
77
+ req.url endpoint(action)
78
+ req.params['key'] = user.key
79
+ req.params['filename'] = filename
80
+ end
81
+ Stash.new(JSON.parse(response.body))
82
+ end
83
+
51
84
  def get_and_save(action)
52
85
  response = conn.get do |req|
53
86
  req.url endpoint(action)
@@ -0,0 +1,53 @@
1
+ class Stash < Thor
2
+
3
+ desc "save FILE", "Stash code from a file in-progress"
4
+ method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
5
+ def save(file)
6
+ require 'exercism'
7
+
8
+ begin
9
+ puts file
10
+ puts File.read file
11
+ response = Exercism::Api.new(options[:host], Exercism.user).save_stash('user/assignments/stash', file)
12
+ say "Stash file has been saved"
13
+ rescue Exception => e
14
+ puts "Error submitting stash"
15
+ puts e.message
16
+ end
17
+ end
18
+
19
+ desc "apply FILE", "Retrieve stashed file from exercism.io"
20
+ method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
21
+ def apply(file)
22
+ require 'exercism'
23
+
24
+ begin
25
+ stash = Exercism::Api.new(options[:host], Exercism.user).apply_stash('user/assignments/stash', file)
26
+ if File.exists?(stash.filename)
27
+ say "File: " + stash.filename + " already exists"
28
+ if no?("Overwrite it? [y/n]")
29
+ return
30
+ end
31
+ end
32
+ stash.save
33
+ puts "Stash file downloaded successfully: " + File.join(FileUtils.pwd, stash.filename)
34
+ rescue Exception => e
35
+ puts "Error: No stash file was found."
36
+ end
37
+ end
38
+
39
+ desc "list", "List stashed files"
40
+ method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
41
+ def list
42
+ require 'exercism'
43
+ begin
44
+ stashed = Exercism::Api.new(options[:host], Exercism.user).list_stash('user/assignments/stash/list')
45
+ stashed.each do |name|
46
+ puts name
47
+ end
48
+ rescue Exception => e
49
+ puts "Error: unable to retrieve stashed file list"
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,28 @@
1
+ class Exercism
2
+ class Stash
3
+
4
+ attr_reader :code, :filename
5
+
6
+ def self.save(body)
7
+ new(body).save
8
+ end
9
+
10
+ def initialize(body)
11
+ @code = body['code']
12
+ @filename = body['filename']
13
+ end
14
+
15
+ def save
16
+ File.open path, 'w' do |f|
17
+ f.write code
18
+ end
19
+ self
20
+ end
21
+
22
+ private
23
+
24
+ def path
25
+ File.join(FileUtils.pwd, filename)
26
+ end
27
+ end
28
+ end
@@ -28,6 +28,7 @@ class Exercism
28
28
  :clojure => '_test.clj',
29
29
  :python => '_test.py',
30
30
  :go => '_test.go',
31
+ :haskell => '_test.hs',
31
32
  }
32
33
  end
33
34
 
@@ -1,3 +1,3 @@
1
1
  class Exercism
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
@@ -75,4 +75,47 @@ class ApiTest < Minitest::Test
75
75
  end
76
76
  end
77
77
 
78
+ def test_save_stash_to_api
79
+ submission = File.join(FileUtils.pwd, 'bob.rb')
80
+ File.open(submission, 'w') do |f|
81
+ f.write "puts 'hello world'"
82
+ end
83
+
84
+ Exercism.stub(:home, home) do
85
+ VCR.use_cassette('alice-submits-stash') do
86
+ response = Exercism::Api.new('http://localhost:4567', Exercism.user).save_stash('user/assignments/stash', submission)
87
+ assert_equal 201, response.status
88
+ end
89
+ end
90
+ end
91
+
92
+ def test_apply_stash_from_api
93
+ submission = File.join(FileUtils.pwd, 'bob.rb')
94
+ File.open(submission, 'w') do |f|
95
+ f.write "puts 'hello world'"
96
+ end
97
+ Exercism.stub(:home, home) do
98
+ VCR.use_cassette('alice-gets-stash') do
99
+ Exercism::Api.new('http://localhost:4567', Exercism.user).save_stash('user/assignments/stash', submission)
100
+ response = Exercism::Api.new('http://localhost:4567', Exercism.user).apply_stash('user/assignments/stash', 'bob.rb')
101
+ assert response
102
+ end
103
+ end
104
+ end
105
+
106
+ def test_get_stash_list
107
+ submission = File.join(FileUtils.pwd, 'bob.rb')
108
+ File.open(submission, 'w') do |f|
109
+ f.write "puts 'hello world'"
110
+ end
111
+ Exercism.stub(:home, home) do
112
+ VCR.use_cassette('alice-gets-stash-list') do
113
+ Exercism::Api.new('http://localhost:4567', Exercism.user).save_stash('user/assignments/stash', submission)
114
+ response = Exercism::Api.new('http://localhost:4567', Exercism.user).list_stash('user/assignments/stash/list')
115
+ assert response
116
+ end
117
+ end
118
+ end
119
+
120
+
78
121
  end
@@ -0,0 +1,75 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:4567/api/v1/user/assignments/stash
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"code":"puts ''hello world''","key":"634abfb095ed621e1c793c9875fcd9fda455ea90","filename":"/vagrant/exercism/old/bob.rb"}'
9
+ headers:
10
+ user-agent:
11
+ - github.com/kytrinyx/exercism CLI v0.0.21
12
+ accept:
13
+ - application/json
14
+ content-type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ content-type:
22
+ - application/json;charset=utf-8
23
+ content-length:
24
+ - '49'
25
+ x-content-type-options:
26
+ - nosniff
27
+ set-cookie:
28
+ - rack.session=BAh7CEkiD3Nlc3Npb25faWQGOgZFRiJFMmQ4YjRlNmUxNmMxODkyMTQ0M2Y0%0AOTA3NTkwYWJkZGFkZWI0NGE0NzA1MDA0OWE2NmQ4ZTM5N2YzMmRmNzE1Ykki%0ACWNzcmYGOwBGIkVjMmM0M2ZlNTFjNjRiZTMxYmJjNGIyYzRhNmY4OWQ0OTEw%0AYmQzODJiN2FlNzJhOTUyODc0OGI4MGQ1ZTUzOWI4SSINdHJhY2tpbmcGOwBG%0AewhJIhRIVFRQX1VTRVJfQUdFTlQGOwBGIi1jODFhNWRiMmQwMDlhYmFlNTJk%0AMmRiM2Q3Y2ZlODQ1ZDg0NTY3YzZhSSIZSFRUUF9BQ0NFUFRfRU5DT0RJTkcG%0AOwBGIi1kYTM5YTNlZTVlNmI0YjBkMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0ASSIZSFRUUF9BQ0NFUFRfTEFOR1VBR0UGOwBGIi1kYTM5YTNlZTVlNmI0YjBk%0AMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0A--da7f28f9a4756d813c05aebea82e8ba690ac9c41;
29
+ path=/; HttpOnly
30
+ connection:
31
+ - close
32
+ server:
33
+ - thin 1.5.1 codename Straight Razor
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"code":"puts ''hello world''","filename":"bob.rb"}'
37
+ http_version: '1.1'
38
+ recorded_at: Tue, 03 Sep 2013 19:48:18 GMT
39
+ - request:
40
+ method: get
41
+ uri: http://localhost:4567/api/v1/user/assignments/stash/list?key=634abfb095ed621e1c793c9875fcd9fda455ea90
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ''
45
+ headers:
46
+ user-agent:
47
+ - github.com/kytrinyx/exercism CLI v0.0.21
48
+ accept-encoding:
49
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
50
+ accept:
51
+ - ! '*/*'
52
+ response:
53
+ status:
54
+ code: 200
55
+ message: OK
56
+ headers:
57
+ content-type:
58
+ - application/json;charset=utf-8
59
+ content-length:
60
+ - '19'
61
+ x-content-type-options:
62
+ - nosniff
63
+ set-cookie:
64
+ - rack.session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRiJFMTY2YzVlNTE2NDgwNmFkYWFjNDlh%0ANzg5MTY1ZTA5Zjk4NDgyYjhiODc5Y2NjNmQzNWVkZGEwZThmOWRkMDZiY0ki%0ADXRyYWNraW5nBjsARnsISSIUSFRUUF9VU0VSX0FHRU5UBjsARiItYzgxYTVk%0AYjJkMDA5YWJhZTUyZDJkYjNkN2NmZTg0NWQ4NDU2N2M2YUkiGUhUVFBfQUND%0ARVBUX0VOQ09ESU5HBjsARiItZGRkMDk4OTE3NGYxOWE1YjE4NzkxMjEzY2M0%0AMGM1YTYwOWQyNTQ2Y0kiGUhUVFBfQUNDRVBUX0xBTkdVQUdFBjsARiItZGEz%0AOWEzZWU1ZTZiNGIwZDMyNTViZmVmOTU2MDE4OTBhZmQ4MDcwOQ%3D%3D%0A--88e3a688ea8b8538dd22926f606ddfec4aa86ada;
65
+ path=/; HttpOnly
66
+ connection:
67
+ - close
68
+ server:
69
+ - thin 1.5.1 codename Straight Razor
70
+ body:
71
+ encoding: US-ASCII
72
+ string: ! '{"list":["bob.rb"]}'
73
+ http_version: '1.1'
74
+ recorded_at: Tue, 03 Sep 2013 19:48:18 GMT
75
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,75 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:4567/api/v1/user/assignments/stash
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"code":"puts ''hello world''","key":"634abfb095ed621e1c793c9875fcd9fda455ea90","filename":"/vagrant/exercism/old/bob.rb"}'
9
+ headers:
10
+ User-Agent:
11
+ - github.com/kytrinyx/exercism CLI v0.0.26
12
+ Accept:
13
+ - application/json
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Content-Type:
22
+ - application/json;charset=utf-8
23
+ Content-Length:
24
+ - '49'
25
+ X-Content-Type-Options:
26
+ - nosniff
27
+ Set-Cookie:
28
+ - rack.session=BAh7CEkiD3Nlc3Npb25faWQGOgZFRiJFYmE5NmY5Zjk0MTVhMWY4ODNmNDEw%0AYjA4NTllODRlZTBkYzhlNjAwOWZlZjg1NTcyMWViNmQ3ODQxNGRmY2MwNEki%0ACWNzcmYGOwBGIkVhMzhkZTdkNzRhOGUyZWVlOWRlYmEzODRhOWQ0ZDkyNjdm%0ANmMxZmRkMzA2NzZmODAxYzIxYTQzYjU5MGU1NzA5SSINdHJhY2tpbmcGOwBG%0AewhJIhRIVFRQX1VTRVJfQUdFTlQGOwBGIi1mNjFlZGRjODY2MWFmNTkzYmVj%0AM2VlNjQzMjJmODFlMGQ0MGYwN2UySSIZSFRUUF9BQ0NFUFRfRU5DT0RJTkcG%0AOwBGIi1kYTM5YTNlZTVlNmI0YjBkMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0ASSIZSFRUUF9BQ0NFUFRfTEFOR1VBR0UGOwBGIi1kYTM5YTNlZTVlNmI0YjBk%0AMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0A--f0aff46f488f06e9b29743514ec4bcd46c76baf2;
29
+ path=/; HttpOnly
30
+ Connection:
31
+ - keep-alive
32
+ Server:
33
+ - thin 1.5.1 codename Straight Razor
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"code":"puts ''hello world''","filename":"bob.rb"}'
37
+ http_version:
38
+ recorded_at: Tue, 03 Sep 2013 21:17:32 GMT
39
+ - request:
40
+ method: get
41
+ uri: http://localhost:4567/api/v1/user/assignments/stash?filename=bob.rb&key=634abfb095ed621e1c793c9875fcd9fda455ea90
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ''
45
+ headers:
46
+ User-Agent:
47
+ - github.com/kytrinyx/exercism CLI v0.0.26
48
+ Accept-Encoding:
49
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
50
+ Accept:
51
+ - ! '*/*'
52
+ response:
53
+ status:
54
+ code: 200
55
+ message: OK
56
+ headers:
57
+ Content-Type:
58
+ - application/json;charset=utf-8
59
+ Content-Length:
60
+ - '49'
61
+ X-Content-Type-Options:
62
+ - nosniff
63
+ Set-Cookie:
64
+ - rack.session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRiJFYjcyNGFhNjQ5MzFkOTM5YzlhY2Mx%0AYjk5YjZmY2MwZWFlMzFiMGIyYjA2YzMwNWRmZDUzN2UxYzU2MmYwMzVjNkki%0ADXRyYWNraW5nBjsARnsISSIUSFRUUF9VU0VSX0FHRU5UBjsARiItZjYxZWRk%0AYzg2NjFhZjU5M2JlYzNlZTY0MzIyZjgxZTBkNDBmMDdlMkkiGUhUVFBfQUND%0ARVBUX0VOQ09ESU5HBjsARiItZGRkMDk4OTE3NGYxOWE1YjE4NzkxMjEzY2M0%0AMGM1YTYwOWQyNTQ2Y0kiGUhUVFBfQUNDRVBUX0xBTkdVQUdFBjsARiItZGEz%0AOWEzZWU1ZTZiNGIwZDMyNTViZmVmOTU2MDE4OTBhZmQ4MDcwOQ%3D%3D%0A--db35df569572aadc232dff027dc7d69836926953;
65
+ path=/; HttpOnly
66
+ Connection:
67
+ - keep-alive
68
+ Server:
69
+ - thin 1.5.1 codename Straight Razor
70
+ body:
71
+ encoding: US-ASCII
72
+ string: ! '{"code":"puts ''hello world''","filename":"bob.rb"}'
73
+ http_version:
74
+ recorded_at: Tue, 03 Sep 2013 21:17:32 GMT
75
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:4567/api/v1/user/assignments/stash
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"code":"puts ''hello world''","key":"634abfb095ed621e1c793c9875fcd9fda455ea90","filename":"/vagrant/exercism/old/bob.rb"}'
9
+ headers:
10
+ user-agent:
11
+ - github.com/kytrinyx/exercism CLI v0.0.21
12
+ accept:
13
+ - application/json
14
+ content-type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ content-type:
22
+ - application/json;charset=utf-8
23
+ content-length:
24
+ - '49'
25
+ x-content-type-options:
26
+ - nosniff
27
+ set-cookie:
28
+ - rack.session=BAh7CEkiD3Nlc3Npb25faWQGOgZFRiJFMTBiNjFjNTgxZjQ5MTYzYzc5YTNh%0AOTljYzI4ZTVkNTAzODllMjhjNjI1NTlmNjcyYWUyNTdkZjA2OWIxZDNjZEki%0ACWNzcmYGOwBGIkViN2E1MjkzZjIyYTg0ZGFmZDU5NTE0YTA1MWIxZjQzZjA0%0AZTc3ZmNmNWEyMWRhMTg1YTZjMWU2ODgxNzg3Nzc0SSINdHJhY2tpbmcGOwBG%0AewhJIhRIVFRQX1VTRVJfQUdFTlQGOwBGIi1jODFhNWRiMmQwMDlhYmFlNTJk%0AMmRiM2Q3Y2ZlODQ1ZDg0NTY3YzZhSSIZSFRUUF9BQ0NFUFRfRU5DT0RJTkcG%0AOwBGIi1kYTM5YTNlZTVlNmI0YjBkMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0ASSIZSFRUUF9BQ0NFUFRfTEFOR1VBR0UGOwBGIi1kYTM5YTNlZTVlNmI0YjBk%0AMzI1NWJmZWY5NTYwMTg5MGFmZDgwNzA5%0A--55534de505b2b27c1026cea95de54209be91452a;
29
+ path=/; HttpOnly
30
+ connection:
31
+ - close
32
+ server:
33
+ - thin 1.5.1 codename Straight Razor
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"code":"puts ''hello world''","filename":"bob.rb"}'
37
+ http_version: '1.1'
38
+ recorded_at: Tue, 03 Sep 2013 19:08:40 GMT
39
+ recorded_with: VCR 2.5.0
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.26
4
+ version: 0.0.27
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-09-02 00:00:00.000000000 Z
12
+ date: 2013-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -208,8 +208,10 @@ files:
208
208
  - lib/exercism.rb
209
209
  - lib/exercism/api.rb
210
210
  - lib/exercism/assignment.rb
211
+ - lib/exercism/cli/stash.rb
211
212
  - lib/exercism/config.rb
212
213
  - lib/exercism/env.rb
214
+ - lib/exercism/stash.rb
213
215
  - lib/exercism/submission.rb
214
216
  - lib/exercism/user.rb
215
217
  - lib/exercism/version.rb
@@ -226,8 +228,11 @@ files:
226
228
  - test/fixtures/home/.exercism
227
229
  - test/fixtures/ruby/bob/bob.rb
228
230
  - test/fixtures/vcr_cassettes/alice-gets-bob.yml
231
+ - test/fixtures/vcr_cassettes/alice-gets-stash-list.yml
232
+ - test/fixtures/vcr_cassettes/alice-gets-stash.yml
229
233
  - test/fixtures/vcr_cassettes/alice-gets-word-count.yml
230
234
  - test/fixtures/vcr_cassettes/alice-submits-bob.yml
235
+ - test/fixtures/vcr_cassettes/alice-submits-stash.yml
231
236
  - test/test_helper.rb
232
237
  homepage: https://github.com/kytrinyx/exercism
233
238
  licenses:
@@ -269,6 +274,9 @@ test_files:
269
274
  - test/fixtures/home/.exercism
270
275
  - test/fixtures/ruby/bob/bob.rb
271
276
  - test/fixtures/vcr_cassettes/alice-gets-bob.yml
277
+ - test/fixtures/vcr_cassettes/alice-gets-stash-list.yml
278
+ - test/fixtures/vcr_cassettes/alice-gets-stash.yml
272
279
  - test/fixtures/vcr_cassettes/alice-gets-word-count.yml
273
280
  - test/fixtures/vcr_cassettes/alice-submits-bob.yml
281
+ - test/fixtures/vcr_cassettes/alice-submits-stash.yml
274
282
  - test/test_helper.rb