Skip to content

@danmayer /api_examples.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
a few examples of using the devver.net Caliper API
#This is a few examples of how to use the devver.net Caliper API
require 'cgi'
require "uri"
require "restclient"
require 'ruby-debug'
require 'json'
API_URL = 'http://api.devver.net'
def create_project(repo, with_build = false)
api_base = "#{API_URL}/projects"
begin
params = {"repo_url" => repo}
params['start_build'] = 'true' if with_build
response = RestClient.post(api_base, params)
project = JSON.parse(response)
rescue RestClient::ResourceNotFound, RestClient::RequestFailed, Errno::ECONNREFUSED => error
puts "error retrieving project #{error}"
project = nil
end
end
def run_project_revision(repo, revision = "HEAD")
api_base = "#{API_URL}/projects"
runs_url = "#{api_base}/#{CGI.escape(repo)}/runs"
response = RestClient.post(runs_url, {"revision" => revision})
result = JSON.parse(response)
end
def get_community_metrics
metrics_yaml = RestClient.get("#{API_URL}/metrics")
#`curl #{API_URL}/metrics`
metrics_yaml
end
def get_project_summary(repo)
metrics_yaml = RestClient.get("#{API_URL}/projects/#{CGI.escape(repo)}/revisions/latest/raw_metrics?trends=yes&summarize=yes")
metrics_data = YAML.load(metrics_yaml) if metrics_yaml
metrics_data
end
def get_project_summary_or_create_project(repo)
begin
metrics_yaml = RestClient.get("#{API_URL}/projects/#{CGI.escape(repo)}/revisions/latest/raw_metrics?trends=yes&summarize=yes")
metrics_data = YAML.load(metrics_yaml) if metrics_yaml
rescue RestClient::ResourceNotFound
metrics_data = nil
create_project(repo,true)
end
metrics_data
end
#project = create_project('git://github.com/madrobby/textorize.git')
#puts project
#project = create_project('git://github.com/razerbeans/sinatra-template.git', true)
#puts project
#puts get_community_metrics
#puts get_project_summary('git://github.com/razerbeans/sinatra-template.git').inspect
#data = get_project_summary_or_create_project('git://github.com/zdzolton/cambric.git')
#puts data.inspect
#puts "project lines of code: #{data[:stats]['code_loc']}"
puts run_project_revision('git://github.com/zdzolton/cambric.git','bc1bae969c25a33ccd8be307ff9b9ec1e66041ae').inspect
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.