public function testRequest()
 {
     require __DIR__ . '/cfgs/ads_config.php';
     if (isset($proxyHost) && isset($proxyPort)) {
         RestfulEnvironment::setProxy($proxyHost, $proxyPort);
     }
     if (isset($allowAllCerts)) {
         RestfulEnvironment::setAcceptAllCerts($allowAllCerts);
     }
     $osrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
     $token = $osrvc->getToken('ADS');
     $adsService = new ADSService($FQDN, $token);
     $category = Category::AUTO;
     $ua = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
     $udid = '938382893239492349234923493249';
     $response = $adsService->getAdvertisement($category, $ua, $udid);
     $this->assertTrue($response->getContent() != null);
 }
 /**
  * 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);
 }
 public function handleRequest()
 {
     if (!isset($_REQUEST['btnGetAds'])) {
         return;
     }
     try {
         $this->_init();
         $adsService = new ADSService($this->apiFQDN, $this->getFileToken());
         //$ua = $_SERVER['HTTP_USER_AGENT'];
         // TODO (pk9069): move values to config
         $category = $_REQUEST['category'];
         $optArgs = $this->_getOptArgs();
         $ua = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
         $udid = md5('RANDOM TRUST ME');
         $result = $adsService->getAdvertisement($category, $ua, $udid, $optArgs);
         if ($result == null) {
             $result = 'No Ads were returned';
         }
         $this->results[ADSController::RESULT_AD] = $result;
     } catch (Exception $e) {
         $this->errors[ADSController::ERROR_AD] = $e->getMessage();
     }
 }
    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;
}
$arr = null;
try {
    envinit();
    $adsService = new ADSService(getFqdn(), getFileToken());
    $category = $_POST['category'];
    $optArgs = parseArgs();
    $result = $adsService->getAdvertisement($category, $userAgent, $udid, $optArgs);
    if ($result === null) {
        $arr = array('success' => true, 'text' => 'No Ads were returned');
    } else {
        $arr = array('success' => true, 'tables' => array(array('caption' => 'Ads Response:', 'headers' => array('Type', 'ClickUrl'), 'values' => array(array($result->getAdsType(), $result->getClickUrl())))));
    }
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Beispiel #5
0
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\Srvc\ServiceException;
// Use the app account settings from developer.att.com for the following values.
// Make sure that the API scope is set to ADS for the Advertising API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth access token using the ADS API scope.
$token = $osrvc->getToken('ADS');
// Create the service for interacting with the Advertising API.
$adsSrvc = new ADSService('https://api.att.com', $token);
try {
    // Specify the user agent (must be mobile).
    $ua = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
    // Specify a unique id.
    $udid = '938382893239492349234923493249';
    // Send the request to the API Gateway for getting an advertisement
    // using 'auto' as the category.
    $cat = Category::AUTO;
    $response = $adsSrvc->getAdvertisement($cat, $ua, $udid);
    echo 'clickUrl: ' . $response->getClickUrl() . "\n";
    echo 'adType: ' . $response->getAdsType() . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
}