私は Uploadcare を使用しており、このリクエストを Faraday に変換したいと考えています。
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が初めてなので、助けてください。