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