lib/exercism/api.rb in exercism-0.0.13 vs lib/exercism/api.rb in exercism-0.0.14

- old
+ new

@@ -9,47 +9,45 @@ end def conn conn = Faraday.new(:url => url) do |c| c.use Faraday::Adapter::NetHttp + c.headers['User-Agent'] = user_agent end end def fetch - response = conn.get do |req| - req.url endpoint('current') - req.headers['User-Agent'] = user_agent - req.params['key'] = user.key - end - save response.body + get_and_save('current') end def peek - response = conn.get do |req| - req.url endpoint('next') - req.headers['User-Agent'] = user_agent - req.params['key'] = user.key - end - save response.body + get_and_save('next') end def submit(filename) path = File.join(filename) contents = File.read path response = conn.post do |req| req.url endpoint req.headers['Accept'] = 'application/json' req.headers['Content-Type'] = 'application/json' - req.headers['User-Agent'] = user_agent req.body = {code: contents, key: user.key, path: path}.to_json end response end private + def get_and_save(action) + response = conn.get do |req| + req.url endpoint(action) + req.params['key'] = user.key + end + save response.body + end + def user_agent - "exercism-CLI v#{Exercism::VERSION}" + "github.com/kytrinyx/exercism CLI v#{Exercism::VERSION}" end def endpoint(action = nil) "/api/v1/user/assignments/#{action}".chomp('/') end