跳转到主要内容

Kazoo API的包装器

项目描述

安装

从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”来覆盖此设置。

覆盖‘base_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字典返回,例如

>>>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)

卡兹乌 Rest API 文档可在以下网址查看:https://2600hz.atlassian.net/wiki/display/APIs/Configuration+APIs

您可以在以下网址查看可用客户端方法列表:https://kazoo-api.readthedocs.org/en/latest/

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源代码分发

kazoo-sdk-0.2.4.tar.gz (15.0 kB 查看哈希值)

上传时间 源代码

由以下支持