use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class PublisherAdViewWrapper method loadAd.
// endregion ==================== GAM AdEventListener Implementation
public void loadAd(Bid bid) {
try {
AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
if (bid != null) {
Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
}
mAdView.loadAd(adRequest);
} catch (Throwable throwable) {
LogUtil.error(TAG, Log.getStackTraceString(throwable));
}
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class RewardedAdWrapper method loadAd.
// endregion ==================== GAM FullScreenContentCallback Implementation
public void loadAd(Bid bid) {
try {
AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
if (bid != null) {
Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
}
RewardedAd.load(mContextWeakReference.get(), mAdUnitId, adRequest, mRewardedAdLoadCallback);
} catch (Throwable throwable) {
LogUtil.error(TAG, Log.getStackTraceString(throwable));
}
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class PublisherInterstitialAdWrapper method loadAd.
public void loadAd(Bid bid) {
mInterstitialAd = null;
try {
AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
if (bid != null) {
Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
}
AdManagerInterstitialAd.load(mActivityWeakReference.get(), mAdUnitId, adRequest, mAdLoadCallback);
} catch (Throwable throwable) {
LogUtil.error(TAG, Log.getStackTraceString(throwable));
}
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class GamUtilsTest method handleGamKeywordsUpdate_KeyWordsShouldMatchExpected.
@Test
public void handleGamKeywordsUpdate_KeyWordsShouldMatchExpected() {
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
builder.addCustomTargeting("Key", "Value");
HashMap<String, String> bids = new HashMap<>();
bids.put("hb_pb", "0.50");
bids.put("hb_cache_id", "123456");
AdManagerAdRequest request = builder.build();
GamUtils.handleGamCustomTargetingUpdate(request, bids);
Assert.assertEquals(3, request.getCustomTargeting().size());
assertTrue(request.getCustomTargeting().containsKey("Key"));
Assert.assertEquals("Value", request.getCustomTargeting().get("Key"));
assertTrue(request.getCustomTargeting().containsKey("hb_pb"));
Assert.assertEquals("0.50", request.getCustomTargeting().get("hb_pb"));
assertTrue(request.getCustomTargeting().containsKey("hb_cache_id"));
Assert.assertEquals("123456", request.getCustomTargeting().get("hb_cache_id"));
GamUtils.handleGamCustomTargetingUpdate(request, null);
Assert.assertEquals(1, request.getCustomTargeting().size());
assertTrue(request.getCustomTargeting().containsKey("Key"));
Assert.assertEquals("Value", request.getCustomTargeting().get("Key"));
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class ResultCodeTest method testSuccessForDFP.
@Test
public void testSuccessForDFP() throws Exception {
HttpUrl httpUrl = server.url("/");
Host.CUSTOM.setHostUrl(httpUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
PrebidMobile.setPrebidServerAccountId("123456");
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus()));
BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
AdManagerAdRequest testRequest = new AdManagerAdRequest.Builder().build();
OnCompleteListener mockListener = mock(OnCompleteListener.class);
adUnit.fetchDemand(testRequest, mockListener);
DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE);
ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
fetcherLooper.runOneTask();
ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
demandLooper.runOneTask();
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onComplete(ResultCode.SUCCESS);
Bundle bundle = testRequest.getCustomTargeting();
assertEquals(10, bundle.size());
assertTrue(bundle.containsKey("hb_pb"));
assertEquals("0.50", bundle.get("hb_pb"));
assertTrue(bundle.containsKey("hb_bidder"));
assertEquals("appnexus", bundle.get("hb_bidder"));
assertTrue(bundle.containsKey("hb_bidder_appnexus"));
assertEquals("appnexus", bundle.get("hb_bidder_appnexus"));
assertTrue(bundle.containsKey("hb_cache_id"));
assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id"));
assertTrue(bundle.containsKey("hb_cache_id_appnexus"));
assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id_appnexus"));
assertTrue(bundle.containsKey("hb_env"));
assertEquals("mobile-app", bundle.get("hb_env"));
assertTrue(bundle.containsKey("hb_env_appnexus"));
assertEquals("mobile-app", bundle.get("hb_env_appnexus"));
assertTrue(bundle.containsKey("hb_pb_appnexus"));
assertEquals("0.50", bundle.get("hb_pb_appnexus"));
assertTrue(bundle.containsKey("hb_size"));
assertEquals("300x250", bundle.get("hb_size"));
assertTrue(bundle.containsKey("hb_size_appnexus"));
assertEquals("300x250", bundle.get("hb_size_appnexus"));
}
Aggregations