/**
  * Sends a request to the API for getting an advertisement.
  *
  * @method getAdvertisement
  *
  * @param {string} $category 	category of the add requested.
  * @param {string} $udid 		specifies a universally unique identifier, which must be at least 30 characters in length.
  * @param {string} $userAgent	user agent string to send to API.
  * @param {Object}  $optArgs 	any optional Key/Value JSON for API parameters.
  *
  * @return {Response} Returns Response object
  * @throws ServiceException if API request was not successful.
  */
 public function getAdvertisement($category, $udid, $userAgent, $getParams)
 {
     $token = $this->getCurrentClientToken();
     $adsSrvc = new ADSService($this->base_url, $token);
     $optArgs = new OptArgs();
     /*
     $keys = array(
     	'AgeGroup', 'AreaCode', 'City', 'Country', 'Gender',
     	'Keywords', 'Latitude', 'Longitude', 'MaxHeight', 'MaxWidth',
     	'MinHeight', 'MinWidth', 'Type', 'ZipCode'
     );
     */
     if (isset($getParams["AgeGroup"])) {
         $optArgs->setAgeGroup(urldecode($getParams["AgeGroup"]));
     }
     if (isset($getParams["AreaCode"])) {
         $optArgs->setAreaCode(urldecode($getParams["AreaCode"]));
     }
     if (isset($getParams["City"])) {
         $optArgs->setCity(urldecode($getParams["City"]));
     }
     if (isset($getParams["Country"])) {
         $optArgs->setCountry(urldecode($getParams["Country"]));
     }
     if (isset($getParams["Gender"])) {
         $optArgs->setGender(urldecode($getParams["Gender"]));
     }
     if (isset($getParams["Keywords"])) {
         $optArgs->setKeywords(explode(',', urldecode($getParams["Keywords"])));
     }
     if (isset($getParams["Latitude"])) {
         $optArgs->setLatitude(urldecode($getParams["Latitude"]));
     }
     if (isset($getParams["Longitude"])) {
         $optArgs->setLongitude(urldecode($getParams["Longitude"]));
     }
     if (isset($getParams["MaxHeight"])) {
         $optArgs->setMaxHeight(urldecode($getParams["MaxHeight"]));
     }
     if (isset($getParams["MaxWidth"])) {
         $optArgs->setMaxWidth(urldecode($getParams["MaxWidth"]));
     }
     if (isset($getParams["MinHeight"])) {
         $optArgs->setMinHeight(urldecode($getParams["MinHeight"]));
     }
     if (isset($getParams["MinWidth"])) {
         $optArgs->setMinWidth(urldecode($getParams["MinWidth"]));
     }
     if (isset($getParams["Type"])) {
         $optArgs->setAdType(urldecode($getParams["Type"]));
     }
     if (isset($getParams["ZipCode"])) {
         $optArgs->setZipCode(urldecode($getParams["ZipCode"]));
     }
     return $adsSrvc->getAdvertisement($category, $udid, $userAgent, $optArgs, true);
 }
function parseArgs()
{
    $optArgs = new OptArgs();
    if (isset($_POST['mmaSize']) && $_POST['mmaSize'] != "") {
        $mma = $_POST['mmaSize'];
        $mmaSplit = explode(' x ', $mma);
        $optArgs->setMaxWidth($mmaSplit[0]);
        $optArgs->setMinWidth($mmaSplit[0]);
        $optArgs->setMaxHeight($mmaSplit[1]);
        $optArgs->setMinHeight($mmaSplit[1]);
    }
    if (isset($_POST['keywords']) && $_POST['keywords'] != "") {
        $keywords = explode(',', $_POST['keywords']);
        $optArgs->setKeywords($keywords);
    }
    if (isset($_POST['ageGroup']) && $_POST['ageGroup'] != "") {
        $optArgs->setAgeGroup($_POST['ageGroup']);
    }
    if (isset($_POST['gender']) && $_POST['gender'] != "") {
        $optArgs->setGender($_POST['gender']);
    }
    if (isset($_POST['zipCode']) && $_POST['zipCode'] != "") {
        $optArgs->setZipCode($_POST['zipCode']);
    }
    if (isset($_POST['city']) && $_POST['city'] != "") {
        $optArgs->setCity($_POST['city']);
    }
    if (isset($_POST['areaCode']) && $_POST['areaCode'] != "") {
        $optArgs->setAreaCode($_POST['areaCode']);
    }
    if (isset($_POST['country']) && $_POST['country'] != "") {
        $optArgs->setCountry($_POST['country']);
    }
    if (isset($_POST['latitude']) && $_POST['latitude'] != "") {
        $optArgs->setLatitude($_POST['latitude']);
    }
    if (isset($_POST['longitude']) && $_POST['longitude'] != "") {
        $optArgs->setLongitude($_POST['longitude']);
    }
    return $optArgs;
}
Esempio n. 3
0
 /**
  * Convenience method to append any optional arguments to the specified
  * <var>$httpGet</var> object.
  *
  * @param HttpGet $httpGet HttpGet object to append to
  * @param OptArgs $optArgs optional arguments used for appending
  *
  * @return void
  */
 private function _appendOptArgs(HttpGet $httpGet, OptArgs $optArgs)
 {
     $keys = array('AgeGroup', 'AreaCode', 'City', 'Country', 'Gender', 'Keywords', 'Latitude', 'Longitude', 'MaxHeight', 'MaxWidth', 'MinHeight', 'MinWidth', 'Type', 'ZipCode');
     $keywords = $optArgs->getKeywords();
     if ($keywords !== null) {
         $keywords = implode(',', $optArgs->getKeywords());
     }
     $vals = array($optArgs->getAgeGroup(), $optArgs->getAreaCode(), $optArgs->getCity(), $optArgs->getCountry(), $optArgs->getGender(), $keywords, $optArgs->getLatitude(), $optArgs->getLongitude(), $optArgs->getMaxHeight(), $optArgs->getMaxWidth(), $optArgs->getMinHeight(), $optArgs->getMinWidth(), $optArgs->getAdType(), $optArgs->getZipCode());
     for ($i = 0; $i < count($keys); ++$i) {
         $key = $keys[$i];
         $val = $vals[$i];
         if ($val != null) {
             $httpGet->setParam($key, $val);
         }
     }
 }