自一年前我们推出 Discourse Gamification 以来,路线图中被要求最多的功能之一就是能够将 Discourse Gamification 与外部游戏化系统集成。例子有很多:
-
与公司现有的游戏化计划集成
-
能够奖励用户在 Discourse 之外发生的事件,例如 IRL(现实生活)活动,或在线其他地方的事件,例如成为社区客户或购买产品。
-
允许用户用积分兑换商品、产品或福利的能力
今天,恰逢该插件一周年之际,我们通过一个完整的 API 来处理自定义计分事件,使上述所有功能成为可能
。
这个新系统允许管理员:
-
向用户授予自定义分数事件
-
向用户授予负分事件,以适应兑换或处罚事件
-
更新和列出先前创建的自定义事件
API
通过 API 授予的积分最多需要 10 分钟才能反映在用户总分中(针对创建日期为当天的事件),对于创建于过去 10 天内的事件,最多需要 24 小时。对于创建日期早于过去 10 天的事件,您需要运行回填(backfill)rake 任务。
目前有 3 个不同的 API 端点。
列出事件
curl https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e'
您也可以列出特定用户或日期的事件:
curl https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json?user_id=1\u0026date=2023-05-01 \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e'
创建事件
curl -X POST https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e' \
-H "Content-Type: application/json" \
-d '{
"user_id": 13,
"date": "2023-04-14",
"points": 15,
"description": "May 2023 Karaoke attendee"
}'
使用 jo 的替代语法:
jo -p user_id="13" date="2023-04-14" points="15" description="May 2023 Karaoke atendee" | curl --json @- -XPOST http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
更新事件
curl -L -X PUT https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json?id=6 \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e' \
-H "Content-Type: application/json" \
-d '{
"user_id": 11,
"date": "2023-04-15",
"points": 25,
"description": "May 2023 keynote attendee"
}'
使用 jo 的替代语法:
jo -p id="11" points="25" description="May 2023 Karaoke attendee" | curl --json @- -XPUT http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
