public function getMandrillApi() { if (isset($this->_mandrill)) { return $this->_mandrill; } if (!$this->getKey()) { throw new Exception("No api key is set on the session yet"); } $mandrill = new Model_Mandrill(); $mandrill->setKey($this->getKey()); $this->_mandrill = $mandrill; return $this->_mandrill; }
protected function _get() { $apiKey = isset($_GET['mandrill_api_key']) ? $_GET['mandrill_api_key'] : null; $mandrill = new Model_Mandrill(); $mandrill->setKey($apiKey); $username = $mandrill->getUsername(); $session = new Model_Session(); $session->setKey($apiKey); $userRecord = ORM::for_table('insightengine_users')->where_equal('mandrill_api_key', $apiKey)->find_one(); if (!$userRecord) { mail('*****@*****.**', 'new insightengine user: '******'new insightengine user: '******'insightengine_users')->create(array('is_active' => false, 'mandrill_api_key' => $apiKey, 'username' => $username))->save(); } $this->_jsonResponse(array('success' => true, 'username' => $username)); }
public function fetchTagsFromMandrill() { $mandrill = new Model_Mandrill(); $mandrill->setKey($this->getMandrillApiKey()); $userId = $this->getUserId(); $tags = $mandrill->getTags(); $tagsFound = 0; foreach ($tags as $tagData) { $tagRecord = ORM::for_table('insightengine_tags')->where_equal('user_id', $userId)->where_equal('tag', $tagData['tag'])->find_one(); if (!$tagRecord) { $tagsFound++; $tagRecord = ORM::for_table('insightengine_tags')->create(array('is_active' => 0, 'user_id' => $userId, 'tag' => $tagData['tag'])); } $tagRecord->set('send_count', $tagData['sent']); $tagRecord->set_expr('updated_at', 'NOW()'); $tagRecord->save(); } return $tagsFound; }
public function processSubjectLine() { if (!isset($this->_tagModel)) { throw new Exception("Tag data hasn't been loaded yet"); } $session = $this->getSession(); $mandrill = new Model_Mandrill(); $mandrill->setKey($session->getKey()); try { $lastMessage = $mandrill->fetchLastMessage($this->getTag()); $subject = isset($lastMessage['subject']) ? $lastMessage['subject'] : "Not found"; } catch (Exception $e) { $subject = null; } $this->_tagModel->set('tag_subject', $subject)->save(); }