From ea5adff6f7b350f8dd37f3df7e53935d1380fd95 Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Tue, 7 Oct 2014 01:29:31 -0400 Subject: [PATCH 1/7] Start support MailChimp API v2. --- Resources/meta/LICENSE => LICENSE | 2 +- Resources/doc/index.rst | 0 .../DependencyInjection}/Configuration.php | 0 .../DependencyInjection}/MZMailChimpExtension.php | 0 MZMailChimpBundle.php => src/MZMailChimpBundle.php | 0 {Resources => src/Resources}/config/schema/mailchimp-1.0.xsd | 0 {Resources => src/Resources}/config/services.xml | 0 {Services => src/Services}/HttpClient.php | 0 {Services => src/Services}/MailChimp.php | 0 {Services => src/Services}/Methods/MCCampaign.php | 0 {Services => src/Services}/Methods/MCEcommerce.php | 0 {Services => src/Services}/Methods/MCExport.php | 0 {Services => src/Services}/Methods/MCList.php | 0 {Tests => src/Tests}/DependencyInjection/ConfigurationTest.php | 0 .../Tests}/DependencyInjection/MZMailChimpExtensionTest.php | 0 {Tests => src/Tests}/Services/MailChimpTest.php | 0 {Tests => src/Tests}/Services/Methods/MCExportTest.php | 0 17 files changed, 1 insertion(+), 1 deletion(-) rename Resources/meta/LICENSE => LICENSE (96%) delete mode 100644 Resources/doc/index.rst rename {DependencyInjection => src/DependencyInjection}/Configuration.php (100%) rename {DependencyInjection => src/DependencyInjection}/MZMailChimpExtension.php (100%) rename MZMailChimpBundle.php => src/MZMailChimpBundle.php (100%) rename {Resources => src/Resources}/config/schema/mailchimp-1.0.xsd (100%) rename {Resources => src/Resources}/config/services.xml (100%) rename {Services => src/Services}/HttpClient.php (100%) rename {Services => src/Services}/MailChimp.php (100%) rename {Services => src/Services}/Methods/MCCampaign.php (100%) rename {Services => src/Services}/Methods/MCEcommerce.php (100%) rename {Services => src/Services}/Methods/MCExport.php (100%) rename {Services => src/Services}/Methods/MCList.php (100%) rename {Tests => src/Tests}/DependencyInjection/ConfigurationTest.php (100%) rename {Tests => src/Tests}/DependencyInjection/MZMailChimpExtensionTest.php (100%) rename {Tests => src/Tests}/Services/MailChimpTest.php (100%) rename {Tests => src/Tests}/Services/Methods/MCExportTest.php (100%) diff --git a/Resources/meta/LICENSE b/LICENSE similarity index 96% rename from Resources/meta/LICENSE rename to LICENSE index 718b318..d3d5470 100644 --- a/Resources/meta/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011 Miguel Perez +Copyright (c) 2014 Miguel Perez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst deleted file mode 100644 index e69de29..0000000 diff --git a/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php similarity index 100% rename from DependencyInjection/Configuration.php rename to src/DependencyInjection/Configuration.php diff --git a/DependencyInjection/MZMailChimpExtension.php b/src/DependencyInjection/MZMailChimpExtension.php similarity index 100% rename from DependencyInjection/MZMailChimpExtension.php rename to src/DependencyInjection/MZMailChimpExtension.php diff --git a/MZMailChimpBundle.php b/src/MZMailChimpBundle.php similarity index 100% rename from MZMailChimpBundle.php rename to src/MZMailChimpBundle.php diff --git a/Resources/config/schema/mailchimp-1.0.xsd b/src/Resources/config/schema/mailchimp-1.0.xsd similarity index 100% rename from Resources/config/schema/mailchimp-1.0.xsd rename to src/Resources/config/schema/mailchimp-1.0.xsd diff --git a/Resources/config/services.xml b/src/Resources/config/services.xml similarity index 100% rename from Resources/config/services.xml rename to src/Resources/config/services.xml diff --git a/Services/HttpClient.php b/src/Services/HttpClient.php similarity index 100% rename from Services/HttpClient.php rename to src/Services/HttpClient.php diff --git a/Services/MailChimp.php b/src/Services/MailChimp.php similarity index 100% rename from Services/MailChimp.php rename to src/Services/MailChimp.php diff --git a/Services/Methods/MCCampaign.php b/src/Services/Methods/MCCampaign.php similarity index 100% rename from Services/Methods/MCCampaign.php rename to src/Services/Methods/MCCampaign.php diff --git a/Services/Methods/MCEcommerce.php b/src/Services/Methods/MCEcommerce.php similarity index 100% rename from Services/Methods/MCEcommerce.php rename to src/Services/Methods/MCEcommerce.php diff --git a/Services/Methods/MCExport.php b/src/Services/Methods/MCExport.php similarity index 100% rename from Services/Methods/MCExport.php rename to src/Services/Methods/MCExport.php diff --git a/Services/Methods/MCList.php b/src/Services/Methods/MCList.php similarity index 100% rename from Services/Methods/MCList.php rename to src/Services/Methods/MCList.php diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/src/Tests/DependencyInjection/ConfigurationTest.php similarity index 100% rename from Tests/DependencyInjection/ConfigurationTest.php rename to src/Tests/DependencyInjection/ConfigurationTest.php diff --git a/Tests/DependencyInjection/MZMailChimpExtensionTest.php b/src/Tests/DependencyInjection/MZMailChimpExtensionTest.php similarity index 100% rename from Tests/DependencyInjection/MZMailChimpExtensionTest.php rename to src/Tests/DependencyInjection/MZMailChimpExtensionTest.php diff --git a/Tests/Services/MailChimpTest.php b/src/Tests/Services/MailChimpTest.php similarity index 100% rename from Tests/Services/MailChimpTest.php rename to src/Tests/Services/MailChimpTest.php diff --git a/Tests/Services/Methods/MCExportTest.php b/src/Tests/Services/Methods/MCExportTest.php similarity index 100% rename from Tests/Services/Methods/MCExportTest.php rename to src/Tests/Services/Methods/MCExportTest.php From a71ad2635d55a4c96b6ff790f74f02c813f1d3a0 Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Tue, 7 Oct 2014 01:32:14 -0400 Subject: [PATCH 2/7] Update composer.json autoload path. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1273c18..6db571a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-curl": "*" }, "autoload": { - "psr-0": { "MZ\\MailChimpBundle": "" } + "psr-0": { "MZ\\MailChimpBundle": "src/" } }, "target-dir": "MZ/MailChimpBundle" } From c625c177c6bbed0945dd7c61c446d138ddac4b21 Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Sun, 12 Oct 2014 22:45:08 -0400 Subject: [PATCH 3/7] Revert directory structure --- .../Configuration.php | 0 .../MZMailChimpExtension.php | 0 src/MZMailChimpBundle.php => MZMailChimpBundle.php | 0 {src/Resources => Resources}/config/schema/mailchimp-1.0.xsd | 0 {src/Resources => Resources}/config/services.xml | 0 {src/Services => Services}/HttpClient.php | 0 {src/Services => Services}/MailChimp.php | 4 +--- {src/Services => Services}/Methods/MCCampaign.php | 0 {src/Services => Services}/Methods/MCEcommerce.php | 0 {src/Services => Services}/Methods/MCExport.php | 0 {src/Services => Services}/Methods/MCList.php | 0 .../Tests => Tests}/DependencyInjection/ConfigurationTest.php | 0 .../DependencyInjection/MZMailChimpExtensionTest.php | 0 {src/Tests => Tests}/Services/MailChimpTest.php | 0 {src/Tests => Tests}/Services/Methods/MCExportTest.php | 0 15 files changed, 1 insertion(+), 3 deletions(-) rename {src/DependencyInjection => DependencyInjection}/Configuration.php (100%) rename {src/DependencyInjection => DependencyInjection}/MZMailChimpExtension.php (100%) rename src/MZMailChimpBundle.php => MZMailChimpBundle.php (100%) rename {src/Resources => Resources}/config/schema/mailchimp-1.0.xsd (100%) rename {src/Resources => Resources}/config/services.xml (100%) rename {src/Services => Services}/HttpClient.php (100%) rename {src/Services => Services}/MailChimp.php (94%) rename {src/Services => Services}/Methods/MCCampaign.php (100%) rename {src/Services => Services}/Methods/MCEcommerce.php (100%) rename {src/Services => Services}/Methods/MCExport.php (100%) rename {src/Services => Services}/Methods/MCList.php (100%) rename {src/Tests => Tests}/DependencyInjection/ConfigurationTest.php (100%) rename {src/Tests => Tests}/DependencyInjection/MZMailChimpExtensionTest.php (100%) rename {src/Tests => Tests}/Services/MailChimpTest.php (100%) rename {src/Tests => Tests}/Services/Methods/MCExportTest.php (100%) diff --git a/src/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php similarity index 100% rename from src/DependencyInjection/Configuration.php rename to DependencyInjection/Configuration.php diff --git a/src/DependencyInjection/MZMailChimpExtension.php b/DependencyInjection/MZMailChimpExtension.php similarity index 100% rename from src/DependencyInjection/MZMailChimpExtension.php rename to DependencyInjection/MZMailChimpExtension.php diff --git a/src/MZMailChimpBundle.php b/MZMailChimpBundle.php similarity index 100% rename from src/MZMailChimpBundle.php rename to MZMailChimpBundle.php diff --git a/src/Resources/config/schema/mailchimp-1.0.xsd b/Resources/config/schema/mailchimp-1.0.xsd similarity index 100% rename from src/Resources/config/schema/mailchimp-1.0.xsd rename to Resources/config/schema/mailchimp-1.0.xsd diff --git a/src/Resources/config/services.xml b/Resources/config/services.xml similarity index 100% rename from src/Resources/config/services.xml rename to Resources/config/services.xml diff --git a/src/Services/HttpClient.php b/Services/HttpClient.php similarity index 100% rename from src/Services/HttpClient.php rename to Services/HttpClient.php diff --git a/src/Services/MailChimp.php b/Services/MailChimp.php similarity index 94% rename from src/Services/MailChimp.php rename to Services/MailChimp.php index 7c7bb94..4ded118 100644 --- a/src/Services/MailChimp.php +++ b/Services/MailChimp.php @@ -31,15 +31,13 @@ class MailChimp */ public function __construct($apiKey, $listId, $ssl = true) { - trigger_error("API v1 has being deprecated by MailChimp. A new version of this bundle is being work on.", E_USER_DEPRECATED); - $this->apiKey = $apiKey; $this->listId = $listId; $key = preg_split("/-/", $this->apiKey); if($ssl) { - $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/'; + $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/2.0/'; }else { $this->dataCenter ='http://' . $key[1] . '.api.mailchimp.com/'; } diff --git a/src/Services/Methods/MCCampaign.php b/Services/Methods/MCCampaign.php similarity index 100% rename from src/Services/Methods/MCCampaign.php rename to Services/Methods/MCCampaign.php diff --git a/src/Services/Methods/MCEcommerce.php b/Services/Methods/MCEcommerce.php similarity index 100% rename from src/Services/Methods/MCEcommerce.php rename to Services/Methods/MCEcommerce.php diff --git a/src/Services/Methods/MCExport.php b/Services/Methods/MCExport.php similarity index 100% rename from src/Services/Methods/MCExport.php rename to Services/Methods/MCExport.php diff --git a/src/Services/Methods/MCList.php b/Services/Methods/MCList.php similarity index 100% rename from src/Services/Methods/MCList.php rename to Services/Methods/MCList.php diff --git a/src/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php similarity index 100% rename from src/Tests/DependencyInjection/ConfigurationTest.php rename to Tests/DependencyInjection/ConfigurationTest.php diff --git a/src/Tests/DependencyInjection/MZMailChimpExtensionTest.php b/Tests/DependencyInjection/MZMailChimpExtensionTest.php similarity index 100% rename from src/Tests/DependencyInjection/MZMailChimpExtensionTest.php rename to Tests/DependencyInjection/MZMailChimpExtensionTest.php diff --git a/src/Tests/Services/MailChimpTest.php b/Tests/Services/MailChimpTest.php similarity index 100% rename from src/Tests/Services/MailChimpTest.php rename to Tests/Services/MailChimpTest.php diff --git a/src/Tests/Services/Methods/MCExportTest.php b/Tests/Services/Methods/MCExportTest.php similarity index 100% rename from src/Tests/Services/Methods/MCExportTest.php rename to Tests/Services/Methods/MCExportTest.php From b1a01d4fb0b14126cc23615f7bda49ccea331412 Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Mon, 13 Oct 2014 00:08:40 -0400 Subject: [PATCH 4/7] Add support for versioning. --- {Services => Lib}/HttpClient.php | 25 ++-- Lib/v1/MailChimp.php | 129 ++++++++++++++++++ {Services => Lib/v1}/Methods/MCCampaign.php | 4 +- {Services => Lib/v1}/Methods/MCEcommerce.php | 4 +- {Services => Lib/v1}/Methods/MCExport.php | 4 +- {Services => Lib/v1}/Methods/MCList.php | 4 +- {Services => Lib/v2}/MailChimp.php | 4 +- Resources/config/services.xml | 5 +- Tests/{Services => lib/v1}/MailChimpTest.php | 4 +- .../v1}/Methods/MCExportTest.php | 9 +- 10 files changed, 166 insertions(+), 26 deletions(-) rename {Services => Lib}/HttpClient.php (73%) create mode 100644 Lib/v1/MailChimp.php rename {Services => Lib/v1}/Methods/MCCampaign.php (99%) rename {Services => Lib/v1}/Methods/MCEcommerce.php (98%) rename {Services => Lib/v1}/Methods/MCExport.php (91%) rename {Services => Lib/v1}/Methods/MCList.php (98%) rename {Services => Lib/v2}/MailChimp.php (98%) rename Tests/{Services => lib/v1}/MailChimpTest.php (94%) rename Tests/{Services => lib/v1}/Methods/MCExportTest.php (90%) diff --git a/Services/HttpClient.php b/Lib/HttpClient.php similarity index 73% rename from Services/HttpClient.php rename to Lib/HttpClient.php index d502839..8d84a0b 100644 --- a/Services/HttpClient.php +++ b/Lib/HttpClient.php @@ -9,13 +9,12 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services; +namespace MZ\MailChimpBundle\Lib; -use Buzz\Browser, - Buzz\Client\Curl; +Use \Curl; /** - * HTTP client + * HTTP Client * * @author Miguel Perez */ @@ -58,12 +57,20 @@ protected function makeRequest($apiCall, $payload, $export = false) } else { $url = $this->dataCenter . '1.3/?method=' . $apiCall; } - $curl = new Curl(); - $curl->setOption(CURLOPT_USERAGENT, 'MZMailChimpBundle'); - $browser = new Browser($curl); - $response = $browser->post($url, array(), http_build_query($payload)); - return $response->getContent(); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, "MZMailChimpBundle"); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload)); + + $result = curl_exec($ch); + curl_close($ch); + + var_dump($result); + + return $result; } } diff --git a/Lib/v1/MailChimp.php b/Lib/v1/MailChimp.php new file mode 100644 index 0000000..ab3e62a --- /dev/null +++ b/Lib/v1/MailChimp.php @@ -0,0 +1,129 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace MZ\MailChimpBundle\Lib\v1; + +/** + * Mailchimp + * + * @author Miguel Perez + */ +class MailChimp +{ + + private $apiKey; + private $listId; + private $dataCenter; + + /** + * Initializes MailChimp + * + * @param string $apiKey Mailchimp api key + * @param string $listId Default mailing list id + */ + public function __construct($apiKey, $listId, $ssl = true) + { + $this->apiKey = $apiKey; + $this->listId = $listId; + + $key = preg_split("/-/", $this->apiKey); + + if($ssl) { + $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/'; + }else { + $this->dataCenter ='http://' . $key[1] . '.api.mailchimp.com/'; + } + + if (!function_exists('curl_init')) { + throw new \Exception('This bundle needs the cURL PHP extension.'); + } + } + + /** + * Get Mailchimp api key + * + * @return string + */ + public function getAPIkey() + { + return $this->apiKey; + } + + /** + * Set mailing list id + * + * @param string $listId mailing list id + */ + public function setListID($listId) + { + $this->listId = $listId; + } + + /** + * get mailing list id + * + * @return string $listId + */ + public function getListID() + { + return $this->listId; + } + + /** + * get datacenter + * + * @return string $datacenter + */ + public function getDatacenter() + { + return $this->dataCenter; + } + + /** + * Get List Methods + * + * @return Methods\MCList + */ + public function getList() + { + return new Methods\MCList($this->apiKey, $this->listId, $this->dataCenter); + } + + /** + * Get List Methods + * + * @return Methods\MCCampaign + */ + public function getCampaign() + { + return new Methods\MCCampaign($this->apiKey, $this->listId, $this->dataCenter); + } + + /** + * Get Export API + * + * @return Methods\MCExport + */ + public function getExport() + { + return new Methods\MCExport($this->apiKey, $this->listId, $this->dataCenter); + } + + /** + * Get Ecommerce Methods + * + * @return Methods\MCEcommerce + */ + public function getEcommerce() + { + return new Methods\MCEcommerce($this->apiKey, $this->listId, $this->dataCenter); + } +} diff --git a/Services/Methods/MCCampaign.php b/Lib/v1/Methods/MCCampaign.php similarity index 99% rename from Services/Methods/MCCampaign.php rename to Lib/v1/Methods/MCCampaign.php index 0fe6819..277601e 100644 --- a/Services/Methods/MCCampaign.php +++ b/Lib/v1/Methods/MCCampaign.php @@ -9,9 +9,9 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services\Methods; +namespace MZ\MailChimpBundle\Lib\v1\Methods; -use MZ\MailChimpBundle\Services\HttpClient; +use MZ\MailChimpBundle\Lib\HttpClient; /** * Mailchimp Campagin method diff --git a/Services/Methods/MCEcommerce.php b/Lib/v1/Methods/MCEcommerce.php similarity index 98% rename from Services/Methods/MCEcommerce.php rename to Lib/v1/Methods/MCEcommerce.php index 24eb0a9..dc3a9a6 100644 --- a/Services/Methods/MCEcommerce.php +++ b/Lib/v1/Methods/MCEcommerce.php @@ -9,9 +9,9 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services\Methods; +namespace MZ\MailChimpBundle\Lib\v1\Methods; -use MZ\MailChimpBundle\Services\HttpClient; +use MZ\MailChimpBundle\Lib\HttpClient; /** * Mailchimp Ecommerce methods diff --git a/Services/Methods/MCExport.php b/Lib/v1/Methods/MCExport.php similarity index 91% rename from Services/Methods/MCExport.php rename to Lib/v1/Methods/MCExport.php index 92c768d..55117e8 100644 --- a/Services/Methods/MCExport.php +++ b/Lib/v1/Methods/MCExport.php @@ -9,9 +9,9 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services\Methods; +namespace MZ\MailChimpBundle\Lib\v1\Methods; -use MZ\MailChimpBundle\Services\HttpClient; +use MZ\MailChimpBundle\Lib\HttpClient; /** * Mailchimp Export api diff --git a/Services/Methods/MCList.php b/Lib/v1/Methods/MCList.php similarity index 98% rename from Services/Methods/MCList.php rename to Lib/v1/Methods/MCList.php index 4c46bf0..f243e51 100755 --- a/Services/Methods/MCList.php +++ b/Lib/v1/Methods/MCList.php @@ -9,9 +9,9 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services\Methods; +namespace MZ\MailChimpBundle\Lib\v1\Methods; -use MZ\MailChimpBundle\Services\HttpClient; +use MZ\MailChimpBundle\Lib\HttpClient; /** * Mailchimp List method diff --git a/Services/MailChimp.php b/Lib/v2/MailChimp.php similarity index 98% rename from Services/MailChimp.php rename to Lib/v2/MailChimp.php index 4ded118..733f3d6 100644 --- a/Services/MailChimp.php +++ b/Lib/v2/MailChimp.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Services; +namespace MZ\MailChimpBundle\Lib; /** * Mailchimp @@ -39,7 +39,7 @@ public function __construct($apiKey, $listId, $ssl = true) if($ssl) { $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/2.0/'; }else { - $this->dataCenter ='http://' . $key[1] . '.api.mailchimp.com/'; + $this->dataCenter ='http://' . $key[1] . '.api.mailchimp.com/2.0/'; } if (!function_exists('curl_init')) { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index ba1ba1d..2538ca0 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -8,11 +8,12 @@ null null true - MZ\MailChimpBundle\Services\MailChimp + MZ\MailChimpBundle\Lib\v1\MailChimp + MZ\MailChimpBundle\Lib\v2\MailChimp - + %mz_mail_chimp.api_key% %mz_mail_chimp.default_list% %mz_mail_chimp.ssl% diff --git a/Tests/Services/MailChimpTest.php b/Tests/lib/v1/MailChimpTest.php similarity index 94% rename from Tests/Services/MailChimpTest.php rename to Tests/lib/v1/MailChimpTest.php index 68a38e7..97e40c7 100644 --- a/Tests/Services/MailChimpTest.php +++ b/Tests/lib/v1/MailChimpTest.php @@ -9,9 +9,9 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Tests\Services; +namespace MZ\MailChimpBundle\Tests\v1; -use MZ\MailChimpBundle\Services\MailChimp; +use MZ\MailChimpBundle\Lib\v1\MailChimp; /** * Test mailchimp diff --git a/Tests/Services/Methods/MCExportTest.php b/Tests/lib/v1/Methods/MCExportTest.php similarity index 90% rename from Tests/Services/Methods/MCExportTest.php rename to Tests/lib/v1/Methods/MCExportTest.php index cf996be..6e65e4a 100644 --- a/Tests/Services/Methods/MCExportTest.php +++ b/Tests/lib/v1/Methods/MCExportTest.php @@ -7,8 +7,11 @@ * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ -use MZ\MailChimpBundle\Services\HttpClient; -use MZ\MailChimpBundle\Services\Methods\MCExport; + +namespace MZ\MailChimpBundle\Tests\v1\Methods; + +use MZ\MailChimpBundle\Lib\HttpClient; +use MZ\MailChimpBundle\Lib\v1\MCExport; /** * Test Mailchimp Export Class * @@ -41,7 +44,7 @@ public function testDumpList() ) ); - $export = $this->getMock('MZ\MailChimpBundle\Services\Methods\MCExport', + $export = $this->getMock('MZ\MailChimpBundle\Lib\v1\Methods\MCExport', array('makeRequest'), array(), '', From 204707e70f45ad9fac78a0536d95a69c7c90a79a Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Mon, 13 Oct 2014 00:21:03 -0400 Subject: [PATCH 5/7] Add deprecating message back. --- Lib/v1/MailChimp.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/v1/MailChimp.php b/Lib/v1/MailChimp.php index ab3e62a..53e608d 100644 --- a/Lib/v1/MailChimp.php +++ b/Lib/v1/MailChimp.php @@ -35,6 +35,8 @@ public function __construct($apiKey, $listId, $ssl = true) $this->listId = $listId; $key = preg_split("/-/", $this->apiKey); + + trigger_error("API v1 has being deprecated by MailChimp. Please use `Mailchimp.v2` service.", E_USER_DEPRECATED); if($ssl) { $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/'; From 081b5e22f86ff09229aaba70424f0f374ff5ccca Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Mon, 13 Oct 2014 00:21:24 -0400 Subject: [PATCH 6/7] Ignore composer.lock --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0669f6d..5210f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor -.DS_Store \ No newline at end of file +.DS_Store +composer.lock \ No newline at end of file From 6c3763e63e40b3b15763cfcb20d8217a0b0cae51 Mon Sep 17 00:00:00 2001 From: Miguel Perez Date: Mon, 13 Oct 2014 00:43:13 -0400 Subject: [PATCH 7/7] Remove deprecating tests and add new service name. --- Lib/v2/MailChimp.php | 53 +++++---------------- Resources/config/services.xml | 5 ++ Tests/lib/v1/MailChimpTest.php | 66 --------------------------- Tests/lib/v1/Methods/MCExportTest.php | 64 -------------------------- 4 files changed, 16 insertions(+), 172 deletions(-) delete mode 100644 Tests/lib/v1/MailChimpTest.php delete mode 100644 Tests/lib/v1/Methods/MCExportTest.php diff --git a/Lib/v2/MailChimp.php b/Lib/v2/MailChimp.php index 733f3d6..48231f7 100644 --- a/Lib/v2/MailChimp.php +++ b/Lib/v2/MailChimp.php @@ -9,14 +9,14 @@ * with this source code in the file LICENSE. */ -namespace MZ\MailChimpBundle\Lib; +namespace MZ\MailChimpBundle\Lib\v2; /** * Mailchimp * * @author Miguel Perez */ -class MailChimp +class MailChimp { private $apiKey; @@ -34,7 +34,7 @@ public function __construct($apiKey, $listId, $ssl = true) $this->apiKey = $apiKey; $this->listId = $listId; - $key = preg_split("/-/", $this->apiKey); + $key = $this->setDataCenter($apiKey); if($ssl) { $this->dataCenter ='https://' . $key[1] . '.api.mailchimp.com/2.0/'; @@ -76,54 +76,23 @@ public function getListID() { return $this->listId; } - - /** - * get datacenter - * - * @return string $datacenter - */ - public function getDatacenter() - { - return $this->dataCenter; - } /** - * Get List Methods + * Set datacenter * - * @return Methods\MCList + * @param string $apiKey API key */ - public function getList() - { - return new Methods\MCList($this->apiKey, $this->listId, $this->dataCenter); - } - - /** - * Get List Methods - * - * @return Methods\MCCampaign - */ - public function getCampaign() - { - return new Methods\MCCampaign($this->apiKey, $this->listId, $this->dataCenter); - } - - /** - * Get Export API - * - * @return Methods\MCExport - */ - public function getExport() - { - return new Methods\MCExport($this->apiKey, $this->listId, $this->dataCenter); + private function setDataCenter($apiKey){ + $this->dataCenter = preg_split("/-/", $apiKey); } /** - * Get Ecommerce Methods + * get datacenter * - * @return Methods\MCEcommerce + * @return string $dataCenter */ - public function getEcommerce() + public function getDataCenter() { - return new Methods\MCEcommerce($this->apiKey, $this->listId, $this->dataCenter); + return $this->dataCenter; } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 2538ca0..ff7f2fe 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -18,6 +18,11 @@ %mz_mail_chimp.default_list% %mz_mail_chimp.ssl% + + %mz_mail_chimp.api_key% + %mz_mail_chimp.default_list% + %mz_mail_chimp.ssl% + diff --git a/Tests/lib/v1/MailChimpTest.php b/Tests/lib/v1/MailChimpTest.php deleted file mode 100644 index 97e40c7..0000000 --- a/Tests/lib/v1/MailChimpTest.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace MZ\MailChimpBundle\Tests\v1; - -use MZ\MailChimpBundle\Lib\v1\MailChimp; - -/** - * Test mailchimp - * - * @author Miguel Perez - */ -class MailChimpTest extends \PHPUnit_Framework_TestCase -{ - /** - * Test MailChimp constructor - * - * @covers MZ\MailChimpBundle\Services\MailChimp::__construct - */ - public function testMailChimpConstruct() - { - $mailchimp = new MailChimp('23212312-us2', '12b6c7e6c4'); - - $this->assertEquals('23212312-us2', $mailchimp->getAPIkey()); - $this->assertEquals('12b6c7e6c4', $mailchimp->getListID()); - - } - - /** - * Test MailChimp constructor - * - * @covers MZ\MailChimpBundle\Services\MailChimp::__construct - */ - public function testDatacenter() - { - $mailchimp = new MailChimp('23212312-us2', '12b6c7e6c4', true); - - $this->assertEquals('https://us2.api.mailchimp.com/', $mailchimp->getDatacenter()); - - $mailchimp2 = new MailChimp('23212312-us2', '12b6c7e6c4', false); - - $this->assertEquals('http://us2.api.mailchimp.com/', $mailchimp2->getDatacenter()); - - } - - /** - * Test ListID - * - * @covers MZ\MailChimpBundle\Services\MailChimp::setListID - */ - public function testListID() - { - $mailchimp = new MailChimp('23212312-us2', '12b6c7e6c5'); - - $mailchimp->setListID('12b6c7e6c4'); - $this->assertEquals('12b6c7e6c4', $mailchimp->getListID()); - } -} diff --git a/Tests/lib/v1/Methods/MCExportTest.php b/Tests/lib/v1/Methods/MCExportTest.php deleted file mode 100644 index 6e65e4a..0000000 --- a/Tests/lib/v1/Methods/MCExportTest.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace MZ\MailChimpBundle\Tests\v1\Methods; - -use MZ\MailChimpBundle\Lib\HttpClient; -use MZ\MailChimpBundle\Lib\v1\MCExport; -/** - * Test Mailchimp Export Class - * - * @author Miguel Perez - */ -class MCExportTest extends \PHPUnit_Framework_TestCase -{ - public function testDumpList() - { - $expect = array( - 0 => array( - 'Email Address' => 'test@gmail.com', - 'First Name' => 'test', - 'Last Name' => 'test', - 'Skills' => 'Both', - 'testing' => '', - 'MEMBER_RATING' => 2, - 'OPTIN_TIME' => '2012-07-03 21:47:23', - 'OPTIN_IP' => '24.189.148.246', - 'CONFIRM_TIME' => '2012-07-03 21:47:31', - 'CONFIRM_IP' => '24.189.148.246', - 'LATITUDE' => '40.8090000', - 'LONGITUDE' => '-73.9168000', - 'GMTOFF' => '-5', - 'DSTOFF' => '-4', - 'TIMEZONE' => 'America/New_York', - 'CC' => 'US', - 'REGION' => 'NY', - 'LAST_CHANGED' => '2012-07-03 21:47:31' - ) - ); - - $export = $this->getMock('MZ\MailChimpBundle\Lib\v1\Methods\MCExport', - array('makeRequest'), - array(), - '', - false, - false, - true); - - $reponse = <<expects($this->any())->method('makeRequest')->will($this->returnValue($reponse)); - $dump = $export->DumpList(); - - $this->assertEquals($expect, $dump); - } -}