2021-03-10 16:11:14 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class GitLab
|
2021-03-24 16:41:05 +00:00
|
|
|
class HttpClient
|
|
|
|
attr_reader :api_token, :endpoint
|
2021-03-10 16:11:14 +00:00
|
|
|
|
|
|
|
def initialize(endpoint, api_token)
|
|
|
|
raise 'api_token required' if api_token.blank?
|
|
|
|
raise 'endpoint required' if endpoint.blank?
|
|
|
|
|
|
|
|
@api_token = api_token
|
2021-03-24 16:41:05 +00:00
|
|
|
@endpoint = endpoint
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform(payload)
|
|
|
|
response = UserAgent.post(
|
|
|
|
endpoint,
|
|
|
|
payload,
|
|
|
|
{
|
|
|
|
headers: headers,
|
|
|
|
json: true,
|
|
|
|
open_timeout: 6,
|
|
|
|
read_timeout: 16,
|
|
|
|
log: {
|
|
|
|
facility: 'GitLab',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2021-03-10 16:11:14 +00:00
|
|
|
|
2021-03-24 16:41:05 +00:00
|
|
|
if !response.success?
|
|
|
|
Rails.logger.error response.error
|
|
|
|
raise "Error while requesting GitLab GraphQL API: #{response.error}"
|
|
|
|
end
|
|
|
|
|
|
|
|
response.data
|
2021-03-10 16:11:14 +00:00
|
|
|
end
|
|
|
|
|
2021-03-24 16:41:05 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def headers
|
2021-03-10 16:11:14 +00:00
|
|
|
{
|
|
|
|
"PRIVATE-TOKEN": @api_token
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|