Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
whtsky committed Apr 15, 2013
1 parent 9a5df0a commit f719149
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
58 changes: 56 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,68 @@
sphinx-quickstart on Fri Apr 5 23:26:27 2013.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. module:: flask.ext.werobot


Flask-WeRoBot
=========================================
Flask-WeRoBot 是一个帮助你将 WeRoBot 集成进 Flask 的插件。
你只要创建一个 :class:`WeRoBot` 类,就可以轻松的在你的 Flask 应用中集成 `WeRoBot <http://werobot.readthedocs.org/en/latest/>`_ 。

入门
------

最简单的 Hello World ::

from flask import Flask
from flask.ext.werobot import WeRoBot

app = Flask(__name__)
robot = WeRoBot(app)

@robot.handler
def echo(message):
return 'Hello World'

你可以像使用 `WeRoBot <http://werobot.readthedocs.org/en/latest/>`_ 一样使用 Flask-WeRoBot 。

当然,你也可以在实例化 :class:`WeRoBot` 时不传入 Flask App ,而是之后通过 :meth:`WeRoBot.init_app` 来给 Flask App 添加 WeRoBot 支持 ::

from flask import Flask
from flask.ext.werobot import WeRoBot

robot = WeRoBot()


@robot.handler
def echo(message):
return 'Hello World'


def create_app():
app = Flask(__name__)
robot.init_app(app)
return app

配置
------

=============== ========================= =============
名称 描述 默认值
=============== ========================= =============
WEROBOT_TOKEN 微信 Token 值 None
WEROBOT_ROLE Flask-WeRoBot 监听的地址 /wechat
=============== ========================= =============

API
----

.. module:: flask.ext.werobot
.. autoclass:: WeRoBot
:members: init_app

ChangeLog
-----------

.. autoclass:: WeRoBot
Version v0.1.0
```````````````
+ 框架可用。
2 changes: 1 addition & 1 deletion examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@robot.handler
def reply():
def reply(message):
return 'Hello!'

robot.init_app(app)
Expand Down
8 changes: 8 additions & 0 deletions flask_werobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def __init__(self, app=None):
self.app = None

def init_app(self, app):
"""
为一个应用添加 WeRoBot 支持。
如果你在实例化 ``WeRoBot`` 类的时候传入了一个 Flask App ,会自动调用本方法;
否则你需要手动调用 ``init_app`` 来为应用添加支持。
可以通过多次调用 ``init_app`` 并分别传入不同的 Flask App 来复用微信机器人。
:param app: 一个标准的 Flask App。
"""
assert isinstance(app, Flask)
from werobot.utils import check_token
from werobot.parser import parse_user_msg
Expand Down

0 comments on commit f719149

Please sign in to comment.