Skip to content

Commit

Permalink
Merge pull request #194 from prebid/feature/banner_api-framework
Browse files Browse the repository at this point in the history
Banner api frameworks field
  • Loading branch information
yoalex5 authored Jul 16, 2020
2 parents 707f53b + ccb4dc5 commit e1f0b47
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

import org.prebid.mobile.AdUnit;
import org.prebid.mobile.BannerAdUnit;
import org.prebid.mobile.BannerBaseAdUnit;
import org.prebid.mobile.Host;
import org.prebid.mobile.InterstitialAdUnit;
import org.prebid.mobile.LogUtil;
Expand Down Expand Up @@ -364,7 +365,15 @@ private void setupPBBanner(Host host, String accountId, String configId, @NonNul

setupPB(host, accountId, storedResponse);

adUnit = new BannerAdUnit(configId, width, height);
BannerAdUnit adUnit = new BannerAdUnit(configId, width, height);

BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
// parameters.setApi(Arrays.asList(new Signals.Api(5)));

adUnit.setParameters(parameters);

this.adUnit = adUnit;

// enableAdditionalFunctionality(adUnit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,21 @@ public void fetchDemand(@NonNull Object adObj, @NonNull OnCompleteListener liste
return;
}

VideoBaseAdUnit.Parameters parameters = null;
BannerBaseAdUnit.Parameters bannerParameters = null;
if (this instanceof BannerBaseAdUnit) {
BannerBaseAdUnit bannerBaseAdUnit = (BannerBaseAdUnit) this;
bannerParameters = bannerBaseAdUnit.parameters;
}

VideoBaseAdUnit.Parameters videoParameters = null;
if (this instanceof VideoBaseAdUnit) {
VideoBaseAdUnit videoBaseAdUnit = (VideoBaseAdUnit) this;
parameters = videoBaseAdUnit.parameters;
videoParameters = videoBaseAdUnit.parameters;
}

