Last active
August 29, 2015 14:27
-
-
Save stevewaffles/e5f34504fd53af001bc5 to your computer and use it in GitHub Desktop.
Revisions
-
stevewaffles revised this gist
Aug 15, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php public function handle($event) { $params = $event->subject(); //create new instance of aweber using our dev creds -
stevewaffles created this gist
Aug 15, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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)); } }