我有一个基于SMTP中继的 SendGrid服务集成的现有rails3应用程序,并订阅事件通知Webhooks 。
我收到了来自服务的提醒电子邮件,告知即将更改SendGrid的服务,我需要进行一些更改以匹配新版本的事件通知Webhooks v3。
我收到的电子邮件包含有关如何升级的说明:
我更聪明,我现在需要在我的网站上实施哪些更改?我阅读了v3手册,但没有关于旧版本和新版本之间规格差异的信息。
答案 0 :(得分:2)
以前,SendGrid事件webhook发送了不正确的批量JSON,文档由换行符分隔:
{ "email": "john.doe@sendgrid.com", "timestamp": 1337197600, "smtp-id": "<4FB4041F.6080505@sendgrid.com>", "event": "processed" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337966815, "category": "newuser", "event": "click", "url": "http://sendgrid.com" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337969592, "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed" }
今天,使用v3
,它会发送正确的JSON:
[
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337197600,
"smtp-id": "<4FB4041F.6080505@sendgrid.com>",
"event": "processed"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337966815,
"category": "newuser",
"event": "click",
"url": "http://sendgrid.com"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337969592,
"smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
"event": "processed"
}
]
如果您之前一直在处理非批处理事件,则需要调整代码以使其解释数组,而不是仅解释单个文档,然后循环遍历所述数组。放入代码:
# This
consume_data(params)
# Becomes this
params.each { |doc|
consume_data(doc)
}