/** * This method constructs a json object, depending on the request parameters * passed. * * @note The request object needs to have valid arguments, depending on the * AdRequestType Please check if the request.isValid() returns * true, as this method internally validates the request & proceeds if * & only the request object is valid for the AdRequestType. * @param $request * The request object, for which a JSON would be constructed * @return Json Object which is used as POST Body in the InMobi API 2.0 Ad * Request. TODO User demography as part of JSON API request. */ public static function generateInMobiAdRequestPayload($request) { if ($request == null || gettype($request) != "object") { return null; } if ($request->isValid() != true) { return null; } $mainObjectArray = array(); if ($request->requestType == AdRequest::NATIVE) { $mainObjectArray['responseformat'] = "native"; } else { $mainObjectArray['responseformat'] = "axml"; } $propertyJson = JSONPayloadCreator::getPropertyJson($request->property); if ($propertyJson != null) { $mainObjectArray['site'] = $propertyJson; } $impJson = JSONPayloadCreator::getImpressionJson($request->impression, $request->requestType); if ($impJson != null) { $mainObjectArray['imp'][] = $impJson; } $deviceJson = JSONPayloadCreator::getDeviceJson($request->device); if ($deviceJson != null) { $mainObjectArray['device'] = $deviceJson; } $userJson = JSONPayloadCreator::getUserJson($request->user); if ($userJson != null && empty($userJson) == false) { $mainObjectArray['user'] = $userJson; } return json_encode($mainObjectArray); }
public function toJSON() { return JSONPayloadCreator::generateInMobiAdRequestPayload($this); }