Sha256: f7c6f037faf54491a62e6b4e61b4b3189765f7407191c4de4c7cf2cd7bfe7442
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
class Exercism class Api attr_reader :url, :user, :project_dir def initialize(url, user, project_dir = nil) @url = url @user = user @project_dir = project_dir end def conn conn = Faraday.new(:url => url) do |c| c.use Faraday::Adapter::NetHttp c.headers['User-Agent'] = user_agent end end def demo get_and_save('assignments/demo') end def fetch get_and_save('user/assignments/current') end def peek get_and_save('user/assignments/next') end def submit(filename) path = File.join(filename) contents = File.read path response = conn.post do |req| req.url endpoint('user/assignments') req.headers['Accept'] = 'application/json' req.headers['Content-Type'] = 'application/json' 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 "github.com/kytrinyx/exercism CLI v#{Exercism::VERSION}" end def endpoint(action = nil) "/api/v1/#{action}".chomp('/') end def save(body) Assignment.save(JSON.parse(body), project_dir) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
exercism-0.0.19 | lib/exercism/api.rb |
exercism-0.0.18 | lib/exercism/api.rb |
exercism-0.0.17 | lib/exercism/api.rb |