Add a simple api
method to ApiHelpers, replacing api_prefix
See docs for usage
This commit is contained in:
parent
fba174e9bc
commit
b2a5344a2d
5 changed files with 33 additions and 3 deletions
|
@ -1,6 +1,31 @@
|
|||
module ApiHelpers
|
||||
def api_prefix
|
||||
"/api/#{Gitlab::API::VERSION}"
|
||||
# Public: Prepend a request path with the path to the API
|
||||
#
|
||||
# path - Path to append
|
||||
# user - User object - If provided, automatically appends private_token query
|
||||
# string for authenticated requests
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# >> api('/issues')
|
||||
# => "/api/v2/issues"
|
||||
#
|
||||
# >> api('/issues', User.last)
|
||||
# => "/api/v2/issues?private_token=..."
|
||||
#
|
||||
# >> api('/issues?foo=bar', User.last)
|
||||
# => "/api/v2/issues?foo=bar&private_token=..."
|
||||
#
|
||||
# Returns the relative path to the requested API resource
|
||||
def api(path, user = nil)
|
||||
"/api/#{Gitlab::API::VERSION}#{path}" +
|
||||
|
||||
# Normalize query string
|
||||
(path.index('?') ? '' : '?') +
|
||||
|
||||
# Append private_token if given a User object
|
||||
(user.respond_to?(:private_token) ?
|
||||
"&private_token=#{user.private_token}" : "")
|
||||
end
|
||||
|
||||
def json_response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue