Browse files

Initial commit

  • Loading branch information...
0 parents commit 2547a9f8bae12f3a33cab39282cade118afed561 @Herzult Herzult committed Mar 24, 2011
Showing with 208 additions and 0 deletions.
  1. +92 −0 DependencyInjection/JirafeMailChimpExtension.php
  2. +18 −0 JirafeMailChimpBundle.php
  3. +21 −0 LICENSE
  4. +60 −0 README.md
  5. +17 −0 Resources/config/mail_chimp.xml
92 DependencyInjection/JirafeMailChimpExtension.php
@@ -0,0 +1,92 @@
+<?php
+
+/*
+ * This file is part of the JirafeMailChimpBundle.
+ *
+ * (c) 2011 Jirafe <http://www.jirafe.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Jirafe\Bundle\MailChimpBundle\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\Extension\Extension;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+class JirafeMailChimpExtension extends Extension
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function load(array $configs, ContainerBuilder $builder)
+ {
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('mail_chimp.xml');
+
+ $config = $this->mergeConfigs($configs);
+
+ if (empty($config['api_key'])) {
+ throw new \Exception('You must define the \'api_key\' parameter in the \'jirafe_mail_chimp\' configuration section.');
+ }
+
+ $builder->setParameter('mail_chimp.api.key', $config['api_key']);
+
+ if (isset($config['secure'])) {
+ $builder->getDefinition('mail_chimp.api');
+ $builder->setParameter(1, $config['secure']);
+ }
+
+ if (isset($config['timeout'])) {
+ $builder->getDefinition('mail_chimp.api');
+ $builder->addMethodCall('setTimeout', array($config['timeout']));
+ }
+ }
+
+ /**
+ * Merges the given configurations
+ *
+ * @param array $configs An array of configurations
+ *
+ * @return array The merged configuration
+ */
+ public function mergeConfigs(array $configs)
+ {
+ $merged = array();
+ foreach ($configs as $config) {
+ if (isset($config['api-key'])) {
+ $merged['api_key'] = $config['api-key'];
+ } else if (isset($config['api_key'])) {
+ $merged['api_key'] = $config['api_key'];
+ }
+
+ if (isset($config['secure'])) {
+ $merged['secure'] = true === $config['secure'] ? true : false;
+ }
+
+ if (isset($config['timeout'])) {
+ $merged['timeout'] = intval($merged['timeout']);
+ }
+ }
+
+ return $merged;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getXsdValidationBasePath()
+ {
+ return __DIR__.'/../Resources/config/schema';
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getNamespace()
+ {
+ return 'http://www.jirafe.com/schema/dic/mail_chimp_bundle';
+ }
+}
18 JirafeMailChimpBundle.php
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * This file is part of the JirafeMailChimpBundle.
+ *
+ * (c) 2011 Jirafe <http://www.jirafe.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Jirafe\Bundle\MailChimpBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle
+
+class JirafeMailChimpBundle extends Bundle
+{
+}
21 LICENSE
@@ -0,0 +1,21 @@
+Copyright (c) 2011 Jirafe
+
+The MIT license
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
60 README.md
@@ -0,0 +1,60 @@
+MailChimpBundle
+===============
+
+The MailChimp API for your Symfony2 projects.
+
+Installation
+------------
+
+First, you need to add the MailChimp library in your project:
+
+ $ git add submodule git://github.com/switzer/mailchimp.git vendor/mailchimp
+
+And the bundle:
+
+ $ git add submodule git://github.com/jirafe/MailChimpBundle.git vendor/bundles/Jirafe/Bundle/MailChimpBundle
+
+Then, add it to the autoloader:
+
+ // app/autoload.php
+ $loader->registerNamespaces(array(
+
+ // ... other namespaces
+
+ 'Jirafe' => __DIR__ . '/../src',
+ 'Mailchimp' => __DIR__ . '/../vendor/mailchimp/src',
+ ));
+
+Add the bundle to your kernel:
+
+ // app/AppKernel.php
+
+ $bundles = array(
+
+ // ... other bundles
+
+ new Jirafe\Bundle\MailChimpBundle\JirafeMailChimpBundle(),
+ );
+
+Finally, configure it:
+
+ # app/config/config.yml
+ # MailChimp Configuration
+ jirafe_mail_chimp:
+ api_key: yourSecretKey # your api key providen by MailChimp
+ secret: false # whether to use the secret mode (optional)
+ timeout: 10 # timeout in seconds (optional)
+
+Usage
+-----
+
+In your controller, you can easily access the MailChimp api:
+
+ // src/FooVendor/Bundle/BarBundle/Controller/DefaultController
+
+ public function foobarAction()
+ {
+ $mailChimp = $this->get('mail_chimp.api');
+
+ $mailChimp->campaignUnschedule($cid);
+ }
17 Resources/config/mail_chimp.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://symfony.com/schema/dic/services"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+ <parameters>
+ <parameter key="mail_chimp.api.class">MailChimp\MCAPI</parameter>
+ <parameter key="mail_chimp.api.key">null</parameter>
+ </parameters>
+
+ <services>
+ <service id="mail_chimp.api" class="%mail_chimp.api.class%">
+ <argument>%mail_chimp.api.key%</argument>
+ </service>
+ </services>
+</container>

0 comments on commit 2547a9f

Please sign in to comment.