Bronto API PHP Class to Send a Contact a particular Message (Zend Helper)

< ? php
class
Zend_Controller_Action_Helper_BrontoSendMessage extends Zend_Controller_Action_Helper_Abstract {

public $message;
public $client;
public $viewData;
public $list;
public $now = “date(‘c’)”;
public $recipientObject;
public $email;
public $contact;
public $contactId;

private $fromName = ‘WHATEVERYOUWOULDLIKE’;
private $fromEmail = ‘YOU@YOURMAIL.COM’;

public function login(){
ini_set(“soap.wsdl_cache_enabled”, “0”);
date_default_timezone_set(‘America/New_York’);

$wsdl = “https://api.bronto.com/v4?wsdl”;
$url = “https://api.bronto.com/v4”;

$this-> client = new SoapClient($wsdl, array(‘trace’ => 1, ‘encoding’ => ‘UTF-8’));
$this-> client->__setLocation($url);

// Login
$token = “YOUR BRONTO TOKEN HERE”;
$sessionId = $this-> client->login(array(“apiToken” => $token))->return;
if (!$sessionId) {
return “Login failed”;
}
$this-> client->__setSoapHeaders(array(new SoapHeader(“http://api.bronto.com/v4”,
‘sessionHeader’,
array(‘sessionId’ => $sessionId))));

$this-> viewData[‘login’] = “logged in”;
}

public function setContact($email){
$this-> email = $email;

$filter = array(’email’ => array(array(‘operator’ => ‘EqualTo’,’value’ => $this-> email)));

$this-> contact = $this-> client->readContacts(array(‘pageNumber’ => 1,
‘includeLists’ => true,
‘filter’ => $filter,
));
if(!isset($this->contact->return->id))
{
//return ‘Email not subscribed’;
}
else
{
$this-> contactId = $this->contact->return->id;
//return $this->contactId;
}

$this-> recipientObject = array(‘type’ => ‘contact’, ‘id’ => $this->contactId);
}

public function setDelivery($messageid){
$delivery = array(‘start’ => date(‘c’),
‘messageId’ => $messageid,
‘fromName’ => $this-> fromName,
‘fromEmail’ => $this-> fromEmail,
‘recipients’ => array($this-> recipientObject),
);

$this->client->addDeliveries(array($delivery));
}
}
? >

called from another Zend Controller as a helper in this fashion:

$this-> _helper-> BrontoSendMessage->login();
$this-> _helper-> BrontoSendMessage->setContact($this-> email);
$this-> _helper-> BrontoSendMessage->setDelivery($this-> messageid);

Leave a Reply

You must be logged in to post a comment.