コード例 #1
0
ファイル: PeoplePlant.php プロジェクト: JamesLinus/platform
 protected function manageWebhooks($list_id, $action = 'add')
 {
     $api_connection = $this->getConnectionAPI($list_id);
     if ($api_connection) {
         // connection found, api instantiated
         switch ($api_connection['connection_type']) {
             case 'com.mailchimp':
                 $mc = $api_connection['api'];
                 // webhooks
                 $api_credentials = CASHSystem::getAPICredentials();
                 $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $list_id . '/api_key/' . $api_credentials['api_key'];
                 if ($action == 'remove') {
                     return $mc->listWebhookDel($webhook_api_url);
                 } else {
                     return $mc->listWebhookAdd($webhook_api_url, $actions = null, $sources = null);
                     // TODO: What do we do when adding a webhook fails?
                     // TODO: Try multiple times?
                 }
                 break;
             default:
                 // confused, return false
                 return false;
         }
     } else {
         // no connection, simply return true
         return true;
     }
 }
コード例 #2
-1
ファイル: MandrillSeed.php プロジェクト: JamesLinus/platform
 public static function handleRedirectReturn($data = false)
 {
     if (!isset($data['key'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         require_once CASH_PLATFORM_ROOT . '/lib/mandrill/Mandrill.php';
         $m = new Mandrill($data['key']);
         $user_info = $m->getUserInfo();
         $username = $user_info['username'];
         // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth
         // calls would only happen in the admin. If this changes we can f**k around with it later.
         $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user'));
         $result = $new_connection->setSettings($username . ' (Mandrill)', 'com.mandrillapp', array('key' => $data['key']));
         if (!$result) {
             return 'There was an error. (adding the connection) Please try again.';
         }
         // set up webhooks
         $api_credentials = CASHSystem::getAPICredentials();
         $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mandrillapp/api_key/' . $api_credentials['api_key'];
         //$m->webhooksDelete($webhook_api_url); // remove duplicate webhooks
         //$m->webhooksAdd($webhook_api_url,array('send','hard_bounce','soft_bounce','open','click','spam','unsub','reject')); // add it, all events
         $m->call('webhooks/add', array("url" => $webhook_api_url, "events" => array('hard_bounce', 'soft_bounce', 'open', 'click', 'spam', 'unsub', 'reject')));
         if (isset($data['return_result_directly'])) {
             return $result;
         } else {
             if ($result) {
                 AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/');
             } else {
                 AdminHelper::formFailure('Error. Something just didn\'t work right.');
             }
         }
     }
 }