add services

This commit is contained in:
Sven Fuchs 2012-09-15 12:06:33 +02:00
parent 1fdcec33a4
commit 79e382ce0b
2 changed files with 11 additions and 0 deletions
lib/travis/api

View File

@ -75,6 +75,10 @@ class Travis::Api::App
def self.setup_travis
Travis::Database.connect
Travis::Services.constants.each do |name|
Travis.services[name.to_s.underscore.to_sym] = Travis::Services.const_get(name) unless name == :Base
end
end
def self.load_endpoints

View File

@ -10,5 +10,12 @@ class Travis::Api::App
before { content_type :json }
error(ActiveRecord::RecordNotFound, Sinatra::NotFound) { not_found }
not_found { content_type =~ /json/ ? { 'file' => 'not found' } : 'file not found' }
private
def service(key)
const = Travis.services[key] || raise("no service registered for #{key}")
const.new(respond_to?(:current_user) ? current_user : nil)
end
end
end