【发布时间】:2013-03-14 07:04:34
【问题描述】:
我无法将 curl 转换为 ruby 脚本。基本上我正在尝试使用 parse.com RESTful api。这是卷曲
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)
)
我收到一个错误代码 107,说 json 无效。任何建议将不胜感激。
【问题讨论】:
-
为什么不使用Curb gem?这是 curl 库的 Ruby 接口。
-
你的
channels值不是一个数组,因为它在你的 curl 请求中 - 可能是服务正在期待一个并且结果抛出一个措辞非常糟糕的错误
标签: ruby-on-rails ruby json curl httparty