所以我使用的是Uploadcare,并希望将此请求转换为法拉第:
curl -X DELETE \
-H "Content-Type: application/json" \
-H "Authorization: Uploadcare.Simple demopublickey:demoprivatekey" \
-d '["21975c81-7f57-4c7a-aef9-acfe28779f78",
"cbaf2d73-5169-4b2b-a543-496cf2813dff"]' \
"https://api.uploadcare.com/files/storage/"
以下是(陈旧的)Uploadcare Ruby gem的摘录:
require 'faraday'
require "faraday_middleware"
module Uploadcare
module Connections
class ApiConnection < Faraday::Connection
def initialize options
super options[:api_url_base] do |frd|
frd.request :url_encoded
frd.use ::FaradayMiddleware::FollowRedirects, limit: 3
frd.adapter :net_http # actually, default adapter, just to be clear
frd.headers['Authorization'] = "Uploadcare.Simple #{options[:public_key]}:#{options[:private_key]}"
frd.headers['Accept'] = "application/vnd.uploadcare-v#{options[:api_version]}+json"
frd.headers['User-Agent'] = Uploadcare::user_agent
frd.response :raise_error
frd.response :parse_json
end
end
end
end
end
以下是使用它的模块:
module Uploadcare
module RawApi
def initialize options={}
@options = Uploadcare::default_settings.merge(options)
@api_connection = Uploadcare::Connections::ApiConnection.new(@options)
@upload_connection = Uploadcare::Connections::UploadConnection.new(@options)
end
# basic request method
def request method = :get, path = "/files/", params = {}
response = @api_connection.send method, path, params
response.body
end
alias_method :api_request, :request
# request with GET verb
def get path= "/files/", params={}
request :get, path, params
end
# request with POST verb
def post path= "/files/", params={}
request :post, path, params
end
# request with PUT verb
def put path= "/files/", params={}
request :put, path, params
end
# request with DELETE verb
def delete path= "/files/", params={}
request :delete, path, params
end
end
end
我目前使用的这段代码不起作用:
uuids = ['1234679', '122344']
uuid_param = '"#{uuids}"'
# does not work
model_object.group.delete('/files/storage/', {'':uuid_param})
# does not work
model_object.group.delete('/files/storage/, {uuid_param})
编辑:以上两个代码都会产生服务器错误500
如何在法拉第上面的uploadcare CURL请求中正确声明'-d'参数?我对REST很陌生,所以请帮助。