Last active
October 13, 2015 15:34
-
-
Save YOzaz/9b1344583370a497d4a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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