Test for Pruner

This commit is contained in:
Senad Uka
2018-08-13 18:54:12 +02:00
parent 5684e58826
commit 973f1e1093
15 changed files with 2888 additions and 53 deletions

View File

@@ -6,27 +6,26 @@ require_relative '../exceptions'
module Pruning
module API
# Handles general concers regarding API calls
class App < Sinatra::Base
before { content_type :json }
after { serialise_response }
set :show_exceptions, true
error Pruning::Exceptions::UnexpectedError do
error Pruning::Exceptions::UnexpectedError do
status 500
end
error Pruning::Exceptions::OriginCannotFindTheResource do
status 404
status 404
end
get '/' do
"Try /tree/:name"
'Try /tree/:name?indicator_ids[]=32&indicator_ids[]=31'
end
private
def serialise_response
return unless content_type == 'application/json'
response.body = [JSON(response.body)]

View File

@@ -7,17 +7,15 @@ require_relative '../exceptions'
module Pruning
module API
# Handles all tree related API requests
class Tree < App
get '/tree/:name' do
tree_repo = Pruning::Repos::Tree.new(RestClient, ENV['TREE_SOURCE_API_HOSTNAME'])
complete_tree = tree_repo.get(query.name)
pruner = Pruning::Processing::Pruner.new(complete_tree)
pruner.prune_tree(query.indicator_ids)
tree_repo = Pruning::Repos::Tree.new(RestClient,
ENV['TREE_SOURCE_API_HOSTNAME'])
complete_tree = tree_repo.get(query.name)
pruner = Pruning::Processing::Pruner.new(complete_tree)
pruner.prune_tree(query.indicator_ids.to_a)
end
end
end
end
end