evodelavega / pushover-net
Pushover.net API 的简单封装
dev-master
2015-03-22 13:46 UTC
Requires
- php: >=5.4.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: 4.5.*
This package is not auto-updated.
Last update: 2024-09-24 03:23:27 UTC
README
简单、独立、干净的 PHP 封装,用于 pushover.net API
基本示例(推送消息)
推送消息很简单。但与其他封装不同,验证用户和组、检查已推送消息的收据、选择声音(通过常量)等同样简单...
这是一个简单的示例
<?php $credentials = new Credentials( 'APP token', 'user API' ); //API settings array $apiSettings = [ 'baseUrl' => 'the url',//default works fine 'output' => Api::OUTPUT_JSON ]; //create message object $message = new Message( [ 'message' => 'The message', 'title' => 'The title', 'priority' => Message::PRIORITY_EMERGENCY, 'sound' => Message::SOUND_GAME ], $credentials ); //USING THE WRAPPER: //get API section: $api = Api::GetApiSection( Api::SECTION_PUSH,//get push section, $apiSettings ); //push message $response = $api->pushMessage($message); //check receipt, alternative way of creating API wrapper: $api = new Receipt($apiSettings); //get the receipt for the response $receipt = $api->getReceipt( $response, $credentials );
基本上,这个示例用于展示在构建了 Credentials
类之后,API 的使用非常直接。一切设置完成后,只需传递对象即可。
如果出现问题,将抛出适当的异常。
这个封装能做什么?
这是一个好问题。简单地说,这是一个极简设置,允许你
- 推送消息(examples/example.php 展示了如何做)
- 验证用户、组和他们的设备
- 如果需要,处理收据
- 轻松扩展功能(查看基类
PushOver\Api
和PushOver\Model\Data
)
它不能做什么(目前还不能)?
另一个好问题。本封装中缺少的功能(但将很快添加)包括
- 支持 XML 格式化响应(不会很快添加)
- 单元测试(正在添加中)
- 提高数据模型一致性,并使整体 API 更一致
将来可能会添加什么?
- 更好的错误/异常处理
- 一致性调整(返回值/属性类型)
- 数据模型应以某种方式实现
\Traversable
接口 - ...
我欢迎建议,所以如果你在寻找某些东西,就像我一样,发现现有的封装不足:创建一个问题,我会很高兴调查它
使 example.php 脚本工作
只需在 examples 目录中创建 params.json
文件。JSON 应该看起来像
{ "credentials": { "user": "<your user string>", "token": "<the API token>" }, "api": { "baseUrl": "base url like: https://api.pushover.net/1/", "output": ".json (or, when added .xml, xml is currently unsupported)" } }
如果你尝试使用 Api::GetApiSection
方法加载除 PushOver\Push
之外的 API 类,不要忘记 require
它(或者更好的是,注册 composer 有帮助地提供的自动加载器)
这就对了!
==========
贡献是可选的,但受到鼓励。
如果你看到改进的空间,或者想要提出建议:不要犹豫,创建问题。Fork,创建 pull requests... 一切都行。合作很有趣。