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.

Revisions

  1. stevewaffles revised this gist Aug 15, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions aweber.php
    Original 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
  2. stevewaffles created this gist Aug 15, 2015.
    30 changes: 30 additions & 0 deletions aweber.php
    Original 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));
    }
    }