From 209dbe2a85a513bd60181222617173875ccb4481 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Fri, 12 Oct 2012 01:24:04 +0200 Subject: [PATCH] rename services, remove service helpers --- Gemfile.lock | 2 +- lib/travis/api/app/endpoint.rb | 2 +- lib/travis/api/app/endpoint/accounts.rb | 2 +- lib/travis/api/app/endpoint/artifacts.rb | 2 +- lib/travis/api/app/endpoint/branches.rb | 4 ++-- lib/travis/api/app/endpoint/builds.rb | 22 ++------------------- lib/travis/api/app/endpoint/hooks.rb | 4 ++-- lib/travis/api/app/endpoint/jobs.rb | 4 ++-- lib/travis/api/app/endpoint/repos.rb | 12 ++++++------ lib/travis/api/app/endpoint/stats.rb | 4 ++-- lib/travis/api/app/endpoint/users.rb | 4 ++-- lib/travis/api/app/endpoint/workers.rb | 4 ++-- lib/travis/api/app/helpers/services.rb | 25 ------------------------ 13 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 lib/travis/api/app/helpers/services.rb diff --git a/Gemfile.lock b/Gemfile.lock index 47819fe5..300a0459 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 1448d4b1505b38014d3083f45500d371c8ec999f + revision: 3154d3fbfa6fe4202ade27f5712927b72dc1673b branch: sf-travis-api specs: travis-core (0.0.1) diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 716a2df7..60700418 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -9,7 +9,7 @@ class Travis::Api::App set(:prefix) { "/" << name[/[^:]+$/].underscore } set disable_root_endpoint: false register :scoping - helpers :current_user, :flash, :services + helpers :current_user, :flash # TODO hmmm? before { flash.clear } diff --git a/lib/travis/api/app/endpoint/accounts.rb b/lib/travis/api/app/endpoint/accounts.rb index 6f2597e9..784adc20 100644 --- a/lib/travis/api/app/endpoint/accounts.rb +++ b/lib/travis/api/app/endpoint/accounts.rb @@ -4,7 +4,7 @@ class Travis::Api::App class Endpoint class Accounts < Endpoint get '/', scope: :private do - respond_with all(params), type: :accounts + respond_with service(:accounts, :find_all, params), type: :accounts end end end diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index e7d5632b..e7e22271 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -7,7 +7,7 @@ class Travis::Api::App class Artifacts < Endpoint # Fetches an artifact by it's *id*. get '/:id' do |id| - respond_with one(params) + respond_with service(:artifacts, :find_one, params) end end end diff --git a/lib/travis/api/app/endpoint/branches.rb b/lib/travis/api/app/endpoint/branches.rb index 671de627..9d97efdd 100644 --- a/lib/travis/api/app/endpoint/branches.rb +++ b/lib/travis/api/app/endpoint/branches.rb @@ -4,12 +4,12 @@ class Travis::Api::App class Endpoint class Branches < Endpoint get '/' do - respond_with all(params), type: :branches + respond_with service(:branches, :find_all, params), type: :branches end # get '/:owner_name/:name/branches' do # v1 # get '/repos/:owner_name/:name/branches' do # v2 - # respond_with all(params), type: :branches + # respond_with service(:branches, :find_all, params), type: :branches # end end end diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 22d83c0d..2357a596 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,30 +4,12 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - respond_with all(params) + respond_with service(:builds, :find_all, params) end get '/:id' do - respond_with one(params) + respond_with service(:builds, :find_one, params) end - - # get '/repositories/:repository_id/builds' do # v1 - # get '/repos/:repository_id/builds' do # v2 - # respond_with all(params) - # end - - # get '/repositories/:repository_id/builds/1' do # v1 - # respond_with all(params) - # end - - # get '/:owner_name/:name/builds' do # v1 - # get '/repos/:owner_name/:name/builds' do # v2 - # respond_with all(params) - # end - - # get '/:owner_name/:name/builds/:id' do # v1 - # respond_with all(params) - # end end end end diff --git a/lib/travis/api/app/endpoint/hooks.rb b/lib/travis/api/app/endpoint/hooks.rb index c13bc444..33b5a698 100644 --- a/lib/travis/api/app/endpoint/hooks.rb +++ b/lib/travis/api/app/endpoint/hooks.rb @@ -4,11 +4,11 @@ class Travis::Api::App class Endpoint class Hooks < Endpoint get '/', scope: :private do - respond_with all(params), type: :hooks + respond_with service(:hooks, :find_all, params), type: :hooks end put '/:id?', scope: :private do - respond_with update(id: params[:id] || params[:hook][:id], active: params[:hook][:active]) + respond_with service(:hooks, :update, id: params[:id] || params[:hook][:id], active: params[:hook][:active]) end end end diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 7c077f92..0fd7f4f0 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -4,11 +4,11 @@ class Travis::Api::App class Endpoint class Jobs < Endpoint get '/' do - respond_with all(params) + respond_with service(:jobs, :find_all, params) end get '/:id' do - respond_with one(params).run + respond_with service(:jobs, :find_one, params) end end end diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 0d05152d..7947a859 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -4,27 +4,27 @@ class Travis::Api::App class Endpoint class Repos < Endpoint get '/' do - respond_with service(:repositories, :all, params) + respond_with service(:repositories, :find_all, params) end get '/:id' do - respond_with service(:repositories, :one, params) + respond_with service(:repositories, :find_one, params) end get '/:id/cc' do - respond_with service(:repositories, :one, params.merge(schema: 'cc')) + respond_with service(:repositories, :find_one, params.merge(schema: 'cc')) end get '/:owner_name/:name' do - respond_with service(:repositories, :one, params) + respond_with service(:repositories, :find_one, params) end get '/:owner_name/:name/builds' do - respond_with service(:builds, :all, params) + respond_with service(:builds, :find_all, params) end get '/:owner_name/:name/builds/:id' do - respond_with service(:builds, :one, params) + respond_with service(:builds, :find_one, params) end end end diff --git a/lib/travis/api/app/endpoint/stats.rb b/lib/travis/api/app/endpoint/stats.rb index 7bd2a2ee..c45f6508 100644 --- a/lib/travis/api/app/endpoint/stats.rb +++ b/lib/travis/api/app/endpoint/stats.rb @@ -4,11 +4,11 @@ class Travis::Api::App class Endpoint class Stats < Endpoint get '/repos' do - { :stats => service(:daily_repos) } + { :stats => service(:stats, :daily_repos) } end get '/tests' do - { :stats => service(:daily_tests) } + { :stats => service(:stats, :daily_tests) } end end end diff --git a/lib/travis/api/app/endpoint/users.rb b/lib/travis/api/app/endpoint/users.rb index 8f4b389d..7676ce2e 100644 --- a/lib/travis/api/app/endpoint/users.rb +++ b/lib/travis/api/app/endpoint/users.rb @@ -24,11 +24,11 @@ class Travis::Api::App end get '/permissions', scope: :private do - respond_with service(:users, :permissions), type: :permissions + respond_with service(:users, :find_permissions), type: :permissions end put '/:id?', scope: :private do - respond_with update(params[:user]) + respond_with service(:users, :update, params[:user]) end post '/sync', scope: :private do diff --git a/lib/travis/api/app/endpoint/workers.rb b/lib/travis/api/app/endpoint/workers.rb index cf75bb37..073152c9 100644 --- a/lib/travis/api/app/endpoint/workers.rb +++ b/lib/travis/api/app/endpoint/workers.rb @@ -4,11 +4,11 @@ class Travis::Api::App class Endpoint class Workers < Endpoint get '/' do - respond_with all(params) + respond_with service(:workers, :find_all, params) end get '/:id' do - respond_with one(params) + respond_with service(:workers, :find_one, params) end end end diff --git a/lib/travis/api/app/helpers/services.rb b/lib/travis/api/app/helpers/services.rb deleted file mode 100644 index 9b5bafab..00000000 --- a/lib/travis/api/app/helpers/services.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - module Helpers - module Services - def all(params) - service(services_namespace, :all, params) - end - - def one(params) - service(services_namespace, :one, params) - end - - def update(params) - service(services_namespace, :update, params) - end - - private - - def services_namespace - self.class.name.split('::').last - end - end - end -end