raphaelz/lametric-php

用于访问 LaMetric API 的 PHP 封装器。

dev-master 2017-01-08 04:20 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:26:33 UTC


README

使用 LaMetric API 创建推送和轮询应用程序的 PHP 封装器。

需求

  • PHP 5.3 或更高版本
  • cURL
  • 注册的 LaMetric 开发者账号

开始使用

要使用 LaMetric API,您必须创建一个开发者账号并关联您的设备。然后,您需要创建一个 指示器应用

安装

$ composer require raphaelz/lametric-php

使用配置初始化类(推送应用程序)

use Lametric\Lametric;

$lametric = new Lametric(array(
    'pushURL' => 'YOUR_PUSH_URL',
    'token' => 'YOUR_TOKEN',
));

不使用配置初始化类(轮询应用程序)

use Lametric\Lametric;

$lametric = new Lametric();

可用方法

更改图标

在推送消息之前设置默认图标。这仅适用于未设置图标的推送。

// Setting icon number to 95 will show a lightning icon
$lametric->setIcon(95);

图标编号可在图标库中找到。

您还可以创建自己的图标,但请注意在公共库中插入时的编号。

发送推送通知

推送方法允许您使用简单消息、指定图标编号的消息和数组(框架)将推送通知发送到 Lametric。

// Send a simple push notification. Icon must be set using the setIcon method, otherwise it will default to null.
$lametric->push("Hello World!");

// Send a push notification with specific icon number.
$lametric->push("Hello World!", 95);

// Send a push notification with an array (frames) as parameter. Must use key, value pairs: text, icon.
// Note: The frames are not stored after the notification as been sent.
$lametric->push(array(array('text'=>'Frame 1', 'icon'=>51), array('text'=>'Frame 2', 'icon'=>62)));

添加框架

使用 addFrame 和 addFrames 方法,可以为推送或轮询应用程序添加框架。

// Add frame to notification.
$lametric->addFrame('Notification', 98);

// Add frames for use later
$lametric->addFrames(array(array('text'=>'Frame 1', 'icon'=>51), array('text'=>'Frame 2', 'icon'=>62)));

生成数据

当创建轮询应用程序时,请结合使用 generateData 方法、addFrame 或 addFrames 方法生成 Lametric 获取所需的 JSON 数据。

// Return frames as an array
$lametric->generateData();

// Return frame array as JSON data (poll method)
$lametric->generateData(true);

清除框架

// Clear frames array for object
$lametric->clearFrames();

待办事项

这是封装器的早期版本,需要一些额外的功能

  • 支持其他类型的指示器应用(例如:度量、目标、Sparkline)

致谢

版权(c)2017 - 由 Raphael Z 编程

许可

版权(c)2017 Raphael Z.

特此授予任何获得此软件及其相关文档副本(以下简称“软件”)的人免费使用软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,以及允许获得软件的人进行此类操作的权利,但受以下条件约束

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是否因合同、侵权或其他行为而引起的,无论是与软件或其使用或其他方式相关的。