0

所以我正在使用 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

如何在 Faraday 上面的 uploadcare CURL 请求中正确声明“-d”参数?我对 REST 很陌生,所以请帮忙。

4

0 回答 0