Commit 634cbd71 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor API classes. So api classes like Gitlab::Issues become API::Issues

parent e6224942
......@@ -152,7 +152,7 @@ class ApplicationController < ActionController::Base
def add_gon_variables
gon.default_issues_tracker = Project.issues_tracker.default_value
gon.api_version = Gitlab::API.version
gon.api_version = API::API.version
gon.api_token = current_user.private_token if current_user
gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
......
require 'sidekiq/web'
require 'api/api'
Gitlab::Application.routes.draw do
#
......@@ -7,9 +8,8 @@ Gitlab::Application.routes.draw do
get 'search' => "search#show"
# API
require 'api'
Gitlab::API.logger Rails.logger
mount Gitlab::API => '/api'
API::API.logger Rails.logger
mount API::API => '/api'
constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
constraints constraint do
......
Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
module Gitlab
module API
class API < Grape::API
version 'v3', using: :path
......
module Gitlab
module API
module Entities
class User < Grape::Entity
expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter,
......
module Gitlab
module API
# groups API
class Groups < Grape::API
before { authenticate! }
......
module Gitlab
module API
module APIHelpers
def current_user
@current_user ||= User.find_by_authentication_token(params[:private_token] || env["HTTP_PRIVATE_TOKEN"])
......
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,
}
......
module Gitlab
module API
# Issues API
class Issues < Grape::API
before { authenticate! }
......
module Gitlab
module API
# MergeRequest API
class MergeRequests < Grape::API
before { authenticate! }
......
module Gitlab
module API
# Milestones API
class Milestones < Grape::API
before { authenticate! }
......
module Gitlab
module API
# Notes API
class Notes < Grape::API
before { authenticate! }
......
module Gitlab
module API
# Projects API
class Projects < Grape::API
before { authenticate! }
......
module Gitlab
module API
# Users API
class Session < Grape::API
# Login to get token
......
module Gitlab
module API
# Hooks API
class SystemHooks < Grape::API
before {
......
module Gitlab
module API
# Users API
class Users < Grape::API
before { authenticate! }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user1) { create(:user) }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......@@ -12,7 +12,7 @@ describe Gitlab::API do
get api("/internal/check")
response.status.should == 200
json_response['api_version'].should == Gitlab::API.version
json_response['api_version'].should == API::API.version
end
end
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......
require "spec_helper"
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user ) }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
before(:each) { enable_observers }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
before(:each) { enable_observers }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......
require 'spec_helper'
describe Gitlab::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......
......@@ -7,7 +7,7 @@ describe SearchController, "routing" do
end
end
# gitlab_api /api Gitlab::API
# gitlab_api /api API::API
# resque /info/resque Resque::Server
# /:path Grack
describe "Mounted Apps", "routing" do
......
......@@ -18,7 +18,7 @@ module ApiHelpers
#
# Returns the relative path to the requested API resource
def api(path, user = nil)
"/api/#{Gitlab::API.version}#{path}" +
"/api/#{API::API.version}#{path}" +
# Normalize query string
(path.index('?') ? '' : '?') +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment