我无法将curl转换为ruby脚本。基本上我试图使用parse.com RESTful API。这里是卷曲将curl转换为ruby等效
curl -X POST \
-H "X-Parse-Application-Id: XXX" \
-H "X-Parse-REST-API-Key: YYY" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"Giants",
"Mets"
],
"data": {
"alert": "test message"
}
}' \
https://api.parse.com/1/push
,这就是我一直试图做的(使用HttParty)
puts "hello world"
require 'httparty'
require 'json'
class Parse
include HTTParty
base_uri "api.parse.com:443"
headers "X-Parse-Application-Id" => "XXX", "X-Parse-REST-API-Key" => "YYY", "Content-Type" => "application/json"
end
option = {:channels => "Giants", :data => {:alert => "un mensaje de mierda"}}
puts Parse.post("/1/push", body: option.to_json)
)
我越来越无效说JSON的错误代码107。任何建议将不胜感激。
为什么不使用[路沿石(HTTPS的另一个Ruby(1.9+)的方式: //github.com/taf2/curb)宝石?这是一个用于卷曲库的Ruby界面。 – 2013-03-14 07:21:03
你的'channels'值不是一个数组,因为它在你的curl请求中 - 可能是因为服务需要一个,并且因此引发了一个措辞非常糟糕的错误 – bdares 2013-03-15 03:53:37