如果我在终端中一次输入一行,我有以下代码可以正常运行:
curl -X PUT \
> -H "X-Parse-Application-Id: APPID" \
> -H "X-Parse-REST-API-Key: APIKEY" \
> -H "Content-Type: application/json" \
> -d '{"production":true}' \
> https://api.parse.com/1/classes/FIELD/OBJECTID
我如何将其转换为Ruby脚本?
我尝试过使用httparty,uri,net / http,但curl的语法(以及它是PUT请求的事实)让我感到困惑。
答案 0 :(得分:2)
Curb是一个cURL包装器。这是一些未经测试的代码:
require 'curb'
# curl -X PUT \
# > -H "X-Parse-Application-Id: APPID" \
# > -H "X-Parse-REST-API-Key: APIKEY" \
# > -H "Content-Type: application/json" \
# > -d '{"production":true}' \
# > https://api.parse.com/1/classes/FIELD/OBJECTID
http = Curl.put("https://api.parse.com/1/classes/FIELD/OBJECTID") do |http|
http.headers['X-Parse-Application-Id'] = 'APPID'
http.headers['X-Parse-REST-API-Key'] = 'APIKEY'
http.headers['Content-Type'] = 'application/json'
http.data = '{"production":true}'
end
puts http.body_str