api.rb 1.52 KB
Newer Older
1
Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
Nihad Abbasov's avatar
Nihad Abbasov committed
2

3
module API
Nihad Abbasov's avatar
Nihad Abbasov committed
4
  class API < Grape::API
Valery Sizov's avatar
Valery Sizov committed
5
    include APIGuard
Riyad Preukschas's avatar
Riyad Preukschas committed
6
    version 'v3', using: :path
Nihad Abbasov's avatar
Nihad Abbasov committed
7

8
    rescue_from ActiveRecord::RecordNotFound do
9
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
10 11
    end

12 13 14 15 16 17 18 19 20
    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  ")

Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
21
      API.logger.add Logger::FATAL, message
22
      rack_response({ 'message' => '500 Internal Server Error' }.to_json, 500)
23 24
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
25
    format :json
26 27
    content_type :txt, "text/plain"

28
    helpers Helpers
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
29

30
    mount Groups
31
    mount GroupMembers
32 33
    mount Users
    mount Projects
34
    mount Repositories
Nihad Abbasov's avatar
Nihad Abbasov committed
35
    mount Issues
Robert Speicher's avatar
Robert Speicher committed
36
    mount Milestones
37
    mount Session
38
    mount MergeRequests
39
    mount Notes
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
40
    mount Internal
Matt Humphrey's avatar
Matt Humphrey committed
41
    mount SystemHooks
42
    mount ProjectSnippets
43
    mount ProjectMembers
44 45
    mount DeployKeys
    mount ProjectHooks
46
    mount Services
47
    mount Files
48
    mount Commits
49
    mount CommitStatus
50
    mount Namespaces
51
    mount Branches
52
    mount Labels
53
    mount Settings
54
    mount Keys
55
    mount Tags
Kamil Trzcinski's avatar
Kamil Trzcinski committed
56
    mount Triggers
57
    mount Builds
58
    mount Variables
59
    mount Runners
60
    mount Licenses
Nihad Abbasov's avatar
Nihad Abbasov committed
61
  end
62
end