use of org.prebid.mobile.rendering.bidding.data.bid.BidResponse in project prebid-mobile-android by prebid.
the class PrebidBannerAdapter method requestBannerAd.
@Override
public void requestBannerAd(@NonNull Context context, @NonNull CustomEventBannerListener adMobListener, @Nullable String serverParameter, @NonNull AdSize adSize, @NonNull MediationAdRequest mediationAdRequest, @Nullable Bundle extras) {
if (extras == null) {
String error = "Extras are empty! Check if you add custom event extras bundle to " + TAG;
Log.e(TAG, error);
adMobListener.onAdFailedToLoad(new AdError(1001, error, "prebid"));
return;
}
String responseId = extras.getString(EXTRA_RESPONSE_ID);
if (responseId == null) {
String error = "Response id is null";
adMobListener.onAdFailedToLoad(new AdError(1002, error, "prebid"));
return;
}
HashMap<String, String> prebidParameters = BidResponseCache.getInstance().getKeywords(responseId);
if (!ParametersMatcher.doParametersMatch(serverParameter, prebidParameters)) {
String error = "Parameters are different";
adMobListener.onAdFailedToLoad(new AdError(1003, error, "prebid"));
return;
}
LogUtil.v(TAG, "Parameters are matched! (" + serverParameter + ")");
BidResponse response = BidResponseCache.getInstance().popBidResponse(responseId);
if (response == null) {
String error = "There's no response for the response id: " + responseId;
adMobListener.onAdFailedToLoad(new AdError(1004, error, "prebid"));
return;
}
AdConfiguration adConfiguration = new AdConfiguration();
adConfiguration.setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.BANNER);
DisplayViewListener listener = getListener(adMobListener);
adView = new DisplayView(context, listener, adConfiguration, response);
}
use of org.prebid.mobile.rendering.bidding.data.bid.BidResponse in project prebid-mobile-android by prebid.
the class MoPubMediationUtilsWithAdUnitsTest method whenOnResponseReceived_UpdateMoPubAndSuccessResult.
@Test
public void whenOnResponseReceived_UpdateMoPubAndSuccessResult() {
String testConfigId = "configId";
String responseString = TestResponse.getResponse();
HashMap<String, String> keywordsMap = TestResponse.getKeywordsMap();
BidResponse bidResponse = new BidResponse(responseString);
OnFetchCompleteListener mockListener = mock(OnFetchCompleteListener.class);
MoPubBannerMediationUtils bannerUtils = mock(MoPubBannerMediationUtils.class);
OpenMediationBaseAdUnit adUnit = new OpenMediationBaseAdUnit(context, testConfigId, mockAdSize, bannerUtils);
WhiteBox.setInternalState(adUnit, "mBidLoader", mMockBidLoader);
adUnit.fetchDemand(mockListener);
adUnit.onResponseReceived(bidResponse);
verify(mockListener).onComplete(FetchDemandResult.SUCCESS);
verify(bannerUtils).setResponseToLocalExtras(bidResponse);
verify(bannerUtils).handleKeywordsUpdate(keywordsMap);
assertNotNull(BidResponseCache.getInstance().popBidResponse(bidResponse.getId()));
}
use of org.prebid.mobile.rendering.bidding.data.bid.BidResponse in project prebid-mobile-android by prebid.
the class BidResponseCache method popBidResponse.
@Nullable
public BidResponse popBidResponse(@Nullable final String responseId) {
LogUtil.debug(TAG, "POPPING the response");
BidResponse bidResponse = null;
if (sCachedBidResponses.containsKey(responseId)) {
// check if the available BidResponse is not stale
bidResponse = sCachedBidResponses.remove(responseId);
} else {
LogUtil.warn(TAG, "No cached ad to retrieve in the final map");
}
LogUtil.debug(TAG, "Cached ad count after popping: " + getCachedResponsesCount());
return bidResponse;
}
use of org.prebid.mobile.rendering.bidding.data.bid.BidResponse in project prebid-mobile-android by prebid.
the class InterstitialController method loadAd.
public void loadAd(String responseId, boolean isRewarded) {
BidResponse bidResponse = BidResponseCache.getInstance().popBidResponse(responseId);
if (bidResponse == null) {
if (mListener != null) {
mListener.onInterstitialFailedToLoad(new AdException(AdException.INTERNAL_ERROR, "No bid response found in the cache"));
}
return;
}
AdConfiguration adUnitConfiguration = new AdConfiguration();
adUnitConfiguration.setRewarded(isRewarded);
loadAd(adUnitConfiguration, bidResponse);
}
use of org.prebid.mobile.rendering.bidding.data.bid.BidResponse in project prebid-mobile-android by prebid.
the class CreativeModelMakerBidsTest method whenMakeModelsAndBidRequestContainsAcjAd_CreateAcjModel.
@Test
public void whenMakeModelsAndBidRequestContainsAcjAd_CreateAcjModel() throws IOException {
AdConfiguration configuration = new AdConfiguration();
configuration.setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.BANNER);
String responseString = ResourceUtils.convertResourceToString("bidding_response_obj.json");
BidResponse bidResponse = new BidResponse(responseString);
ArgumentCaptor<CreativeModelsMaker.Result> resultArgumentCaptor = ArgumentCaptor.forClass(CreativeModelsMaker.Result.class);
mModelMakerBids.makeModels(configuration, bidResponse);
verify(mMockLoadListener).onCreativeModelReady(resultArgumentCaptor.capture());
CreativeModel creativeModel = resultArgumentCaptor.getValue().creativeModels.get(0);
Bid bid = bidResponse.getSeatbids().get(0).getBids().get(0);
assertEquals("HTML", creativeModel.getName());
assertEquals(bid.getAdm(), creativeModel.getHtml());
assertEquals(bid.getWidth(), creativeModel.getWidth());
assertEquals(bid.getHeight(), creativeModel.getHeight());
assertFalse(creativeModel.isRequireImpressionUrl());
}
Aggregations