Skip to content

Instantly share code, notes, and snippets.

@stevewaffles
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save stevewaffles/e5f34504fd53af001bc5 to your computer and use it in GitHub Desktop.

Select an option

Save stevewaffles/e5f34504fd53af001bc5 to your computer and use it in GitHub Desktop.
Aweber subscribe
<?php
public function handle($event) {
$params = $event->subject();
//create new instance of aweber using our dev creds
$app = new AweberAPI(Configure::read('aweber.consumerKey'), Configure::read('aweber.consumerSecret'));
//get our aweber account
$account = $app->getAccount(Configure::read('aweber.accessToken'), Configure::read('aweber.accessSecret'));
//find the list id that we want to subscribe the email to
$get_list = $account->lists->find(array('name' => $params['list_id']));
$get_list = $get_list[0];
$listUrl = "/accounts/$account->id/lists/$get_list->id";
$list = $account->loadFromUrl($listUrl);
//create the new email array
$subscriber = array(
'email' => $params['email'],
'name' => $params['first_name'].' '.$params['last_name'],
'custom_fields' => array(
'client_token' => $params['client_token'],
'sub_id1' => $params['sub_id1'],
'sub_id2' => $params['sub_id2']
)
);
CakeLog::debug('aweber subscriber: '.print_r($subscriber, true), 'debug');
//subscribe them!
try {
$list->subscribers->create($subscriber);
}
catch(Exception $exc) {
error_log("AWeber error on subscribe: ".print_r($exc, true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment