lib/exercism/api.rb in exercism-0.0.26 vs lib/exercism/api.rb in exercism-0.0.27

- old
+ new

@@ -44,10 +44,43 @@ json_request(:delete, 'user/assignments', { :key => user.key }) end + def save_stash(action, filename) + path = File.join(filename) + contents = File.read path + response = conn.post do |req| + req.url endpoint(action) + req.headers['Accept'] = 'application/json' + req.headers['Content-Type'] = 'application/json' + req.body = {:code => contents, :key => user.key, :filename => path}.to_json + end + response + end + + def apply_stash(action, filename) + get_stash(action, filename) + end + + def list_stash(action) + response = conn.get do |req| + req.url endpoint(action) + req.params['key'] = user.key + end + JSON.parse(response.body) + end + private + + def get_stash(action, filename) + response = conn.get do |req| + req.url endpoint(action) + req.params['key'] = user.key + req.params['filename'] = filename + end + Stash.new(JSON.parse(response.body)) + end def get_and_save(action) response = conn.get do |req| req.url endpoint(action) req.params['key'] = user.key