Skip to content

Instantly share code, notes, and snippets.

@YOzaz
Last active October 13, 2015 15:34
Show Gist options
  • Save YOzaz/9b1344583370a497d4a8 to your computer and use it in GitHub Desktop.
Save YOzaz/9b1344583370a497d4a8 to your computer and use it in GitHub Desktop.
<?php namespace MyApp\Utils\MailChimp;
use MyApp\Utils\FacebookAdsRepository;
class MailChimpService
{
/**
* @var FacebookAdsRepository
*/
protected $facebook;
/**
* Maps MailChimp list ID with Facebook audience ID
*
* @var array MailChimp list maps
*/
protected $map = [
'abcdefg' => '123456789'
];
/**
* Loads our MailChimp service
*
* @param FacebookAdsRepository $facebook
*/
public function __construct( FacebookAdsRepository $facebook )
{
$this->facebook = $facebook;
}
/**
* Syncs subscription process
*
* @param string $list_id
* @param string $email
*/
public function syncSubscribe( $list_id, $email )
{
$audience = isset($this->map[$list_id]) ? $this->map[$list_id] : null;
if ( ! $audience )
{
return;
}
$this->facebook->addToAudience([
'id' => $audience,
'email' => $email
]);
}
/**
* Syncs subscription process
*
* @param string $list_id
* @param string $email
*/
public function syncUnsubscribe( $list_id, $email )
{
$audience = isset($this->map[$list_id]) ? $this->map[$list_id] : null;
if ( ! $audience )
{
return;
}
$this->facebook->removeFromAudience([
'id' => $audience,
'email' => $email
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment