diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 36d1f1d8..1b2b7230 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -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 diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 9d96435f..6fc5ced8 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -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