Houdini API发送如下所示的回发:
{
"api_key": "keykeykeykeykey",
"environment": "production",
"postback_url": "http://example.com/postbacks",
"blueprint": "research_link_data",
"input": {
"name": "example name"
"website": "example website"
}
"status": "processing",
"output": {
"Correction": "example Correction"
"has_book": "example has_book"
"search_results_link": "example search_results_link"
}
}
(使用真正的 API_Key。)
(您在postback_url
向 API 发送初始请求时自行设置。)
要接收和处理这些回发,我有:
class Postback < ActiveRecord::Base
attr_accessible :uuid
belongs_to :survey
extend FriendlyId
friendly_id :uuid
after_create :generate_uuid
def generate_uuid
self.update_attributes :uuid => SecureRandom.uuid
end
end
class PostbacksController < ApplicationController
respond_to :html
def receive
@postback = Postback.find(params[:id])
end
end
Testivate::Application.routes.draw do
resources :postbacks, :only => [:index, :show] do
member do
post :receive
end
end
end
在Simple REST Client中,我有:
- 选择 POST 单选按钮
- 输入“http etc postbacks/32e5a1bb-452f-4ad2-9a42-c17239f3d964/receive 作为 URL(这是一个真正的 UUID,抱歉 StackOverflow 不允许我发布完整的本地 URL)
- 将 Header 字段留空(因为我不知道该放什么)
将以下内容放入数据字段:
{“api_key”:“keykeykeykeykey”,“环境”:“生产”,“postback_url”:url,“蓝图”:“research_link_data”,“输入”:{“名称”:“示例名称”“网站”:“示例网站”}“状态”:“处理”,“输出”:{“更正”:“示例更正”“has_book”:“示例 has_book”“search_results_link”:“示例 search_results_link”}}
(该 URL 与我在上面的第 2 步中列出的 URL 相同。抱歉,StackOverflow 不喜欢指向本地服务器的 URL。抱歉,我无法让 StackOverflow 将其格式化为代码块。)
postbacks#receive
然后我使用 Pry投入到行动中。为什么我只看到:
> params
=> {"action"=>"receive",
"controller"=>"postbacks",
"id"=>"32e5a1bb-452f-4ad2-9a42-c17239f3d964"}
我如何获得其余的结果?
谢谢,
史蒂文。