src/ads/fetchAds.js
function requestAds(adUnit, callback) {
    var limit = _getRequiredAdCountForAdUnit(adUnit);
    var token = page.getToken();
    var imageType = adUnit.imageType;
    if (typeof imageType == 'undefined'){
      imageType = "hq_icon";
    }
    var requestQuery = {
        "output": "json",
        "placement_key": adUnit.placementKey,
        "limit": limit,
        "token": token,
        "auto_device": 1,
        "image_type": imageType
    };

    //noinspection JSUnresolvedVariable
    var overrides = appSettings.overrides;
    if (overrides && overrides.formFactor && overrides.platform && overrides.fullDeviceName && overrides.version) {
        delete requestQuery.auto_device;
        requestQuery.os = overrides.platform;
        requestQuery.model = overrides.fullDeviceName;
        requestQuery.version = overrides.version;
    }

    ajax.get({
        url: appSettings.adApiBaseUrl,
        query: requestQuery,
        success: function (data) {
            if (data.length !== limit) {
                logger.warn("Tried to fetch " + limit + " ads, but received " + data.length);
            }
            data = _buildImageFields(data);
            callback(data);
        },
        error: function (e) {
            logger.wtf('An error occurred trying to fetch ads');
        }
    });
}
function requestAds(adUnit, callback) {
    var limit = _getRequiredAdCountForAdUnit(adUnit);
    var token = page.getToken();
    var imageType = adUnit.imageType;
    if (typeof imageType == 'undefined'){
      imageType = "hq_icon";
    }
    var requestQuery = {
        "output": "json",
        "placement_key": adUnit.placementKey,
        "limit": limit,
        "token": token,
        "auto_device": 1,
        "image_type": imageType
    };

    //noinspection JSUnresolvedVariable
    var overrides = appSettings.overrides;
    if (overrides && overrides.formFactor && overrides.platform && overrides.fullDeviceName && overrides.version) {
        delete requestQuery.auto_device;
        requestQuery.os = overrides.platform;
        requestQuery.model = overrides.fullDeviceName;
        requestQuery.version = overrides.version;
    }

    ajax.get({
        url: appSettings.adApiBaseUrl,
        query: requestQuery,
        success: function (data) {
            if (data.length !== limit) {
                logger.warn("Tried to fetch " + limit + " ads, but received " + data.length);
            }
            data = _buildImageFields(data);
            callback(data);
        },
        error: function (e) {
            logger.wtf('An error occurred trying to fetch ads');
        }
    });
}
function requestAds ( adUnit , callback ) { var limit = _getRequiredAdCountForAdUnit ( adUnit ) ; var token = page . getToken ( ) ; var imageType = adUnit . imageType ; if ( typeof imageType == 'undefined' ) { imageType = "hq_icon" ; } var requestQuery = { "output" : "json" , "placement_key" : adUnit . placementKey , "limit" : limit , "token" : token , "auto_device" : 1 , "image_type" : imageType } ; //noinspection JSUnresolvedVariable var overrides = appSettings . overrides ; if ( overrides && overrides . formFactor && overrides . platform && overrides . fullDeviceName && overrides . version ) { delete requestQuery . auto_device ; requestQuery . os = overrides . platform ; requestQuery . model = overrides . fullDeviceName ; requestQuery . version = overrides . version ; } ajax . get ( { url : appSettings . adApiBaseUrl , query : requestQuery , success : function ( data ) { if ( data . length !== limit ) { logger . warn ( "Tried to fetch " + limit + " ads, but received " + data . length ) ; } data = _buildImageFields ( data ) ; callback ( data ) ; } , error : function ( e ) { logger . wtf ( 'An error occurred trying to fetch ads' ) ; } } ) ; }
Request ads from the offerEngine
@param adUnit - The ad Unit that is requesting ads
@param callback - The callback to execute containing the ads
Request ads from the offerEngine