-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mattecalcio/new-api-calls
Add new api calls
- Loading branch information
Showing
11 changed files
with
426 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,61 +89,123 @@ public function addMember($member, $send_invite = true, $send_welcome = false, $ | |
return $result; | ||
} | ||
|
||
/** | ||
* Return a collection of member records. | ||
* | ||
* @param int $limit The maximum number of records to return, defaults to the maximum of 200 | ||
* @param int $offset The starting point within the paginated results (use in combination with limit), defaults to 0 | ||
* @param timestamp $signup_after The starting signup time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @param timestamp $singup_before The ending signup time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @param timestamp $updated_after The starting last updated time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @param timestamp $updated_before The ending last updated time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @param timestamp $unsubscribed_after The starting unsubscribed time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @param timestamp $unsubscribed_before The ending unsubscribed time from which to return records, in UTC, e.g., 2016-03-30 14:15:30 | ||
* @return export_struct | MAILAPI_Error | ||
*/ | ||
public function getBulkMembers($limit = 200, $offset = 0, $signup_after, $signup_before, $updated_after, $updated_before, $unsubscribed_after, $unsubscribed_before) | ||
{ | ||
$params = array(); | ||
$params['limit'] = php_xmlrpc_encode($limit); | ||
$params['offset'] = php_xmlrpc_encode($offset); | ||
$params['signup_after'] = php_xmlrpc_encode($signup_after); | ||
$params['singup_before'] = php_xmlrpc_encode($signup_before); | ||
$params['updated_after'] = php_xmlrpc_encode($updated_after); | ||
$params['updated_before'] = php_xmlrpc_encode($updated_before); | ||
$params['unsubscribed_after'] = php_xmlrpc_encode($unsubscribed_after); | ||
$params['unsubscribed_before'] = php_xmlrpc_encode($unsubscribed_before); | ||
$result = $this->mailapi_call->executeMethod('getBulkMembers', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Return the member record. | ||
* | ||
* @param string $user_token Either user_email, which is the member's email (e.g., [email protected]) or user_enc, which is the member's permanent id (e.g., 01234a-56789b) | ||
* @return export_struct | MAILAPI_Error | ||
*/ | ||
public function getMember($user_token) | ||
{ | ||
$params = array(); | ||
$params['user_token'] = php_xmlrpc_encode($user_token); | ||
$result = $this->mailapi_call->executeMethod('getMember', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Unsubscribe a collection of member email addresses from the account list. | ||
* | ||
* @param string $user_emails emails of the members to unsubscribe | ||
* @param array $user_tokens emails of the members to unsubscribe | ||
* @return true | MAILAPI_Error | ||
*/ | ||
public function unsubBulkMembers($user_emails) | ||
public function unsubBulkMembers($user_tokens) | ||
{ | ||
$params = array(); | ||
$params['user_emails'] = php_xmlrpc_encode($user_emails); | ||
$params['user_tokens'] = php_xmlrpc_encode($user_tokens); | ||
$result = $this->mailapi_call->executeMethod('unsubBulkMembers', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Unsubscribe the email address from the account email list. | ||
* | ||
* @param string $user_email email of the member to unsubscribe | ||
* @param string $user_token Either user_email, which is the member's email (e.g., [email protected]) or user_enc, which is the member's permanent id (e.g., 01234a-56789b) | ||
* @return true | MAILAPI_Error | ||
*/ | ||
public function unsubMember($user_email) | ||
public function unsubMember($user_token) | ||
{ | ||
$params = array(); | ||
$params['user_email'] = php_xmlrpc_encode($user_email); | ||
$params['user_token'] = php_xmlrpc_encode($user_token); | ||
$result = $this->mailapi_call->executeMethod('unsubMember', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Suppress the member email address. | ||
* | ||
* @param string $user_email email of the member to suppress | ||
* @param string $user_token Either user_email, which is the member's email (e.g., [email protected]) or user_enc, which is the member's permanent id (e.g., 01234a-56789b) | ||
* @return true | MAILAPI_Error | ||
*/ | ||
public function suppressMember($user_email) | ||
public function suppressMember($user_token) | ||
{ | ||
$params = array(); | ||
$params['user_email'] = php_xmlrpc_encode($user_email); | ||
$params['user_token'] = php_xmlrpc_encode($user_token); | ||
$result = $this->mailapi_call->executeMethod('suppressMember', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Unsuppress the member email address. | ||
* | ||
* @param string $user_email email of the member to unsuppress | ||
* @param string $user_token Either user_email, which is the member's email (e.g., [email protected]) or user_enc, which is the member's permanent id (e.g., 01234a-56789b) | ||
* @return true | MAILAPI_Error | ||
*/ | ||
public function unsuppressMember($user_email) | ||
public function unsuppressMember($user_token) | ||
{ | ||
$params = array(); | ||
$params['user_email'] = php_xmlrpc_encode($user_email); | ||
$params['user_token'] = php_xmlrpc_encode($user_token); | ||
$result = $this->mailapi_call->executeMethod('unsuppressMember', $params); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Update an existing specified list member. | ||
* | ||
* @param string $user_token Either user_email, which is the member's email (e.g., [email protected]) or user_enc, which is the member's permanent id (e.g., 01234a-56789b) | ||
* @param member_struct $member A single member record | ||
* @param boolean $enforce_required Flag to control whether missing required fields as specified by account configuration should throw an exception, defaults to true | ||
* @param boolean $send_invite Flag to control if double opt-in confirmation message is sent, defaults to true | ||
* @return true | MAILAPI_Error | ||
*/ | ||
public function updateMember($user_token, $member, $enforced_required = true, $send_invite = true) | ||
{ | ||
$params = array(); | ||
$params['user_token'] = php_xmlrpc_encode($user_token); | ||
$params['member'] = php_xmlrpc_encode($member); | ||
$params['enforce_required'] = php_xmlrpc_encode($enforce_required); | ||
$params['send_invite'] = php_xmlrpc_encode($send_invite); | ||
$result = $this->mailapi_call->executeMethod('updateMember', $params); | ||
return $result; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
include("../MAILAPI_Client.php"); | ||
|
||
// Make sure we have an api key | ||
if (getenv('MAILAPI_KEY') == null) { | ||
exit('Set setenv("MAILAPI_KEY") to use this example'); | ||
} | ||
|
||
// Make sure we have an email address | ||
if (getenv('MAILAPI_TEST_EMAIL') == null) { | ||
exit('Set setenv("MAILAPI_TEST_EMAIL") to use this example'); | ||
} | ||
|
||
date_default_timezone_set('America/New_York'); | ||
|
||
// Create our API object | ||
$mailapi = new MAILAPI_Client(getenv('MAILAPI_KEY')); | ||
|
||
// Get bulk members who signed up in the past year | ||
$date_after = date('Y-m-d H:i:s', time() - (365 * 24 * 60 * 60)); | ||
$date_before = date('Y-m-d H:i:s', time()); | ||
$response = $mailapi->getBulkMembers(10, 0, $date_after, $date_before, null, null, null, null); | ||
|
||
if (MAILAPI_Error::isError($response)) { | ||
echo "Error \n"; | ||
echo "Code: " . $response->getErrorCode() . "\n"; | ||
echo "Message: ". $response->getErrorMessage() . "\n"; | ||
} else { | ||
echo "Got " . sizeof($response) . " members\n"; | ||
echo "Here are the members:\n"; | ||
var_dump($response); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
include("../MAILAPI_Client.php"); | ||
|
||
// Make sure we have an api key | ||
if (getenv('MAILAPI_KEY') == null) { | ||
exit('Set setenv("MAILAPI_KEY") to use this example'); | ||
} | ||
|
||
// Make sure we have an email address | ||
if (getenv('MAILAPI_TEST_EMAIL') == null) { | ||
exit('Set setenv("MAILAPI_TEST_EMAIL") to use this example'); | ||
} | ||
|
||
// Create our API object | ||
$mailapi = new MAILAPI_Client(getenv('MAILAPI_KEY')); | ||
|
||
// Add the member | ||
$response = $mailapi->getMember(getenv('MAILAPI_TEST_EMAIL')); | ||
|
||
// Evaluate response | ||
if (MAILAPI_Error::isError($response)) { | ||
echo "Error \n"; | ||
echo "Code: " . $response->getErrorCode() . "\n"; | ||
echo "Message: ". $response->getErrorMessage() . "\n"; | ||
} else { | ||
echo "Success got member\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
include("../MAILAPI_Client.php"); | ||
|
||
// Make sure we have an api key | ||
if (getenv('MAILAPI_KEY') == null) { | ||
exit('Set setenv("MAILAPI_KEY") to use this example'); | ||
} | ||
|
||
// Make sure we have an email address | ||
if (getenv('MAILAPI_TEST_EMAIL') == null) { | ||
exit('Set setenv("MAILAPI_TEST_EMAIL") to use this example'); | ||
} | ||
|
||
$member = array(); | ||
|
||
// Open text fields | ||
$member['user_email'] = getenv('MAILAPI_TEST_EMAIL'); | ||
$member['user_fname'] = 'John'; | ||
$member['user_lname'] = 'Doe'; | ||
|
||
// Country | ||
$member['user_country'] = 'us'; | ||
|
||
// State | ||
$member['user_state'] = 'md'; | ||
|
||
// Category fields with multiple selection (checkboxes) | ||
$member['user_attr1'] = array('a','b','c','d'); | ||
|
||
// Category fields with single selection (dropdown menu) | ||
$member['user_attr2'] = array('a'); | ||
|
||
// Create our API object | ||
$mailapi = new MAILAPI_Client(getenv('MAILAPI_KEY')); | ||
|
||
// Update the member | ||
$response = $mailapi->updateMember(getenv('MAILAPI_TEST_EMAIL'), $member); | ||
|
||
// Evaluate response | ||
if (MAILAPI_Error::isError($response)) { | ||
echo "Error \n"; | ||
echo "Code: " . $response->getErrorCode() . "\n"; | ||
echo "Message: ". $response->getErrorMessage() . "\n"; | ||
} else { | ||
echo "Success updated member\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
require_once("test_config.php"); | ||
|
||
class GetBulkMembers extends PHPUnit_Framework_TestCase | ||
{ | ||
protected $mailapi; | ||
|
||
protected $email1; | ||
protected $email2; | ||
protected $email3; | ||
|
||
protected $member1; | ||
protected $member2; | ||
protected $member3; | ||
|
||
|
||
protected function setUp() | ||
{ | ||
include 'test_vars.php'; | ||
|
||
$this->mailapi = new MAILAPI_Client($test_apikey); | ||
|
||
$this->email1 = $test_email1; | ||
$this->email2 = $test_email2; | ||
$this->email3 = $test_email3; | ||
|
||
$formfields = $this->mailapi->getFormFields(); | ||
|
||
foreach ($formfields as $formfield) { | ||
$value; | ||
if ($formfield["type"] == 'select') { | ||
if ($formfield["attributes"]["select_type"] == 'multi') { | ||
$value = array("a","b","c","d"); | ||
} else { | ||
$value = array("a"); | ||
} | ||
} elseif ($formfield["type"] == 'open_text') { | ||
$value = "ANYTHING"; | ||
} elseif ($formfield["type"] == 'state') { | ||
$value = "md"; | ||
} elseif ($formfield["type"] == 'country') { | ||
$value = "us"; | ||
} | ||
$this->member1[$formfield["fieldname"]] = $value; | ||
$this->member2[$formfield["fieldname"]] = $value; | ||
$this->member3[$formfield["fieldname"]] = $value; | ||
} | ||
|
||
$this->member1["user_email"] = $this->email1; | ||
$this->member2["user_email"] = $this->email2; | ||
$this->member3["user_email"] = $this->email3; | ||
|
||
$response = $this->mailapi->addBulkMembers(array($this->member1, $this->member2, $this->member3)); | ||
$expected = array('added' => 3, 'updated' => 0, 'errors' => array(), 'report' => $response); | ||
$this->assertEquals(1, $this->checkReport($expected)); | ||
|
||
|
||
|
||
sleep(2); | ||
} | ||
|
||
public function testContainsNewMembers() | ||
{ | ||
$date_after = date('Y-m-d H:i:s', time() - (60 * 60)); | ||
$date_before = date('Y-m-d H:i:s', time() + (60 * 60)); | ||
|
||
$response = $this->mailapi->getBulkMembers(200, 0, $date_after, $date_before, null, null, null, null); | ||
$collectEmails = array_map(function($member){ | ||
return $member["user_email"]; | ||
}, $response); | ||
|
||
$this->assertNotInstanceOf('MAILAPI_Error', $response); | ||
$this->assertContains($this->email1, $collectEmails); | ||
$this->assertContains($this->email2, $collectEmails); | ||
$this->assertContains($this->email3, $collectEmails); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////// | ||
// | ||
// HELPER FUNCTION | ||
// | ||
//////////////////////////////////////////////////////////////// | ||
public function checkReport($params) | ||
{ | ||
$added = $params["added"]; | ||
$updated = $params["updated"]; | ||
$errors = $params["errors"]; | ||
|
||
$report = $params["report"]; | ||
|
||
if (count($errors)) { | ||
foreach ($report["errors"] as $value) { | ||
if ($errors[$value["email"]]) { | ||
if ($errors[$value["email"]] > 1) { | ||
$errors[$value["email"]]--; | ||
} | ||
else { | ||
unset($errors[$value["email"]]); | ||
} | ||
} | ||
} | ||
} | ||
return ($added == $report["added"] && $updated == $report["updated"] && count($errors) == 0); | ||
} | ||
} | ||
?> |
Oops, something went wrong.