require 'json' require 'sinatra/base' require 'sinatra/custom_logger' require_relative '../http/query' 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, false error Pruning::Exceptions::UnexpectedError do status 500 end error Pruning::Exceptions::OriginCannotFindTheResource do status 404 end get '/' do { info: "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)] end def query Pruning::HTTP::Query.new(params) end end end end