public function convertFromJson($object, $json) { $value = Utils::getArrayValue($json, $this->jsonFieldName); $result = Conversions::createFromJSON($this->className, $value, false); $fieldName = $this->objectFieldName; $object->{$fieldName} = $result; }
function __convert_inbound_sms_messages($object, $jsonData) { $messages = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.inboundSMSMessage', array()); $object->inboundSMSMessage = array(); foreach ($messages as $message) { $object->inboundSMSMessage[] = Conversions::createFromJSON('infobip\\models\\InboundSmsMessage', $message, false); } $object->numberOfMessagesInThisBatch = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.numberOfMessagesInThisBatch', 0); $object->totalNumberOfPendingMessages = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.totalNumberOfPendingMessages', 0); $object->callbackData = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.callbackData'); }
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); } } }
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; }
<?php use infobip\Conversions; use infobip\Models; use infobip\models\AbstractObject; use infobip\ObjectArrayConversionRule; require_once 'oneapi/client.php'; class Person extends AbstractObject { public $name; public $surname; public $aliases; } Models::register('Person', array(new ObjectArrayConversionRule('Alias', 'aliases'))); class Alias extends AbstractObject { public $alias; } Models::register('Alias'); $json = '{"surname": "bbb", "name": "aaa", "aliases": [{"alias": "qqqq"}, {"alias": "wwww"}, {"alias": "yyyy"}]}'; $result = Conversions::createFromJSON('Person', $json, false); assert($result); assert($result->surname == 'bbb'); assert(sizeof($result->aliases) == 3); assert($result->aliases[1]->alias == 'wwww');
<?php use infobip\Conversions; use infobip\Models; use infobip\models\AbstractObject; use infobip\SubscriptionIdFieldConversionRule; require_once '../oneapi/client.php'; $json = '{"deliveryReceiptSubscription":{"callbackReference":{"callbackData":null,"notifyURL":"http://192.168.10.111/save_requests"},"resourceURL":"http://oneapi.infobip.com/1/smsmessaging/outbound/subscriptions/q1id6ksfc8"}}'; class TestClass_32749789 extends AbstractObject { public $subscriptionId; public function __construct() { parent::__construct(); } } Models::register('TestClass_32749789', new SubscriptionIdFieldConversionRule('subscriptionId', 'deliveryReceiptSubscription.resourceURL')); $object = Conversions::createFromJSON('TestClass_32749789', $json, false); assert($object); assert($object->subscriptionId == 'q1id6ksfc8');
/** * Create new inbound messages subscription. */ public function subscribeToInboundMessagesNotifications($moSubscription) { $restUrl = $this->getRestUrl('/1/smsmessaging/inbound/subscriptions'); $params = Conversions::convertToJSON($moSubscription); list($isSuccess, $content) = $this->executePOST($restUrl, $params); // TODO(TK) clientCorrelator !!! return new GenericObject($content, $isSuccess); }
protected function createFromJSON($className, $json, $isError) { $result = Conversions::createFromJSON($className, $json, $isError); if ($this->throwException && !$result->isSuccess()) { $message = $result->exception->messageId . ': ' . $result->exception->text . ' [' . implode(',', $result->exception->variables) . ']'; throw new Exception($message); } if ('infobip\\models\\iam\\IamException' == $className) { $message = json_encode($result->requestError); throw new Exception($message); } return $result; }
<?php use infobip\Conversions; require_once '../vendor/autoload.php'; $json = '{"terminalRoamingStatusList":{"roaming":{"address":"38598123456","currentRoaming":null,"servingMccMnc":{"mcc":"219","mnc":"01"},"resourceURL":null,"retrievalStatus":"Error","extendedData":{"destinationAddress":"38598123456","statusId":5,"doneTime":1343312580170,"pricePerMessage":5.0,"mccMnc":"21901","servingMsc":"38598042003","censoredServingMsc":"3859804","gsmErrorCode":0,"originalNetworkName":"T-Mobile HR","portedNetworkName":"T-Mobile HR","servingHlr":"3859812008","imsi":"219014100133704","originalNetworkPrefix":"98","originalCountryPrefix":"385","originalCountryName":"Croatia ","isNumberPorted":false,"portedNetworkPrefix":"97","portedCountryPrefix":"385","portedCountryName":"Croatia ","numberInRoaming":false},"callbackData":null}}}'; $object = Conversions::createFromJSON('infobip\\models\\TerminalRoamingStatusList', $json, false); assert($object != null); assert($object->terminalRoamingStatus != null); assert($object->terminalRoamingStatus->servingMccMnc != null); assert($object->terminalRoamingStatus->servingMccMnc->mcc == '219'); assert($object->terminalRoamingStatus->extendedData != null); assert(trim($object->terminalRoamingStatus->extendedData->originalCountryName) == 'Croatia'); assert(!$object->terminalRoamingStatus->extendedData->isNumberPorted); assert($object->terminalRoamingStatus->extendedData->portedNetworkPrefix == '97');
<?php use infobip\Conversions; require_once '../vendor/autoload.php'; $json = '{"requestError":{"serviceException":{"text":"Request URI missing required component(s): ","messageId":"SVC0002","variables":[""]},"policyException":null}}'; $smsException = Conversions::createFromJSON('infobip\\models\\SmsException', $json, false); assert($smsException); assert($smsException->messageId == 'SVC0002'); assert($smsException->text == 'Request URI missing required component(s): ');
<?php use infobip\Conversions; require_once '../oneapi/client.php'; $json = '{"deliveryInfoList":{"deliveryInfo":[{"address":"38598123456","deliveryStatus":"DeliveredToTerminal"}],"resourceURL":"http://oneapi.infobip.com/1/smsmessaging/outbound/TODO/requests/ih5k7mm6dy/deliveryInfos"}}'; $deliveryInfoList = Conversions::createFromJSON('DeliveryInfoList', $json, false); assert($deliveryInfoList); assert(sizeof($deliveryInfoList->deliveryInfo) == 1); assert($deliveryInfoList->deliveryInfo[0]->deliveryStatus == 'DeliveredToTerminal');