if (Util.supportedAdObject(adObj)) {
fetcher = new DemandFetcher(adObj);
RequestParams requestParams = new RequestParams(configId, adType, sizes, contextDataDictionary, contextKeywordsSet, minSizePerc, parameters, pbAdSlot);
RequestParams requestParams = new RequestParams(configId, adType, sizes, contextDataDictionary, contextKeywordsSet, minSizePerc, pbAdSlot, bannerParameters, videoParameters);
if (this.adType.equals(AdType.NATIVE)) {
requestParams.setNativeRequestParams(((NativeAdUnit) this).params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import java.util.HashSet;

public class BannerAdUnit extends AdUnit {
public class BannerAdUnit extends BannerBaseAdUnit {

private HashSet<AdSize> sizes;

public BannerAdUnit(@NonNull String configId, int width, int height) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2018-2019 Prebid.org, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.prebid.mobile;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.List;

public abstract class BannerBaseAdUnit extends AdUnit {

@Nullable
Parameters parameters;

BannerBaseAdUnit(@NonNull String configId, @NonNull AdType adType) {
super(configId, adType);
}

@Nullable
public Parameters getParameters() {
return parameters;
}

public void setParameters(@Nullable Parameters parameters) {
this.parameters = parameters;
}

//Parameters class

/**
* Describes an <a href="https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf">OpenRTB</a> banner object
*/
public static class Parameters {

/**
List of supported API frameworks for this impression. If an API is not explicitly listed, it is assumed not to be supported.
*/
@Nullable
private List<Signals.Api> api;

//Getters and setters
@Nullable
public List<Signals.Api> getApi() {
return api;
}

public void setApi(@Nullable List<Signals.Api> api) {
this.api = api;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

public class InterstitialAdUnit extends AdUnit {
public class InterstitialAdUnit extends BannerBaseAdUnit {

@Nullable
private AdSize minSizePerc = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,25 +560,41 @@ private JSONArray getImp() throws NoContextException {
imp.put("instl", 1);
}

if (adType.equals(AdType.INTERSTITIAL)) {
if (adType.equals(AdType.BANNER) || adType.equals(AdType.INTERSTITIAL)) {

JSONObject banner = new JSONObject();
JSONArray format = new JSONArray();
Context context = PrebidMobile.getApplicationContext();
if (context != null) {
format.put(new JSONObject().put("w", context.getResources().getConfiguration().screenWidthDp).put("h", context.getResources().getConfiguration().screenHeightDp));
} else {
// Unlikely this is being called, if so, please check if you've set up the SDK properly
throw new NoContextException();

if (adType.equals(AdType.BANNER)) {
for (AdSize size : requestParams.getAdSizes()) {
format.put(new JSONObject().put("w", size.getWidth()).put("h", size.getHeight()));
}
} else if (adType.equals(AdType.INTERSTITIAL)) {
Context context = PrebidMobile.getApplicationContext();
if (context != null) {
format.put(new JSONObject().put("w", context.getResources().getConfiguration().screenWidthDp).put("h", context.getResources().getConfiguration().screenHeightDp));
} else {
// Unlikely this is being called, if so, please check if you've set up the SDK properly
throw new NoContextException();
}
}

banner.put("format", format);
imp.put("banner", banner);
} else if (adType.equals(AdType.BANNER)) {
JSONObject banner = new JSONObject();
JSONArray format = new JSONArray();
for (AdSize size : requestParams.getAdSizes()) {
format.put(new JSONObject().put("w", size.getWidth()).put("h", size.getHeight()));

BannerBaseAdUnit.Parameters parameters = requestParams.getBannerParameters();
if (parameters != null) {

List<Integer> apiList = Util.convertCollection(parameters.getApi(), new Util.Function1<Integer, Signals.Api>() {
@Override
public Integer apply(Signals.Api element) {
return element.value;
}
});

banner.put("api", new JSONArray(apiList));

}
banner.put("format", format);

imp.put("banner", banner);
} else if (adType.equals(AdType.NATIVE)) {
// add native request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,30 @@ class RequestParams {
private AdSize minSizePerc; //non null only for InterstitialAdUnit(String, int, int)

@Nullable
private VideoBaseAdUnit.Parameters parameters;
private String pbAdSlot;

@Nullable
private String pbAdSlot;
private VideoBaseAdUnit.Parameters videoParameters;

@Nullable
private BannerBaseAdUnit.Parameters bannerParameters;

RequestParams(String configId, AdType adType, HashSet<AdSize> sizes) {
this.configId = configId;
this.adType = adType;
this.sizes = sizes; // for Interstitial this will be null, will use screen width & height in the request
}

RequestParams(String configId, AdType adType, HashSet<AdSize> sizes, @Nullable Map<String, Set<String>> contextDataDictionary, @Nullable Set<String> contextKeywordsSet, @Nullable AdSize minSizePerc, @Nullable VideoBaseAdUnit.Parameters parameters, @Nullable String pbAdSlot) {
RequestParams(String configId, AdType adType, HashSet<AdSize> sizes, @Nullable Map<String, Set<String>> contextDataDictionary, @Nullable Set<String> contextKeywordsSet, @Nullable AdSize minSizePerc, @Nullable String pbAdSlot , @Nullable BannerBaseAdUnit.Parameters bannerParameters, @Nullable VideoBaseAdUnit.Parameters videoParameters) {
this(configId, adType, sizes);
this.contextDataDictionary = contextDataDictionary;
this.contextKeywordsSet = contextKeywordsSet;
this.minSizePerc = minSizePerc;
this.parameters = parameters;
this.pbAdSlot = pbAdSlot;
this.bannerParameters = bannerParameters;
this.videoParameters = videoParameters;
}


void setNativeRequestParams(NativeRequestParams params) {
this.nativeParams = params;
}
Expand Down Expand Up @@ -97,12 +100,17 @@ AdSize getMinSizePerc() {
}

@Nullable
VideoBaseAdUnit.Parameters getVideoParameters() {
return parameters;
String getPbAdSlot() {
return pbAdSlot;
}

@Nullable
String getPbAdSlot() {
return pbAdSlot;
BannerBaseAdUnit.Parameters getBannerParameters() {
return bannerParameters;
}

@Nullable
VideoBaseAdUnit.Parameters getVideoParameters() {
return videoParameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public int hashCode() {
| 4 | ORMMA |
| 5 | MRAID-2 |
| 6 | MRAID-3 |
| 7 | OMID-1 |
*</pre>
*/
public static class Api extends SingleContainerInt {
Expand All @@ -69,10 +70,13 @@ public static class Api extends SingleContainerInt {
public static Api ORMMA = new Api(4);

/** MRAID-2 */
public static Api MARAID_2 = new Api(5);
public static Api MRAID_2 = new Api(5);

/** MRAID-3 */
public static Api MARAID_3 = new Api(6);
public static Api MRAID_3 = new Api(6);

/** OMID-1 */
public static Api OMID_1 = new Api(7);

public Api(int value) {
super(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public void setParameters(@Nullable Parameters parameters) {
}

//Parameters class
/// Describes an [OpenRTB](https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf) video object

/**
* Describes an <a href="https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf">OpenRTB</a> video object
*/
public static class Parameters {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ public void testBannerAdUnitAddSize() throws Exception {
assertEquals(2, adUnit.getSizes().size());
}

@Test
public void testBannerParametersCreation() throws Exception {

//given
BannerAdUnit bannerAdUnit = new BannerAdUnit("123456", 320, 50);

BannerAdUnit.Parameters parameters = new BannerAdUnit.Parameters();
parameters.setApi(Arrays.asList(Signals.Api.VPAID_1, Signals.Api.VPAID_2));

bannerAdUnit.parameters = parameters;

//when
BannerAdUnit.Parameters testedBannerParameters = bannerAdUnit.parameters;
List<Signals.Api> api = testedBannerParameters.getApi();

//then
assertEquals(2, api.size());
assertTrue(api.contains(new Signals.Api(1)) && api.contains(new Signals.Api(2)));

}

//Interstitial AdUnit
@Test
public void testInterstitialAdUnitCreation() throws Exception {
Expand Down
Loading

0 comments on commit e1f0b47

Please sign in to comment.