public
Last active

a few examples of using the devver.net Caliper API

  • Download Gist
api_examples.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.