Update drone request server

This commit is contained in:
Jasder 2020-07-20 15:38:12 +08:00
parent b89598d452
commit e414960153
1 changed files with 18 additions and 4 deletions

View File

@ -35,7 +35,12 @@
def put(endpoint, path, options={})
validate_request_params!(endpoint)
request(:put, endpoint, path, options)
end
def patch(url, params={})
validate_request_params!(endpoint)
request(:patch, endpoint, path, options)
end
def delete(endpoint, path, options={})
@ -45,10 +50,19 @@
private
def request(method, endpoint, path, **params)
Rails.logger.info("[drone] request: #{method} #{path} #{params.except(:secret).inspect}")
Rails.logger.info("[drone] request: #{method} #{path} #{params.except(:drone_token).inspect}")
client = Faraday.new(url: endpoint)
response = client.public_send(method, path, params)
client ||= begin
Faraday.new(url: endpoint) do |req|
req.request :url_encoded
req.headers['Content-Type'] = 'application/json'
req.response :logger # 显示日志
req.adapter Faraday.default_adapter
req.authorization :Bearer, params[:drone_token]
req.headers['Authorization']
end
end
response = client.public_send(method, path, params.except(:drone_token))
json_response(response)
end