diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-14 15:33:31 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-14 15:33:31 +0300 |
commit | 634cbd71380f595f6f44ce93399b92fbee37f98f (patch) | |
tree | c421f7fd1b2cfbf396f8765e948b19fa47d1fd6e /lib/api | |
parent | e6224942cee8f02d96e51098552a738f1d89860f (diff) | |
download | gitlab-ce-634cbd71380f595f6f44ce93399b92fbee37f98f.tar.gz |
Refactor API classes. So api classes like Gitlab::Issues become API::Issues
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 38 | ||||
-rw-r--r-- | lib/api/entities.rb | 2 | ||||
-rw-r--r-- | lib/api/groups.rb | 2 | ||||
-rw-r--r-- | lib/api/helpers.rb | 2 | ||||
-rw-r--r-- | lib/api/internal.rb | 4 | ||||
-rw-r--r-- | lib/api/issues.rb | 2 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 2 | ||||
-rw-r--r-- | lib/api/milestones.rb | 2 | ||||
-rw-r--r-- | lib/api/notes.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 2 | ||||
-rw-r--r-- | lib/api/session.rb | 2 | ||||
-rw-r--r-- | lib/api/system_hooks.rb | 2 | ||||
-rw-r--r-- | lib/api/users.rb | 2 |
13 files changed, 51 insertions, 13 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb new file mode 100644 index 00000000000..28e6add73ed --- /dev/null +++ b/lib/api/api.rb @@ -0,0 +1,38 @@ +Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} + +module API + class API < Grape::API + version 'v3', using: :path + + rescue_from ActiveRecord::RecordNotFound do + rack_response({'message' => '404 Not found'}.to_json, 404) + end + + rescue_from :all do |exception| + # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 + # why is this not wrapped in something reusable? + trace = exception.backtrace + + message = "\n#{exception.class} (#{exception.message}):\n" + message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code) + message << " " << trace.join("\n ") + + API.logger.add Logger::FATAL, message + rack_response({'message' => '500 Internal Server Error'}, 500) + end + + format :json + helpers APIHelpers + + mount Groups + mount Users + mount Projects + mount Issues + mount Milestones + mount Session + mount MergeRequests + mount Notes + mount Internal + mount SystemHooks + end +end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 3fe4abc3e2a..c3c351e1733 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1,4 +1,4 @@ -module Gitlab +module API module Entities class User < Grape::Entity expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter, diff --git a/lib/api/groups.rb b/lib/api/groups.rb index efdbeb176c6..701f6777b77 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # groups API class Groups < Grape::API before { authenticate! } diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index f12fb5fdbd0..94cf4f2e69f 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -1,4 +1,4 @@ -module Gitlab +module API module APIHelpers def current_user @current_user ||= User.find_by_authentication_token(params[:private_token] || env["HTTP_PRIVATE_TOKEN"]) diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 3e1173bd0a3..a602dc05418 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Internal access API class Internal < Grape::API namespace 'internal' do @@ -58,7 +58,7 @@ module Gitlab get "/check" do { - api_version: Gitlab::API.version, + api_version: API.version, gitlab_version: Gitlab::VERSION, gitlab_rev: Gitlab::REVISION, } diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 500a8551f35..53e2e8cfa35 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Issues API class Issues < Grape::API before { authenticate! } diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index d5595d5f16b..23e2f82889f 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # MergeRequest API class MergeRequests < Grape::API before { authenticate! } diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 1adeefece1f..a25bbad1302 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Milestones API class Milestones < Grape::API before { authenticate! } diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 450faae535a..cb2bc764476 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Notes API class Notes < Grape::API before { authenticate! } diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 18e912ff48e..d9743b4539a 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Projects API class Projects < Grape::API before { authenticate! } diff --git a/lib/api/session.rb b/lib/api/session.rb index b4050160ae4..509acded51e 100644 --- a/lib/api/session.rb +++ b/lib/api/session.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Users API class Session < Grape::API # Login to get token diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb index 9e3574e3b99..3e239c5afe7 100644 --- a/lib/api/system_hooks.rb +++ b/lib/api/system_hooks.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Hooks API class SystemHooks < Grape::API before { diff --git a/lib/api/users.rb b/lib/api/users.rb index cda543495a0..84256b51124 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -1,4 +1,4 @@ -module Gitlab +module API # Users API class Users < Grape::API before { authenticate! } |