ardakilic/euromessage-php

Euromessage PHP 客户端

0.1.2 2019-05-08 11:14 UTC

This package is auto-updated.

Last update: 2024-08-29 04:37:22 UTC


README

这个PHP库可以帮助您创建成员数据,将它们添加到特定的列表中或删除它们,并更新Euromessage上的成员偏好设置。

此客户端使用Euromessage的REST API,您可以从配置中设置端点。

需求

  • 不是古老的PHP版本(>=5.5.0)
  • ext-json

安装

您可以通过composer包管理器简单地安装

composer require ardakilic/euromessage-php

示例配置

请参阅config.example.php

配置参数包含endpoints部分,因为在我的集成过程中,公司为我提供了一个不同的API端点(base_uri)。

示例

创建(并更新)成员

a) 从成员服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
    'demographic' => [ // Depends on your account's configuration
        'E-Posta' => 'john@doe.com',
        'Adınız' => 'John',
        'Soyadınız' => 'Doe',
        'Telefon' => '532.1234567',
        // ....
    ],
];
// Whether the member will be subscribed and force updated? These parameters are `true` as default, and optional. No need to set every time.
$subscribeEmail = true;
$subscribeGSM = true;
$forceUpdate = true; // If set to true, if the key value pair matches a current member, it updates
try {
    $response = $euromessage->createMember($memberData, $subscribeEmail, $subscribeGSM, $forceUpdate);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

b) 从数据仓库服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'warehouseTableName' => 'your_warehouse_table_name', // The name of the data warehouse table on your system
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
    'demographic' => [ // Depends on your account's configuration
        'EMAIL' => 'john@doe.com',
        'AD' => 'John',
        'SOYAD' => 'Doe',
        'GSMNO' => '532.1234567',
        // ....
    ],
];
// Whether the member will be subscribed and force updated, or will the non-demographic fields be filled with blanks? These parameters are true as default, and optional. No need to set every time.
$subscribeEmail = true;
$subscribeGSM = true;
$forceUpdate = true;  // If set to true, if the key value pair matches a current member, it updates
$insertEmptyValueForNonDemographicColumns = true;
try {
    $response = $euromessage->createMemberAtWarehouse($memberData, $subscribeEmail, $subscribeGSM, $forceUpdate, $insertEmptyValueForNonDemographicColumns);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

将成员添加到列表中

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
    'lists' => [
        [
            'name' => 'List Name 1',
            'group' => 'Group Name', // "Genel" may be set as default
        ],
    ],
];
try {
    $response = $euromessage->addMemberToLists($memberData);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

从列表中移除成员

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
    'lists' => [
        [
            'name' => 'List Name 1',
            'group' => 'Group Name', // "Genel" may be set as default
        ],
    ],
];
try {
    $response = $euromessage->removeMemberFromLists($memberData);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

更新成员的通知偏好设置

此方法设置成员的关于其人口统计数据的偏好设置,因此根据Euromessage的文档,这适用于所有列表。

a) 从成员服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
];
// When these parameters are set to true, memberData wants to contact with the channels
// If these parameters are set to false, memberData wants to unsubscribe from Email or GSM
$subscribeEmail = true;
$subscribeGSM = true;
try {
    $response = $euromessage->updateNotificationPreferences($memberData, $subscribeEmail, $subscribeGSM);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

b) 从数据仓库服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'warehouseTableName' => 'your_warehouse_table_name', // The name of the data warehouse table on your system
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
];
// When these parameters are set to true, memberData wants to contact with the channels
// If these parameters are set to false, memberData wants to unsubscribe from Email or GSM
$subscribeEmail = true;
$subscribeGSM = true;
try {
    $response = $euromessage->updateNotificationPreferencesAtDataWarehouse($memberData, $subscribeEmail, $subscribeGSM);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

注意:如果您在数据仓库和成员服务中都有成员,如支持部门确认,您需要运行updateNotificationPreferencesAtDataWarehouse方法。它将在数据仓库和通过默认成员服务创建的成员中找到并更新数据。

查询成员的人口统计数据

a) 从成员服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'key' => 'KEY_ID', // Unique identifier for the service
    'value' => 'Value',
];
try {
    $response = $euromessage->queryMemberDemography($memberData);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

b) 从数据仓库服务

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$memberData = [
    'warehouseTableName' => 'your_warehouse_table_name', // The name of the data warehouse table on your system
    'key' => 'KEY_ID', // Unique identifier for the service
    'values' => [
        'Value', // You can query multiple values with this method from warehouse, that's why this is array.
        // You can add more values like 'Value2', 'Value3' etc.
    ],
];
try {
    $response = $euromessage->queryMemberDemographyFromDataWarehouse($memberData);
} catch (Exception $e) {
    if($e instanceof \GuzzleHttp\Exception\RequestException) {
        // Guzzle request exception
    } else {
        // Class's exception, wrong credentials etc.
    }
    // The code and message are according to the Euromessage API
    var_dump($e->getCode(), $e->getMessage(), $e->getTrace());
}

在运行时设置全新的配置

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$newConfig = require('./config.new.php');
$euromessage->setConfig($newConfig);
// .. Do the rest

在运行时设置一些新的配置值

<?php
$config = require('./config.php'); // or from env, etc. Should respect the example configuration
$euromessage = new Euromessage\Client($config);
$newConfig = [
    'username' => 'newUsername',
    'password' => 'newPassword',
];
$euromessage->addConfig($newConfig);
// .. Do the rest

待办事项

对于我的个人需求,不需要很多东西,但是任何pull请求都将被考虑并受到赞赏。

更新日志

0.1.2

  • setConfigaddConfig方法现在在提供endpoints.base_uri参数时重新初始化HTTP客户端。

0.1.1

  • 添加了setConfigaddConfig方法以在运行时更改配置,这些方法也可以链接。

0.1.0

  • 添加了将成员添加到数据仓库的方法。
  • 从成员服务和数据仓库中添加了查询成员ID和人口统计数据的方法。
  • updateNotificationPreferences方法中移除了forceUpdate参数。

配置参数中的端点部分现在包含换行符,请相应更新。

0.0.1

  • 初始发布。

许可证

MIT