Example #1
0
 public static function getConversionRules($className)
 {
     $className = strtolower($className);
     if (!array_key_exists($className, self::$conversions)) {
         Logs::debug('Registered models:', array_keys(self::$conversions));
         throw new Exception('Unregistered model:' . $className);
     }
     return self::$conversions[$className];
 }
Example #2
0
 public function __construct($array = null, $success = true)
 {
     if (!$success) {
         $this->exception = new SmsException($array);
     } else {
         if ($array) {
             Logs::warn('Constructor with JSON params in ' . get_class($this) . ' is deprecated, use Conversions utility class!');
             Conversions::fillFromJSON($this, $array, !$success);
         }
     }
 }
Example #3
0
 public function __construct($arrayOrJson = null, $success = true)
 {
     // TODO: Remove this and use only the Conversions class
     if (!$success) {
         $this->exception = new SmsException($arrayOrJson);
     } else {
         if ($arrayOrJson) {
             Logs::warn('Constructor with JSON params in ' . get_class($this) . ' is deprecated, use Conversions utility class!');
             Conversions::fillFromJSON($this, $arrayOrJson, !$success);
         }
     }
 }
 public function convertFromJson($object, $json)
 {
     $values = Utils::getArrayValue($json, $this->jsonFieldName);
     if (!is_array($values)) {
         Logs::warn('Looking for array (', $this->jsonFieldName, '), but found:', $values);
         return null;
     }
     $result = array();
     foreach ($values as $value) {
         $result[] = Conversions::createFromJSON($this->className, $value, false);
     }
     $fieldName = $this->objectFieldName;
     $object->{$fieldName} = $result;
 }
Example #5
0
function redirectToForm($success, $url, $message)
{
    if (DEBUG) {
        $message .= "<hr/>" . implode('<br/>', Logs::getLogs());
    }
    $message .= '<hr><a href="index.php">home</a>';
    if ($success) {
        header('Location: ' . $url . '?success=' . urlencode($message));
    } else {
        header('Location: ' . $url . '?alert=' . urlencode($message));
    }
    $_SESSION['params'] = array();
    foreach ($_GET as $key => $value) {
        $_SESSION['params'][$key] = $value;
    }
    foreach ($_POST as $key => $value) {
        $_SESSION['params'][$key] = $value;
    }
    die;
}
<?php

use infobip\DataConnectionProfileClient;
use infobip\utils\Logs;
require_once __DIR__ . '/../vendor/autoload.php';
$client = new DataConnectionProfileClient(USERNAME, PASSWORD);
$client->login();
# example:retrieve-roaming-status-with-notify-url
$response = $client->retrieveRoamingStatus(DESTINATION_ADDRESS, NOTIFY_URL);
// if there is no error the query has been succesfully executed
if (!$response->isSuccess()) {
    echo 'Error:', $response->exception, "\n";
    Logs::printLogs();
}
# ----------------------------------------------------------------------------------------------------
echo $response;
echo NOTIFY_URL;
 private function executeRequest($httpMethod, $url, $queryParams = null, $requestHeaders = null, $contentType = "application/x-www-form-urlencoded", $specialAuth = null)
 {
     if ($queryParams == null) {
         $queryParams = array();
     }
     if ($requestHeaders == null) {
         $requestHeaders = array();
     }
     // Check if the charset is specified in the content-type:
     if (strpos($contentType, 'charset') === false) {
         $charset = OneApiConfigurator::getCharset();
         if (!$charset) {
             $charset = 'utf-8';
         }
         $contentType .= '; charset=' . $charset;
     }
     $sendHeaders = array('Content-Type: ' . $contentType);
     foreach ($requestHeaders as $key => $value) {
         $sendHeaders[] = $key . ': ' . $value;
     }
     if ($httpMethod === 'GET') {
         if (sizeof($queryParams) > 0) {
             $url .= '?' . $this->buildQuery($queryParams);
         }
     }
     $opts = array(CURLOPT_FRESH_CONNECT => 1, CURLOPT_CONNECTTIMEOUT => 60, CURLOPT_TIMEOUT => 120, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 3, CURLOPT_USERAGENT => 'OneApi-php-' . self::VERSION, CURLOPT_CUSTOMREQUEST => $httpMethod, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $sendHeaders);
     if ($specialAuth) {
         $opts[CURLOPT_HTTPHEADER][] = 'Authorization: App ' . $specialAuth;
     } else {
         if ($this->oneApiAuthentication && $this->oneApiAuthentication->ibssoToken) {
             // Token based authentication (one request per login request):
             $opts[CURLOPT_HTTPHEADER][] = 'Authorization: IBSSO ' . $this->oneApiAuthentication->ibssoToken;
         } else {
             // Basic authorization:
             $opts[CURLOPT_USERPWD] = $this->username . ':' . $this->password;
         }
     }
     Logs::debug('Executing ', $httpMethod, ' to ', $url);
     if (sizeof($queryParams) > 0 && ($httpMethod == 'POST' || $httpMethod == 'PUT')) {
         $httpBody = null;
         if (strpos($contentType, 'x-www-form-urlencoded')) {
             $httpBody = $this->buildQuery($queryParams);
         } else {
             if (strpos($contentType, 'json')) {
                 $httpBody = json_encode($queryParams);
             }
         }
         Logs::debug('Http body:', $httpBody);
         $opts[CURLOPT_POSTFIELDS] = $httpBody;
     }
     $ch = curl_init();
     curl_setopt_array($ch, $opts);
     $result = curl_exec($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if (curl_errno($ch) != 0) {
         throw new Exception(curl_error($ch));
     }
     $isSuccess = 200 <= $code && $code < 300;
     curl_close($ch);
     Logs::debug('Response code ', $code);
     Logs::debug('isSuccess:', $isSuccess);
     Logs::debug('Result:', $result);
     return array($isSuccess, $result);
 }