├── tests └── .gitkeep ├── .gitignore ├── .travis.yml ├── src ├── config │ └── config.php └── Hugofirth │ └── Mailchimp │ ├── MailchimpServiceProvider.php │ ├── Facades │ └── MailchimpWrapper.php │ └── MailchimpWrapper.php ├── phpunit.xml ├── composer.json └── README.md /tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | 'your-key-here', 18 | 19 | 20 | ); 21 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hugofirth/mailchimp", 3 | "description": "Wrapper on the Mailchimp class provided by Mailchimp - with support for Laravel 4. v2.0.0 supports Mailchimp API verion 2.0", 4 | "keywords": ["laravel", "mailchimp"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Hugo Firth", 9 | "email": "hebfirth@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.3.0", 14 | "illuminate/support": "4.*|5.0.*", 15 | "mailchimp/mailchimp": "2.0.*" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "Hugofirth\\Mailchimp": "src/" 20 | } 21 | }, 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "2.0-dev" 25 | } 26 | }, 27 | "minimum-stability": "dev" 28 | } 29 | -------------------------------------------------------------------------------- /src/Hugofirth/Mailchimp/MailchimpServiceProvider.php: -------------------------------------------------------------------------------- 1 | package('hugofirth/mailchimp'); 24 | } 25 | 26 | /** 27 | * Register the service provider. 28 | * 29 | * @return void 30 | */ 31 | public function register() 32 | { 33 | $this->app->singleton('mailchimp_wrapper', function() { 34 | $mc = new Mailchimp(Config::get('mailchimp::apikey')); 35 | 36 | return new MailchimpWrapper($mc); 37 | }); 38 | } 39 | 40 | /** 41 | * Get the services provided by the provider. 42 | * 43 | * @return array 44 | */ 45 | public function provides() 46 | { 47 | return array('mailchimp_wrapper'); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Hugofirth/Mailchimp/Facades/MailchimpWrapper.php: -------------------------------------------------------------------------------- 1 | mc = $mc; 48 | } 49 | 50 | /** 51 | * Proxies call to the underlying MailChimp API 52 | * 53 | * @param $method 54 | * @param array $args 55 | * @return mixed 56 | */ 57 | public function __call($method, array $args) 58 | { 59 | //If it's a method, call it 60 | if(method_exists($this->mc, $method)) 61 | { 62 | return call_user_func_array(array($this->mc, $method), $args); 63 | } 64 | 65 | //Otherwise, treat it as a property 66 | return $this->mc->{$method}; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mailchimp API w. support for Laravel 2 | --- 3 | 4 | The package supports use with the [Laravel framework][2] (v4) providing a `MailchimpWrapper` facade. 5 | 6 | ---- 7 | 8 | ###Setup: 9 | 10 | In order to install add the following to your `composer.json` file within the `require` block: 11 | 12 | ```js 13 | "require": { 14 | … 15 | "hugofirth/mailchimp": "2.0.*", 16 | … 17 | } 18 | ``` 19 | 20 | Within Laravel, locate the file `..app/config/app.php` *. 21 | 22 | Add the following to the `providers` array: 23 | 24 | ```php 25 | 'providers' => array( 26 | … 27 | 'Hugofirth\Mailchimp\MailchimpServiceProvider', 28 | … 29 | ), 30 | ``` 31 | 32 | Furthermore, add the following the the `aliases` array: 33 | 34 | ```php 35 | 'aliases' => array( 36 | … 37 | 'MailchimpWrapper' => 'Hugofirth\Mailchimp\Facades\MailchimpWrapper', 38 | … 39 | ), 40 | ``` 41 | 42 | Publish the configuration 43 | 44 | ```sh 45 | $ php artisan config:publish hugofirth/mailchimp 46 | ``` 47 | 48 | Lastly, run the command `composer update`. 49 | 50 | _\* The subsequent steps should be repeated for any file `app.php` created for additional environments._ 51 | 52 | ---- 53 | 54 | ###Usage: 55 | 56 | Your unique MailChimp API key should be set in the package's config found in `app/config/packages/hugofirth/mailchimp/config.php` 57 | 58 | Methods of the MailChimp api class work as described by the MailChimp API docs found [Here][3]. Examples of actual usage can be found [Here][4] (**Warning**: Examples use CakePHP). Thanks to Laravel's use of the "Facade" design pattern, all methods may be called in the following manner: 59 | 60 | ```php 61 | … 62 | //Retrieve an array of lists for your account 63 | $lists = MailchimpWrapper::lists()->getList()['data']; 64 | … 65 | //Subscribe a user, with email: $email_address, to a list with id: $list_id 66 | MailchimpWrapper::lists()->subscribe($list_id, array('email'=>$email_address)); 67 | ``` 68 | 69 | In order to allow for auto-completion, you can include a use statement for the Facade: 70 | 71 | ```php 72 |