Kazoo API的包装

kazoo-sdk的Python项目详细描述


安装

从PIP安装:

pip install kazoo-sdk

身份验证

使用用户名/密码对进行身份验证:

>>>import kazoo
>>>client = kazoo.Client(username='myusername', password='mypassword',
                         account_name='my account name',
                         base_url='http://api.example.com:8000/v1')
>>>client.authenticate()

或者使用api密钥:

>>>import kazoo
>>>client = kazoo.Client(api_key="sdfasdfas")
>>>client.authenticate()

默认的api url是:'http://api.2600hz.com:8000/v1'。你可以覆盖这个 通过向kazoo.client()提供额外的参数'base_url'。

重写“基URL”的示例:

>>>client = kazoo.Client(base_url='http://api.example.com:8000/v1',
                         api_key="sdfasdfas")

需要数据的api调用采用必需参数的形式 调用了“data”,这是该方法的最后一个参数。例如

>>>client.update_account(acct_id, {"name": "somename", "realm":"superfunrealm"})

字典和列表将自动转换为相应的 表示,以便您可以执行以下操作:

>>>client.update_callflow(acct_id, callflow_id, {"flow":{"module":"somemodule"}})

无效数据将导致解释问题的异常。

服务器响应作为python字典从每个方法返回 返回的json对象,例如:

>>>client.get_account(acct_id)
{'auth_token': 'abc437daf8517d0454cc984f6f09daf3',
 'data': {'billing_mode': 'normal',
  'caller_id': {},
  'caller_id_options': {},
  'id': 'c4f64412ad0057222c12559a3e7da011',
  'media': {'bypass_media': 'auto'},
  'music_on_hold': {},
  'name': 'test3',
  'notifications': {},
  'realm': '4c8b50.sip.2600hz.com',
  'superduper_admin': False,
  'timezone': 'America/Los_Angeles',
  'wnm_allow_additions': False},
 'request_id': 'ea6441422fb85f67ad21db4f1e2326c1',
 'revision': '3-c16dd0a629fe1da254fe1e7b3e5fb35a',
 'status': 'success'}

对于kazoo api公开的每个资源,都有相应的方法 在客户身上。例如,对于“callflows”资源 通信如下。

GET /accounts/{account_id}/callflows -> client.get_callflows(acct_id)
GET /accounts/{account_id}/callflows/{callflow_id} -> client.get_callflow(acct_id, callflow_id)
PUT /accounts/{account_id}/callflows/ -> client.create_callflow(acct_id, data)
POST /account/{account_id}/callflows/{callflow_id} -> client.update_callflow(acct_id, data)
DELETE /account/{account_id}/callflows/{callflow_id} -> client.delete_callflow(acct_id, callflow_id)

有些资源没有所有可用的方法,在这种情况下,它们是 不在客户机上。

还有一些资源不太适合这种模式,它们是:

GET /accounts/{account_id}/media -> client.get_all_media(acct_id)
GET /accounts/{account_id}/children -> client.get_account_children(acct_id)
GET /accounts/{account_id}/descendants -> client.get_account_descendants(acct_id)
GET /accounts/{account_id}/devices/status -> client.get_all_devices_status(acct_id)
GET /accounts/{account_id}/servers/{server_id}/deployment -> client.get_deployment(acct_id, server_id)
GET /accounts/{account_id}/users/hotdesk -> client.get_hotdesk(acct_id)

kazoo rest api文档可在https://2600hz.atlassian.net/wiki/display/APIs/Configuration+APIs

您可以在:https://kazoo-api.readthedocs.org/en/latest/

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法使用与Gradle发行版的连接运行生成操作https://services.gradle.org/distributions/gradle4.10.2bin.zip'   java显式定位窗格   java试图在安卓中退出。堆栈未正确清除   Java读取大文件Java堆空间   java如何处理未知的实体引用?   java如何在Spring框架中实现UDP   java在安卓中使用异常   java Android密钥库   java如何在opus文件中添加元数据?   swing无法在Java构建中添加自定义JButton。格拉德尔项目   java如何在MongoDB中按特定字段获取计数组?   基于java网络的屏幕录制器插件   java使用JDBC从Oracle获取唯一索引的所有外键   带有返回值的java simplify方法调用