secomapp / sendyphp
用于与Sendy新闻通讯系统(http://sendy.co)交互的PHP库
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
- squizlabs/php_codesniffer: 1.*
This package is not auto-updated.
Last update: 2024-09-21 14:51:39 UTC
README
一个用于与Sendy API(http://sendy.co)交互的PHP类
安装
使用Composer
首先,通过Composer安装此包。编辑项目的composer.json
文件以需要jacobbennett/sendyphp
。
"require": {
"secomapp/sendyphp": "1.3.*"
}
然后,从终端更新Composer
composer update
非Composer安装
- 获取
src/SendyPHP.php
文件并将其放置到您的文件结构中。 - 在您希望使用SendyPHP的位置引入SendyPHP。
require('SendyPHP.php');
使用方法
创建类的实例,同时传递包括您的API密钥、安装URL和您要与之工作的列表ID的数组。
$config = array( 'api_key' => 'yourapiKEYHERE', //your API key is available in Settings 'installation_url' => 'http://updates.mydomain.com', //Your Sendy installation 'list_id' => 'your_list_id_goes_here' ); $sendy = new \SendyPHP\SendyPHP($config); //you can change the list_id you are referring to at any point $sendy->setListId("a_different_list_id");
方法
在创建新的SendyPHP实例后,可以调用以下任何方法
返回值
这些函数的返回值将包括状态和与该状态相关的消息。
状态是布尔值true
或false
,而消息将根据所执行的操作类型而变化。
//example of a succesful return value array( 'status'=>true, 'message'=>'Already Subscribed' ) //example of a UNsuccesful return value array( 'status'=>false, 'message'=>'Some fields are missing.' )
我已经注释和组织了代码,以便于阅读。如果您对返回的状态或消息有进一步的问题,请参阅库注释。
subscribe(array $values)
此方法接受一个$values
数组,并尝试将$values
添加到$list_id
中指定的列表。
$results = $sendy->subscribe(array( 'name'=>'Jim', 'email' => 'Jim@gmail.com', //this is the only field required by sendy 'customfield1' => 'customValue' ));
注意:在使用此库之前,请确保在Sendy中添加任何自定义字段到列表。 另一条注意:如果用户已订阅列表,库将返回状态true
。您可以根据需要编辑代码。
unsubscribe($email)
取消提供电子邮件地址(如果存在)的当前列表订阅。
$results = $sendy->unsubscribe('test@testing.com');
delete($email)
从当前列表中删除电子邮件地址。
$results = $sendy->delete('test@testing.com');
注意:请参阅代码或查看http://sendy.co/api以获取您预期的返回消息类型。
substatus($email)
返回提供电子邮件地址(如果存在)的当前列表中用户的状态。
$results = $sendy->substatus('test@testing.com');
注意:请参阅代码或查看http://sendy.co/api以获取您预期的返回消息类型。
subcount()
返回当前列表的订阅者数量。
$results = $sendy->subcount();
createCampaign(array $values)
此方法接受一个$values
数组,并创建一个活动(可选发送它)。
$results = $sendy->createCampaign(array( 'from_name' => 'Some Name', 'from_email' => 'some@domain.com', 'reply_to' => 'some@domain.com', 'subject' => 'Some Subject', 'plain_text' => 'Amazing campaign', // (optional). 'html_text' => '<h1>Amazing campaign</h1>', 'list_ids' => 'your_list_id', // Required only if you set send_campaign to 1. 'brand_id' => 0, // Required only if you are creating a 'Draft' campaign. 'query_string' => 'some', // eg. Google Analytics tags. 'send_campaign' => 0 // Set to 1 if you want to send the campaign as well and not just create a draft. Default is 0. ));
setListId($list_id) 和 getListId()
更改或获取您当前正在处理的列表。
//set or switch the list id $sendy->setListId('another_list_id'); //get the current list id echo $sendy->getListId();
单元测试
所有单元测试都位于src/test目录下。要从项目根目录运行测试,请输入以下内容。
php vendor/bin/phpunit src/test/SendyPHPTest.php
确保设置了测试的API密钥。
$config = [ 'api_key' => 'xxx', //your API key is available in Settings 'installation_url' => 'http://my.sendy.installation.com', //Your Sendy installation 'list_id' => 'xxx'// List ID ];