require 'net/http' require 'json' module Korinthenkacker class API def initialize(base_url) uri = URI(base_url) @host = uri.host @port = uri.port end def jobs get('') end def job(jobname) get("/job/#{jobname}") end def build(jobname, build) get("/job/#{jobname}/#{build}") end def test_report(jobname, build) get("/job/#{jobname}/#{build}/testReport") end private def get(path) uri = URI::HTTP.build({:host => @host, :port => @port, :path => path + '/api/json'}) response = Net::HTTP.get_response(uri) if response.code == '200' JSON.parse(response.body) else raise 'response code is ' + response.code + ' for ' + uri.to_s end end end end