跳转到主要内容

sailplay.ru 的 API 客户端

项目描述

Python 客户端用于 sailplay.ru API

Build Status Coverals https://pypip.in/d/sailplay/badge.png https://badge.fury.io/py/sailplay.png

文档可在 https://sailplay.readthedocs.org/ 找到。带有文档改进和/或修正的拉取请求非常棒,非常受欢迎。

需求

  • python >= 2.6

安装

sailplay 可以使用 pip 安装

pip install sailplay

使用

初始化 API 客户端

您应该从服务中获取 pinstore_department_idstore_department_key

from sailplay import SailPlayClient

client = SailPlayClient(pin, store_department_id, store_department_key)

额外参数

client = SailPlayClient(
    pin, store_department_id, store_department_key,
    token="token-here", # Set token manually (default "")
    silence=True,       # Dont fail on API errors (default False)
    loglevel="debug",   # Set log level (default INFO)
)

获取 API 令牌

client.login()
print client.token

使用 api

Sailplay 有一个漂亮且简单的语法。只需看看即可

# Get events list  http://sailplay.ru/api/v2/events/list/
client.api.events.list()

# Create a new user http://sailplay.ru/api/v2/users/add/?...
client.api.users.add(user_phone='...', first_name='...', last_name='...')

# Get info about user http://sailplay.ru/api/v2/users/info/?...
client.api.users.info(user_phone='...')

# Create purchase http://sailplay.ru/api/v2/purchases/new/?...
client.api.purchases.new(**params)

# You also could use getitem syntax for params
client.api.users['custom-vars'](**params)
# Same as
client.api['users']['custom-vars'](**params)

# And etc. I hope you make decision how the client works :)

目前客户端会自动选择 API 版本。

上下文管理器

您可以在上下文中重新定义客户端设置。

with client.ctx(silence=True):
    # Errors will not be raised here
    client.api.users.add(user_phone='...', first_name='...', last_name='...')

原始 API 请求

您可以向 sailplay API 发送原始请求。

client.request(method='GET', url='/users/info', data={...})

编程愉快!

缺陷跟踪器

如果您有任何建议、错误报告或烦恼,请向问题跟踪器报告,网址为 https://github.com/klen/sailplay/issues

贡献

入门项目的开发在github上进行:https://github.com/klen/sailplay

贡献者

  • klen (Kirill Klenov)

许可证

许可协议为BSD。

项目详情


下载文件

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

源分布

sailplay-0.2.0.tar.gz (5.5 kB 查看哈希值)

上传时间

构建分布

sailplay-0.2.0-py2.py3-none-any.whl (6.4 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下组织支持