usefomo / fomo-php-sdk
Fomo PHP SDK 是 Fomo API 服务的官方 SDK 包装器
1.2.0
2019-02-08 23:58 UTC
Requires
- php: >=5.3.0
- ext-curl: *
README
Fomo PHP SDK 是 Fomo API 服务 的官方 SDK 包装器
API 文档: https://docs.fomo.com
要求
- PHP 版本 5.3.0+
安装
使用以下命令安装最新版本
$ composer require usefomo/fomo-php-sdk
手动用户安装
下载 src/Fomo/FomoClient.php 并将其包含在您的 PHP 项目中。
查看我们的示例 example/fomo-example.php,快速使用示例
基本使用
初始化 Fomo 客户端
<?php use Fomo\FomoClient; $client = new FomoClient($authToken); // auth token can be found Fomo application admin dashboard (App -> API Access)
创建一个新事件
使用模板名称...
use Fomo\FomoEventBasic; $event = new FomoEventBasic(); $event->event_type_tag = "new_order"; // Event type tag is found on Fomo dashboard (Templates -> Template name) $event->title = "Test event"; $event->first_name = "Ryan"; $event->email_address = "ryan.kulp@fomo.com"; // used to fetch Gravatar for notification image $event->ip_address = "128.177.108.102"; // used for extracting location parameters (city, province, country) $event->city = "New York City"; $event->url = "https://www.fomo.com"; // for additional parameters check code documentation // Add event custom attributes $event->addCustomEventField('variable_name', 'value'); $fomoEvent = $client->createEvent($event);
或使用模板 ID
use Fomo\FomoEventBasic; $event = new FomoEventBasic(); $event->event_type_id = "4"; // Event type ID is found on Fomo dashboard (Templates -> Template ID) $event->title = "Test event"; $event->first_name = "Ryan"; $event->email_address = "ryan.kulp@fomo.com"; $event->ip_address = "128.177.108.102"; $event->url = "https://www.fomo.com"; // for additional parameters check code documentation // Add event custom attributes $event->addCustomEventField('variable_name', 'value'); $fomoEvent = $client->createEvent($event);
获取事件
$fomoEvent = $client->getEvent("<event ID>");
获取事件
$fomoEvents = $client->getEvents(30 /* page size */, 1 /* page */);
获取包含元数据的事件
$fomoEventsWithMeta = $client->getEventsWithMeta(30 /* page size */, 1 /* page */); /* Events */ print_r($fomoEventsWithMeta->events); /* Meta data */ echo 'Current page: ', $fomoEventsWithMeta->meta->page, "\n"; echo 'Total pages: ', $fomoEventsWithMeta->meta->total_pages, "\n"; echo 'Page size: ', $fomoEventsWithMeta->meta->per_page, "\n"; echo 'Total count: ', $fomoEventsWithMeta->meta->total_count, "\n";
删除事件
$client->deleteEvent("<event ID>");
更新事件
$fomoEvent = $client->getEvent("<event ID>"); $fomoEvent->first_name = "John"; $fomoEvent = $client->updateEvent($fomoEvent);
支持
如果您有任何问题,请通过 hello@fomo.com 发送电子邮件给我们。