django+webhooks使操作变得简单
dj-webhooks的Python项目详细描述
django+webhooks使操作变得简单
完整的文档位于https://dj-webhooks.readthedocs.org。
要求
- python 2.7.x或3.3.2或更高版本
- django>;=1.5.5
- django jsonfield=0.9.12
- Django型号Utils>;=2.0.2
- django rq>;=0.6.1
- webhooks>;=0.3.1
快速启动
安装DJ网络挂钩:
pip install dj-webhooks
配置一些Webhook事件:
# settings.pyWEBHOOK_EVENTS=("purchase.paid","purchase.refunded","purchase.fulfilled")
添加一些webhook目标:
fromdjango.contrib.authimportget_user_modelUser=get_user_model()user=User.objects.get(username="pydanny")fromwebhooks.modelsimportWebhookWebhookTarget.objects.create(owner=user,event="purchase.paid",target_url="https://mystorefront.com/webhooks/",header_content_type=Webhook.CONTENT_TYPE_JSON,)
然后在项目中使用:
fromdjango.contrib.authimportget_user_modelUser=get_user_model()user=User.objects.get(username="pydanny")fromdjwebhooks.decoratorsimporthookfrommyproject.modelsimportPurchase# Event argument helps identify the webhook target@hook(event="purchase.paid")defsend_purchase_confirmation(purchase,owner):# Webhook_owner also helps identify the webhook targetreturn{"order_num":purchase.order_num,"date":purchase.confirm_date,"line_items":[x.skuforxinpurchase.lineitem_set.filter(inventory__gt=0)]}forpurchaseinPurchase.objects.filter(status="paid"):send_purchase_confirmation(purchase=purchase,owner=user)
在使用django rq的队列中
假设您正在运行redis并且还配置了django rq:
fromdjango.contrib.authimportget_user_modelUser=get_user_model()user=User.objects.get(username="pydanny")# import redis hookfromdjwebhooks.decoratorsimportredis_hookfrommyproject.modelsimportPurchase# Event argument helps identify the webhook target@redis_hook(event="purchase.paid")defsend_purchase_confirmation(purchase,owner):# Webhook_owner also helps identify the webhook targetreturn{"order_num":purchase.order_num,"date":purchase.confirm_date,"line_items":[x.skuforxinpurchase.lineitem_set.filter(inventory__gt=0)]}forpurchaseinPurchase.objects.filter(status="paid"):job=send_purchase_confirmation(purchase=purchase,owner=user)
功能
- 同步webhook
- 通过django orm跟踪交货。
- 异步webhook的选项。
计划功能
- 通过redis和其他写快数据存储跟踪交付。
历史记录
0.2.1(2014-05-17)
- 删除了conf.py文件,因为它只是添加了抽象
- 创建了Exlicitly importable挂钩。使设置管理更容易。
- 删除了utils.py,因为我们不再做花哨的动态导入(见上一个项目符号)。
- 现在覆盖率为100%
0.2.0(2014-05-15)
- 将发送者重构为非常可扩展的。
- 添加了一个基于orm的发件人。
- 添加了一个使用django rq的基于redis的发送器。
- 添加了一个redis hookdecorator。
- 添加了管理视图。
- 把测试覆盖率提高到89%。
- setup.py现在包含所有依赖项。
0.1.0(2014-05-12)
- pypi上的第一个版本。