Last active
October 13, 2015 15:26
-
-
Save YOzaz/c164ba0651e30d2d2814 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\Facebook; | |
use FacebookAds\Api; | |
use FacebookAds\Object\CustomAudience; | |
use FacebookAds\Object\Values\CustomAudienceTypes; | |
use Setting; | |
/** | |
* Our repository, containing commonly used queries | |
*/ | |
class FacebookAdsRepository | |
{ | |
/** | |
* @return FacebookAdsRepository | |
*/ | |
public function __construct() | |
{ | |
Api::init( Setting:get('facebook.app_id'), Setting:get('facebook.app_secret'), Setting:get('facebook.token') ); | |
} | |
/** | |
* Adds users to custom audience | |
* | |
* @param array $params | |
*/ | |
public function addToAudience( $params ) | |
{ | |
$audience = new CustomAudience( $params['id'] ); | |
if ( isset($params['email']) ) | |
{ | |
$emails = is_array( $params['email'] ) ? $params['email'] : [ $params['email'] ]; | |
$audience->addUsers($emails, CustomAudienceTypes::EMAIL ); | |
} | |
} | |
/** | |
* Removes users from audience | |
* | |
* @param array $params | |
*/ | |
public function removeFromAudience( $params ) | |
{ | |
$audience = new CustomAudience( $params['id'] ); | |
if ( isset($params['email']) ) | |
{ | |
$emails = is_array( $params['email'] ) ? $params['email'] : [ $params['email'] ]; | |
$audience->removeUsers($emails, CustomAudienceTypes::EMAIL ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment