这是我的curl命令,在命令行中运行良好:
curl --data @order_new.json \
-H "X-Augury-Token:My_token_goes_here" \
-H "Content-Type:application/json" \
http://staging.hub.spreecommerce.com/api/stores/store_id_goes_here/messages
我需要使用任何种类的Gem在rails中实现相同的功能,尝试使用HTTParty / rest_client / spree-api-client,但这里有些错误:
require 'httparty'
result = HTTParty.post(
"http://staging.hub.spreecommerce.com/api/stores/52eb347f755b1c97e900001e/messages",
:body => JSON.parse(File.read("order_new.json")),
:header => {
"X-Augury-Token" => "UjjKsdxbrwjpAPx9Hiw4",
"Content-Type" => "application/json"
}
)
但我收到错误,
"The page you were looking for doesn't exist (404)"
我需要相当于curl命令的rails,使用spree-api-client gem会有很大帮助。
答案 0 :(得分:0)
如果您更喜欢使用Spree::API::Client
,是否可以发布您的调查结果?你能评估以下命令的输出并回发:
client = Spree::API::Client.new('http://staging.hub.spreecommerce.com/api/', 'UjjKsdxbrwjpAPx9Hiw4')
client.products.inspect
答案 1 :(得分:0)
require 'httparty'
result = HTTParty.post(
"http://staging.hub.spreecommerce.com/api/stores/52eb347f755b1c97e900001e/messages",
:body => @order.to_json,
:header => {
"X-Augury-Token" => "UjjKsdxbrwjpAPx9Hiw4",
"Content-Type" => "application/json"
}
)
传递给HTTParty正文时不要解析json