Skip to content

Instantly share code, notes, and snippets.

@YOzaz
Created October 13, 2015 15:20
Show Gist options
  • Save YOzaz/0bac63adad60f395a830 to your computer and use it in GitHub Desktop.
Save YOzaz/0bac63adad60f395a830 to your computer and use it in GitHub Desktop.
<?php namespace MyApp\Controllers\Mailer;
use MailChimpAPI;
class MailChimpController extends \Controller
{
/**
* Syncs MailChimp data
*
* @throws \Exception
*/
public function sync()
{
if ( !Input::has('type', 'data') )
{
return;
// throw new \Exception('Required arguments missing.');
}
$input = Input::all();
switch ( $input['type'] )
{
case 'subscribe':
MailChimpAPI::syncSubscribe( $input['data']['list_id'], $input['data']['email'] );
break;
case 'unsubscribe':
MailChimpAPI::syncUnsubscribe( $input['data']['list_id'], $input['data']['email'] );
break;
case 'cleaned':
MailChimpAPI::syncUnsubscribe( $input['data']['list_id'], $input['data']['email'] );
break;
case 'upemail':
MailChimpAPI::syncUnsubscribe( $input['data']['list_id'], $input['data']['old_email'] );
MailChimpAPI::syncSubscribe( $input['data']['list_id'], $input['data']['new_email'] );
break;
default:
// throw new \Exception('Unsupported request.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment