Sha256: deba223894e63daf390ef5aa6af5b70f5a6b026b8c268fdbd04b25ae3ccec753

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require "rack"

class Konstant::Web

  def self.call(env)
    new(env).route
  end

  def initialize(env)
    @env = env
  end

  def request
    @request ||= Rack::Request.new(@env)
  end

  def route
    if request.path.match(/^\/projects$/)
      [200, {"Content-type" => "application/json"}, [Konstant::Project.all.to_json]]
    elsif m = request.path.match(/^\/projects\/([^\/]+)\/builds\/(\d+)$/)
      project = Konstant::Project.new m[1]
      build = Konstant::Build.new project, m[2]
      [200, {"Content-type" => "application/json"}, [build.to_json]]
    elsif request.path.match(/^\/config$/)
      [200, {"Content-type" => "application/json"}, [Konstant.config.to_json]]
    elsif m = request.path.match(/^\/projects\/([^\/]+)\/builds$/)
      project = Konstant::Project.new m[1]
      [200, {"Content-type" => "application/json"}, [project.builds.to_json]]
    elsif m = request.path.match(/^\/projects\/([^\/]+)\/build$/)
      project = Konstant::Project.new m[1]
      project.build!
      message = {"message" => "ok"}
      [200, {"Content-type" => "application/json"}, [message.to_json]]
    else
      [404, {"Content-type" => "text/plain"}, ["not found"]]
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
konstant-0.1.2 lib/konstant/web.rb
konstant-0.1.1 lib/konstant/web.rb
konstant-0.1.0 lib/konstant/web.rb
konstant-0.0.10 lib/konstant/web.rb
konstant-0.0.9 lib/konstant/web.rb
konstant-0.0.8 lib/konstant/web.rb