diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 09cad0cb..aabe2ffc 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -10,9 +10,17 @@ module Travis class App < Sinatra::Application autoload :Service, 'travis/api/app/service' - register Sinatra::Reloader use ActiveRecord::ConnectionAdapters::ConnectionManagement + error ActiveRecord::RecordNotFound do + not_found + end + + configure :development do + register Sinatra::Reloader + set :show_exceptions, :after_handler + end + provides :json get '/repositories' do @@ -20,8 +28,7 @@ module Travis end get '/repositories/:id' do - respond_with Service::Repos.new(params).element - # rescue ActiveRecord::RecordNotFound + respond_with Service::Repos.new(params).item # raise if not params[:format] == 'png' end @@ -30,11 +37,12 @@ module Travis end get '/builds/:id' do - respond_with Service::Builds.new(params).element + respond_with Service::Builds.new(params).item end get '/branches' do - respond_with Service::Repos.new(params).element, :type => :branches + # respond_with Service::Repos.new(params).item, :type => :branches + { branches: [] }.to_json end get '/jobs' do @@ -42,11 +50,11 @@ module Travis end get '/jobs/:id' do - respond_with Service::Jobs.new(params).element + respond_with Service::Jobs.new(params).item end get '/artifacts/:id' do - respond_with Service::Artifacts.new(params).element + respond_with Service::Artifacts.new(params).item end get '/workers' do @@ -55,7 +63,7 @@ module Travis get '/hooks' do authenticate_user! - respond_with Service::Hooks.new(user, params).element + respond_with Service::Hooks.new(user, params).item # rescue_from ActiveRecord::RecordInvalid, :with => Proc.new { head :not_acceptable } end diff --git a/lib/travis/api/app/service/artifacts.rb b/lib/travis/api/app/service/artifacts.rb index e9ada452..5435659a 100644 --- a/lib/travis/api/app/service/artifacts.rb +++ b/lib/travis/api/app/service/artifacts.rb @@ -3,7 +3,7 @@ module Travis class App class Service class Artifacts < Service - def element + def item Artifact.find(params[:id]) end end diff --git a/lib/travis/api/app/service/builds.rb b/lib/travis/api/app/service/builds.rb index 8638dd5a..ca138331 100644 --- a/lib/travis/api/app/service/builds.rb +++ b/lib/travis/api/app/service/builds.rb @@ -9,7 +9,7 @@ module Travis scope end - def element + def item one = params[:repository_id] ? repository.builds : Build one.includes(:commit, :matrix => [:commit, :log]).find(params[:id]) end diff --git a/lib/travis/api/app/service/jobs.rb b/lib/travis/api/app/service/jobs.rb index 84f0ae20..66e8f59f 100644 --- a/lib/travis/api/app/service/jobs.rb +++ b/lib/travis/api/app/service/jobs.rb @@ -13,7 +13,7 @@ module Travis end end - def element + def item Job.find(params[:id]) end end diff --git a/lib/travis/api/app/service/profile.rb b/lib/travis/api/app/service/profile.rb index 49d71d16..1b6c9e85 100644 --- a/lib/travis/api/app/service/profile.rb +++ b/lib/travis/api/app/service/profile.rb @@ -9,7 +9,7 @@ module Travis @user = user end - def element + def item user end diff --git a/lib/travis/api/app/service/repos.rb b/lib/travis/api/app/service/repos.rb index 1af2d875..3ce66f24 100644 --- a/lib/travis/api/app/service/repos.rb +++ b/lib/travis/api/app/service/repos.rb @@ -17,7 +17,7 @@ module Travis scope end - def element + def item Repository.find_by(params) end end