protected function fireRequest($url, $headers, $params = array(), $method = 'POST') { $httpClient = new Vtiger_Net_Client($url); if (count($headers)) { $httpClient->setHeaders($headers); } switch ($method) { case 'POST': $response = $httpClient->doPost($params); break; case 'GET': $response = $httpClient->doGet($params); break; } return $response; }
/** * Function to download the file of this instance * @param <Integer> $extensionId * @param <String> $targetFileName * @return <boolean> true/false */ public static function download($extensionId, $targetFileName) { $extensions = self::getAll(); $downloadURL = $extensions[$extensionId]->get('downloadURL'); if ($downloadURL) { $clientModel = new Vtiger_Net_Client($downloadURL); file_put_contents($targetFileName, $clientModel->doGet()); return true; } return false; }
public function query($messageid) { if (empty($messageid)) { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = 'Error'; return $result; } $serviceURL = $this->getServiceURL(self::SERVICE_QUERY); $httpClient = new Vtiger_Net_Client($serviceURL . $messageid); $response = $httpClient->doGet(array('output' => 'json')); $response = trim($response); $result = array('error' => false, 'needlookup' => 1, 'statusmessage' => ''); $reply = array(); $reply = json_decode($response, true); if (key($reply) == 'error') { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = 'Error'; } else { $result['id'] = $messageid; // Capture the status code as message by default. $result['statusmessage'] = "unknown"; switch (key($reply)) { case 'queued': $statusMessage = 'Message is waiting in queue'; $result['status'] = self::MSG_STATUS_PROCESSING; $needlookup = 1; break; case 'submitting': $statusMessage = 'Message is about to be submitted'; $needlookup = 1; break; case 'submitted': $statusMessage = 'Message has been sent'; $result['status'] = self::MSG_STATUS_DISPATCHED; $needlookup = 1; break; case 'delivered': $result['status'] = 'Delivered'; $statusMessage = 'Message delivered to phone'; $needlookup = 0; break; case 'submitFailed': $statusMessage = 'Message rejected (invalid recipient, invalid senderID)'; $needlookup = 0; break; case 'deliveryFailed': $statusMessage = 'Message undelivered (non-existent number, roaming error)'; $needlookup = 0; break; } if (!empty($statusMessage)) { $result['needlookup'] = $needlookup; $result['statusmessage'] = $statusMessage; } } return $result; }