Sha256: 6b0fac15a853bf3fa03646be25a4d22ae255bf7500c88a04b5564cb80a5765d4

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

class Exercism
  class Api
    def self.conn
     conn = Faraday.new(:url => Exercism.url) do |c|
        c.use Faraday::Adapter::NetHttp
      end
    end

    def self.fetch_for(user)
      response = conn.get do |req|
        req.url '/api/v1/user/assignments/current'
        req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
        req.params['key'] = user.key
      end
      Assignment.save(JSON.parse(response.body))
    end

    def self.submit(filename, options)
      user = options[:for]
      path = File.join(FileUtils.pwd, filename)
      contents = File.read path
      response = conn.post do |req|
        req.url '/api/v1/user/assignments'
        req.headers['Accept'] = 'application/json'
        req.headers['Content-Type'] = 'application/json'
        req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
        req.body = {code: contents, key: user.key, path: path}.to_json
      end
      response
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exercism-0.0.4 lib/exercism/api.rb