Created
January 26, 2014 19:53
-
-
Save danmayer/8638368 to your computer and use it in GitHub Desktop.
churn swagger client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift "#{File.dirname(__FILE__)}/lib" | |
require "swagger" | |
# Get request API endpoints | |
require "index_api" | |
require "project_name_api.rb" | |
require "project_path_api.rb" | |
# Post request endpoints | |
require "churn_api" | |
require "projects_api" | |
#models | |
model_files = %w(commit.rb commiturl.rb minproject.rb project.rb) | |
model_files.each do |file| | |
require_relative "./models/#{file}" | |
end | |
#configure swagger | |
Swagger.configure do |config| | |
config.api_key = '1234567890abcdef' # required | |
config.username = 'wordlover' # optional, but needed for user-related functions | |
config.password = 'i<3words' # optional, but needed for user-related functions | |
config.format = 'json' # optional, defaults to 'json' | |
config.host = "http://churn.picoappz.com" # Churn_api.send(:basePath) | |
config.base_path = '/' | |
config.inject_format = false | |
config.force_ending_format = true | |
config.camelize_params = false | |
end | |
# Index churn project list | |
projects = Index_api.list_churn | |
#puts projects.inspect | |
#puts projects.first.inspect | |
puts projects.first.project_url | |
# Churn Project Show #get project http://churn.picoappz.com/al3x/sovereign.json | |
project = Project_name_api.get_project('al3x/sovereign') | |
puts project.inspect | |
puts project.name | |
# Get commit details for specific churn project | |
# http://churn.picoappz.com/guard/guard/commits/47b818dbdea16d4a8212ca668387af186f371845.json | |
# noticed this endpoint is broken in the swagger UI as well. Try to fix that first | |
# error with the model, investigate json model representation | |
# or Ruby code for ingesting | |
# /Users/danmayer/projects/swagger-codegen/generated-code/ruby/models/commit.rb:19:in `[]': can't convert String into Integer (TypeError) | |
# project_commit_churn_data = Project_path_api.get_project_commit("guard/guard","47b818dbdea16d4a8212ca668387af186f371845") | |
# puts project_commit_churn_data.inspect | |
# puts project_commit_churn_data.project_name | |
#Churn existing project | |
puts "churning a project" | |
begin | |
project = Churn_api.churn_project('al3x/sovereign',nil) | |
puts project.inspect | |
rescue ServerError => error | |
puts "server error churning project #{error.inspect}" | |
end | |
#Add a new project to calculate churn metrics against | |
puts "adding a new project" | |
begin | |
response = Projects_api.create_project('elabs/nanomachine') | |
puts response.inspect | |
rescue ServerError => error | |
puts "server error adding new project #{error}" | |
rescue ClientError => error | |
puts "client error adding new churn project #{error}" | |
puts error.message | |
puts error.backtrace.join("\n") | |
end | |
puts "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment