-
Notifications
You must be signed in to change notification settings - Fork 5
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 #8 from MikaFima/feature/update-mailchimp-client
Feature/update mailchimp client
- Loading branch information
Showing
8 changed files
with
217 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
require_once __DIR__.'/vendor/autoload.php'; |
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,11 @@ | ||
<?php | ||
|
||
use \mageekguy\atoum; | ||
|
||
$cliReport = $script->addDefaultReport(); | ||
$cliReport->addField(new atoum\report\fields\runner\result\logo()); | ||
$runner->addReport($cliReport); | ||
|
||
$script->bootstrapFile(__DIR__ . DIRECTORY_SEPARATOR . '.atoum.bootstrap.php'); | ||
|
||
$runner->addTestsFromDirectory(__DIR__.'/Tests/Units'); |
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,2 @@ | ||
# Symfony directories | ||
vendor/* |
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,12 @@ | ||
language: php | ||
php: | ||
- 5.3 | ||
- 5.5 | ||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- COMPOSER_ROOT_VERSION=dev-master php composer.phar install --dev | ||
script: | ||
- bin/atoum | ||
notifications: | ||
email: | ||
- [email protected] |
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 |
---|---|---|
|
@@ -3,16 +3,16 @@ | |
namespace Rezzza\MailChimpBundle\Api; | ||
|
||
use Rezzza\MailChimpBundle\Connection\ConnectionInterface; | ||
use Rezzza\MailChimp\MCAPI; | ||
|
||
/** | ||
* Client | ||
* | ||
* @uses MCAPI | ||
* @uses \Mailchimp | ||
* @author Sébastien HOUZÉ <[email protected]> | ||
*/ | ||
class Client extends MCAPI | ||
class Client extends \Mailchimp | ||
{ | ||
|
||
protected $connection; | ||
protected $lastRequest; | ||
protected $lastResponse; | ||
|
@@ -24,9 +24,11 @@ class Client extends MCAPI | |
*/ | ||
public function __construct($apiKey) | ||
{ | ||
parent::__construct($apiKey); | ||
parent::__construct($apiKey, array( | ||
'CURLOPT_FOLLOWLOCATION' => true, | ||
)); | ||
|
||
$this->lastRequest = null; | ||
$this->lastRequest = null; | ||
$this->lastResponse = null; | ||
} | ||
|
||
|
@@ -53,10 +55,10 @@ public function getConnection() | |
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function callServer($method, $params) | ||
public function call($method, $params) | ||
{ | ||
$request = new Request($method, $params); | ||
$response = $this->call($request); | ||
$request = new Request($method, $params); | ||
$response = $this->callServer($request); | ||
|
||
return $response->getContent(); | ||
} | ||
|
@@ -68,23 +70,23 @@ public function callServer($method, $params) | |
* | ||
* @return Response | ||
*/ | ||
public function call(Request $request) | ||
private function callServer(Request $request) | ||
{ | ||
$this->errorMessage = null; | ||
$this->errorCode = null; | ||
$this->errorCode = null; | ||
|
||
$request->setParam('apikey', $this->api_key); | ||
$request->setParam('apikey', $this->apikey); | ||
|
||
$response = $this->connection->execute($request); | ||
|
||
if ($response->isError()) { | ||
$content = $response->getContent(); | ||
|
||
$this->errorMessage = $content['error']; | ||
$this->errorCode = $content['code']; | ||
$this->errorCode = $content['code']; | ||
} | ||
|
||
$this->lastRequest = $request; | ||
$this->lastRequest = $request; | ||
$this->lastResponse = $response; | ||
|
||
return $response; | ||
|
@@ -109,4 +111,5 @@ public function getLastResponse() | |
{ | ||
return $this->lastResponse; | ||
} | ||
|
||
} |
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,149 @@ | ||
<?php | ||
|
||
namespace Rezzza\MailChimpBundle\Tests\Units\Api; | ||
|
||
/** | ||
* Description of HttpConnection | ||
* | ||
* @author mika | ||
*/ | ||
class Client extends \mageekguy\atoum\test | ||
{ | ||
const CUSTOMER_LIST_ID = 'db993d96da'; | ||
|
||
private $customerEmail; | ||
|
||
/** | ||
* Test batch-subscribe success | ||
*/ | ||
public function testBatchSubscribeSuccess() | ||
{ | ||
$response = $this->getClient()->call('lists/batch-subscribe', $this->getBatchSubscribeParameters()); | ||
$this->array($response)->isNotEmpty()->notHasKey('error'); | ||
} | ||
|
||
/** | ||
* Test batch-subscribe fail | ||
*/ | ||
public function testBatchSubscribeFail() | ||
{ | ||
$response = $this->getClient()->call('lists/batch-subscribe', array_merge($this->getBatchSubscribeParameters(), array('id' => 'victor_samuel_mackey'))); | ||
$this->array($response)->isNotEmpty()->hasKey('error'); | ||
} | ||
|
||
/** | ||
* Test batch-unsubscribe success | ||
*/ | ||
public function testBatchUnsubscribeSuccess() | ||
{ | ||
$response = $this->getClient()->call('lists/batch-unsubscribe', $this->getBatchUnsubscribeParameters()); | ||
$this->array($response)->isNotEmpty()->notHasKey('error'); | ||
} | ||
|
||
/** | ||
* Test batch-unsubscribe fail | ||
*/ | ||
public function testBatchUnsubscribeFail() | ||
{ | ||
$response = $this->getClient()->call('lists/batch-unsubscribe', array_merge($this->getBatchUnsubscribeParameters(), array('id' => 'victor_samuel_mackey'))); | ||
$this->array($response)->isNotEmpty()->hasKey('error'); | ||
} | ||
|
||
/** | ||
* Get MailChimp Client | ||
* @return \Rezzza\MailChimpBundle\Api\Client | ||
*/ | ||
private function getClient() | ||
{ | ||
$client = new \Rezzza\MailChimpBundle\Api\Client('e90c270f8cf2cfbb2d5c14a36ba884c2-us9'); | ||
$client->setConnection(new \Rezzza\MailChimpBundle\Connection\HttpConnection(true)); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* Parameters for subscribe method | ||
* @return array | ||
*/ | ||
private function getBatchSubscribeParameters() | ||
{ | ||
return array( | ||
'id' => self::CUSTOMER_LIST_ID, | ||
'batch' => array( | ||
array( | ||
'email' => array('email' => $this->getEmail()), | ||
'email_type' => $this->getEmailType(), | ||
'merge_vars' => $this->getMergeVars(), | ||
), | ||
), | ||
"double_optin" => false, | ||
"update_existing" => true, | ||
"replace_interests" => true | ||
); | ||
} | ||
|
||
/** | ||
* Parameters for unsubscribe method | ||
* @return array | ||
*/ | ||
private function getBatchUnsubscribeParameters() | ||
{ | ||
return array( | ||
'id' => self::CUSTOMER_LIST_ID, | ||
'batch' => array( | ||
array( | ||
'email' => $this->getEmail(), | ||
), | ||
), | ||
"delete_member" => false, | ||
"send_goodbye" => false, | ||
"send_notify" => false, | ||
); | ||
} | ||
|
||
/** | ||
* Customer email | ||
* @return string | ||
*/ | ||
private function getEmail() | ||
{ | ||
if (is_null($this->customerEmail) === true) { | ||
$this->customerEmail = 'mika+mailchimptest'.time().'@verylastroom.com'; | ||
} | ||
|
||
return $this->customerEmail; | ||
} | ||
|
||
/** | ||
* Customer email type | ||
* @return string | ||
*/ | ||
private function getEmailType() | ||
{ | ||
return 'html'; | ||
} | ||
|
||
/** | ||
* Customer merge_vars | ||
* @return array | ||
*/ | ||
private function getMergeVars() | ||
{ | ||
return array( | ||
'FNAME' => 'john', | ||
'LNAME' => 'doe', | ||
'GENDER' => 'Male', | ||
'LOCALE' => 'fr', | ||
'SIGNUPVIA' => 'EMAIL', | ||
'PHONE' => '0606060606', | ||
'CREDIT' => 30, | ||
'CREATEDAT' => date('Y-m-d H:i:s'), | ||
'UPDATEDAT' => date('Y-m-d H:i:s'), | ||
'APP_VER' => null, | ||
'APP_OS' => null, | ||
'REF_CODE' => 'JDOE', | ||
'CREDIT_EXP' => date('Y-m-d H:i:s'), | ||
); | ||
} | ||
|
||
} |
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