zammad/lib/github/http_client.rb
Martin Gruner 64a87b1c67 Fixes #2709, fixes #2666, fixes #2665, fixes #556, fixes #3275 - Refactoring: Implement new translation toolchain based on gettext.
- Translations are no longer fetched from the cloud.
- Instead, they are extracted from the codebase and stored in i18n/zammad.pot.
- Translations will be managed via a public Weblate instance soon.
- The translated .po files are fed to the database as before.
- It is now possible to change "translation" strings for en-us locally via the admin GUI.
- It is no longer possible to submit local changes.
2021-11-15 16:58:19 +01:00

49 lines
1.1 KiB
Ruby

# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'uri'
class GitHub
class HttpClient
attr_reader :api_token, :endpoint
def initialize(endpoint, api_token)
raise 'api_token required' if api_token.blank?
raise 'endpoint required' if endpoint.blank? || endpoint.exclude?('/graphql') || endpoint.scan(URI::DEFAULT_PARSER.make_regexp).blank?
@api_token = api_token
@endpoint = endpoint
end
def perform(payload)
response = UserAgent.post(
endpoint,
payload,
{
headers: headers,
json: true,
open_timeout: 6,
read_timeout: 16,
log: {
facility: 'GitHub',
},
verify_ssl: true,
},
)
if !response.success?
Rails.logger.error response.error
raise __('GitHub request failed! Please have a look at the log file for details')
end
response.data
end
private
def headers
{
Authorization: "bearer #{api_token}"
}
end
end
end