From c7c74e6761f95d538d1a22490506b720fcb1fec3 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sat, 20 Sep 2014 16:55:05 -0400 Subject: [PATCH 1/8] Resolve conflicts --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 16daeb4..bfc91d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # mailermailer-api-php -A PHP wrapper using the [PHPXMLRPC](http://phpxmlrpc.sourceforge.net/) library to connect to the MailerMailer API. +A PHP wrapper using the [PHPXMLRPC](http://phpxmlrpc.sourceforge.net/) library to connect to the MailerMailer API ##Requirements @@ -8,7 +8,7 @@ PHP 5 ## Installation -Just place mailermailer-api-php in a directory accessible by your application +Just place mailermailer-api-php in a directory accessible by your application. ## Usage From 763d65d4db0834dcab1f1cba8048ef6a7282e8f2 Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 22 Mar 2016 21:31:00 -0400 Subject: [PATCH 2/8] Add new API calls --- MAILAPI_Client.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/MAILAPI_Client.php b/MAILAPI_Client.php index 61e66e3..927631c 100644 --- a/MAILAPI_Client.php +++ b/MAILAPI_Client.php @@ -89,6 +89,48 @@ 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., johnsmith@email.com) 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. * @@ -144,6 +186,26 @@ public function unsuppressMember($user_email) $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., johnsmith@email.com) 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('unsuppressMember', $params); + return $result; + } } ?> From e382e2d25c43952c32ae2bc8f8df1e05fd6b4aca Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 22 Mar 2016 21:41:01 -0400 Subject: [PATCH 3/8] Update calls to use user_token --- MAILAPI_Client.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MAILAPI_Client.php b/MAILAPI_Client.php index 927631c..1bfada8 100644 --- a/MAILAPI_Client.php +++ b/MAILAPI_Client.php @@ -134,13 +134,13 @@ public function getMember($user_token) /** * 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; } @@ -148,13 +148,13 @@ public function unsubBulkMembers($user_emails) /** * 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., johnsmith@email.com) 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; } @@ -162,13 +162,13 @@ public function unsubMember($user_email) /** * 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., johnsmith@email.com) 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; } @@ -176,13 +176,13 @@ public function suppressMember($user_email) /** * 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., johnsmith@email.com) 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; } From 298b80e10cbc012e238f29f61d32d238c1eeb7b8 Mon Sep 17 00:00:00 2001 From: Matteo Date: Wed, 30 Mar 2016 23:58:07 -0400 Subject: [PATCH 4/8] Add tests for new calls --- MAILAPI_Client.php | 2 +- tests/GetBulkMembersTest.php | 107 +++++++++++++++++++++++++++++++++++ tests/GetMemberTest.php | 59 +++++++++++++++++++ tests/UnsubMemberTest.php | 2 +- tests/UpdateMemberTest.php | 61 ++++++++++++++++++++ tests/test_vars.php | 2 + 6 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 tests/GetBulkMembersTest.php create mode 100644 tests/GetMemberTest.php create mode 100644 tests/UpdateMemberTest.php diff --git a/MAILAPI_Client.php b/MAILAPI_Client.php index 1bfada8..db1203e 100644 --- a/MAILAPI_Client.php +++ b/MAILAPI_Client.php @@ -203,7 +203,7 @@ public function updateMember($user_token, $member, $enforced_required = true, $s $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('unsuppressMember', $params); + $result = $this->mailapi_call->executeMethod('updateMember', $params); return $result; } } diff --git a/tests/GetBulkMembersTest.php b/tests/GetBulkMembersTest.php new file mode 100644 index 0000000..58635a9 --- /dev/null +++ b/tests/GetBulkMembersTest.php @@ -0,0 +1,107 @@ +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); + } +} +?> \ No newline at end of file diff --git a/tests/GetMemberTest.php b/tests/GetMemberTest.php new file mode 100644 index 0000000..8076ea9 --- /dev/null +++ b/tests/GetMemberTest.php @@ -0,0 +1,59 @@ +mailapi = new MAILAPI_Client($test_apikey); + $this->email = $test_email1; + + $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->member[$formfield["fieldname"]] = $value; + } + + $this->member["user_email"] = $this->email; + + $response = $this->mailapi->addMember($this->member); + $this->assertEquals(1, $response); + + sleep(2); + } + + public function testSuccess() + { + $response = $this->mailapi->getMember($this->email); + $this->assertNotInstanceOf('MAILAPI_Error', $response); + } + + public function testNonExistentUser() + { + $response = $this->mailapi->getMember('fake@email.com'); + $this->assertEquals(305, $response->getErrorCode()); + } +} + +?> \ No newline at end of file diff --git a/tests/UnsubMemberTest.php b/tests/UnsubMemberTest.php index eac9781..724319e 100644 --- a/tests/UnsubMemberTest.php +++ b/tests/UnsubMemberTest.php @@ -61,7 +61,7 @@ public function testUnsubTwice() public function testUnsubNonexistentListMember() { $response = $this->mailapi->unsubMember("This email doesn't exist"); - $this->assertEquals(305, $response->getErrorCode()); + $this->assertEquals(302, $response->getErrorCode()); } public function testMissingFields() diff --git a/tests/UpdateMemberTest.php b/tests/UpdateMemberTest.php new file mode 100644 index 0000000..3c02bd3 --- /dev/null +++ b/tests/UpdateMemberTest.php @@ -0,0 +1,61 @@ +mailapi = new MAILAPI_Client($test_apikey); + $this->email = $test_email1; + + $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->member[$formfield["fieldname"]] = $value; + } + + $this->member["user_email"] = $this->email; + + $response = $this->mailapi->addMember($this->member); + $this->assertEquals(1, $response); + + sleep(2); + } + + public function testSuccess() + { + $response = $this->mailapi->updateMember($this->email, $this->member); + $this->assertNotInstanceOf('MAILAPI_Error', $response); + } + + public function testBadUpdate() + { + $bad_member = $this->member; + $bad_member["user_email"] = "bad value"; + $response = $this->mailapi->updateMember($this->email, $bad_member); + $this->assertEquals(302, $response->getErrorCode()); + } +} + +?> \ No newline at end of file diff --git a/tests/test_vars.php b/tests/test_vars.php index ccb45d9..c46cb92 100644 --- a/tests/test_vars.php +++ b/tests/test_vars.php @@ -12,6 +12,8 @@ exit("Provide the test email address by setting MAILAPI_TEST_EMAIL env variable.\n"); } +date_default_timezone_set('America/New_York'); + $test_apikey = getenv('MAILAPI_KEY'); $test_email1 = str_replace("@", "+php1" . md5(time()) . "@", getenv('MAILAPI_TEST_EMAIL')); From 53bcc2a2b76a5084d98f606765bcf1b0164d333a Mon Sep 17 00:00:00 2001 From: Matteo Date: Thu, 31 Mar 2016 01:23:21 -0400 Subject: [PATCH 5/8] Add examples for new calls --- examples/getBulkMembers.php | 35 ++++++++++++++++++++++++++ examples/getMember.php | 30 +++++++++++++++++++++++ examples/updateMember.php | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 examples/getBulkMembers.php create mode 100644 examples/getMember.php create mode 100644 examples/updateMember.php diff --git a/examples/getBulkMembers.php b/examples/getBulkMembers.php new file mode 100644 index 0000000..3a8795e --- /dev/null +++ b/examples/getBulkMembers.php @@ -0,0 +1,35 @@ +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); +} + +?> diff --git a/examples/getMember.php b/examples/getMember.php new file mode 100644 index 0000000..e77a4bf --- /dev/null +++ b/examples/getMember.php @@ -0,0 +1,30 @@ +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"; +} + +?> diff --git a/examples/updateMember.php b/examples/updateMember.php new file mode 100644 index 0000000..72944c9 --- /dev/null +++ b/examples/updateMember.php @@ -0,0 +1,49 @@ +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"; +} + +?> From 1d68bb5973324ecff915bc38d552903a15ebaf5e Mon Sep 17 00:00:00 2001 From: Matteo Date: Thu, 31 Mar 2016 01:37:14 -0400 Subject: [PATCH 6/8] Bump up version to 1.0.7 --- LICENSE.php | 2 +- config.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE.php b/LICENSE.php index 353045c..ff69a3f 100644 --- a/LICENSE.php +++ b/LICENSE.php @@ -21,7 +21,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * @version 1.0.6 + * @version 1.0.7 * @link http://www.mailermailer.com/api/index.rwp */ diff --git a/config.php b/config.php index 18b3680..bc66a52 100644 --- a/config.php +++ b/config.php @@ -5,7 +5,7 @@ define('MAILAPI_ENDPOINT', 'https://api.mailermailer.com/1.0/'); -define('MAILAPI_VERSION', '1.0.6'); +define('MAILAPI_VERSION', '1.0.7'); define ('MAILAPI_PARTNER', 'MM'); From fc0fa994aa6ce8a1f0b83e4763019a58c25bcec5 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sun, 3 Apr 2016 22:59:44 -0400 Subject: [PATCH 7/8] Fix up non existent list member test and add bad email test for UnsubMember call --- tests/UnsubMemberTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/UnsubMemberTest.php b/tests/UnsubMemberTest.php index 724319e..1cb2ea9 100644 --- a/tests/UnsubMemberTest.php +++ b/tests/UnsubMemberTest.php @@ -59,6 +59,12 @@ public function testUnsubTwice() } public function testUnsubNonexistentListMember() + { + $response = $this->mailapi->unsubMember("fakeuser@email.com"); + $this->assertEquals(305, $response->getErrorCode()); + } + + public function testUnsubBadEmail() { $response = $this->mailapi->unsubMember("This email doesn't exist"); $this->assertEquals(302, $response->getErrorCode()); From 53e5c169ecfc8b4124ada82a5454e1b0f1193b70 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sun, 3 Apr 2016 23:01:42 -0400 Subject: [PATCH 8/8] Update default timezone for testing --- tests/test_vars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_vars.php b/tests/test_vars.php index c46cb92..24eb628 100644 --- a/tests/test_vars.php +++ b/tests/test_vars.php @@ -12,7 +12,7 @@ exit("Provide the test email address by setting MAILAPI_TEST_EMAIL env variable.\n"); } -date_default_timezone_set('America/New_York'); +date_default_timezone_set('UTC'); $test_apikey = getenv('MAILAPI_KEY');