Update drone request server
This commit is contained in:
parent
b89598d452
commit
e414960153
|
@ -35,7 +35,12 @@
|
||||||
|
|
||||||
def put(endpoint, path, options={})
|
def put(endpoint, path, options={})
|
||||||
validate_request_params!(endpoint)
|
validate_request_params!(endpoint)
|
||||||
request(:put, endpoint, path, options)
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def patch(url, params={})
|
||||||
|
validate_request_params!(endpoint)
|
||||||
|
request(:patch, endpoint, path, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(endpoint, path, options={})
|
def delete(endpoint, path, options={})
|
||||||
|
@ -45,10 +50,19 @@
|
||||||
|
|
||||||
private
|
private
|
||||||
def request(method, endpoint, path, **params)
|
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)
|
client ||= begin
|
||||||
response = client.public_send(method, path, params)
|
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)
|
json_response(response)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue