Example #1
0
 public function sendRequest($api_action, $params, $method = self::METHOD_POST)
 {
     $this->setMethod($method);
     $this->setHeader('Expect', '');
     $this->params = $params;
     if ($this->plugin->getConfig('api_type') == 0) {
         $this->vars['api_user'] = $this->plugin->getConfig('api_user');
         $this->vars['api_pass'] = $this->plugin->getConfig('api_password');
     } else {
         $this->vars['api_key'] = $this->plugin->getConfig('api_key');
     }
     $this->vars['api_action'] = $api_action;
     $this->vars['api_output'] = 'serialize';
     if ($method == self::METHOD_POST) {
         $this->addPostParameter($this->params);
         $url = $this->plugin->getConfig('api_url') . '/admin/api.php?' . http_build_query($this->vars, '', '&');
         if ($this->plugin->getConfig('debug')) {
             Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN POST REQUEST : {$url}" . var_export($this->params, true));
         }
     } else {
         $url = $this->plugin->getConfig('api_url') . '/admin/api.php?' . http_build_query($this->vars + $this->params, '', '&');
         if ($this->plugin->getConfig('debug')) {
             Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN GET REQUEST : {$url}");
         }
     }
     $this->setUrl($url);
     $ret = parent::send();
     if (!in_array($ret->getStatus(), array(200, 404))) {
         throw new Am_Exception_InternalError("Activecampaign API Error, configured API Key is wrong");
     }
     $arr = unserialize($ret->getBody());
     if ($this->plugin->getConfig('debug')) {
         Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN RESPONSE : " . var_export($arr, true));
     }
     if (!$arr) {
         throw new Am_Exception_InternalError("Activecampaign API Error - unknown response [" . $ret->getBody() . "]");
     }
     if ($arr['result_code'] != 1) {
         Am_Di::getInstance()->errorLogTable->log("Activecampaign API Error - code [" . $arr['result_code'] . "]response [" . $arr['result_message'] . "]");
     }
     unset($arr['result_code'], $arr['result_message'], $arr['result_output']);
     return $arr;
 }