Search in sources :

Example 1 with BidResponse

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);
}
Also used : DisplayViewListener(org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) AdError(com.google.android.gms.ads.AdError) DisplayView(org.prebid.mobile.rendering.bidding.display.DisplayView)

Example 2 with BidResponse

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()));
}
Also used : OnFetchCompleteListener(org.prebid.mobile.rendering.bidding.listeners.OnFetchCompleteListener) BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) MoPubBannerMediationUtils(com.mopub.mediation.MoPubBannerMediationUtils) OpenMediationBaseAdUnit(org.prebid.mobile.mopub.mock.OpenMediationBaseAdUnit) Test(org.junit.Test)

Example 3 with BidResponse

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;
}
Also used : BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) Nullable(androidx.annotation.Nullable)

Example 4 with 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);
}
Also used : AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 5 with 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());
}
Also used : BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) Bid(org.prebid.mobile.rendering.bidding.data.bid.Bid) Test(org.junit.Test)

Aggregations

BidResponse (org.prebid.mobile.rendering.bidding.data.bid.BidResponse)30 Test (org.junit.Test)26 Bid (org.prebid.mobile.rendering.bidding.data.bid.Bid)12 AdException (org.prebid.mobile.rendering.errors.AdException)7 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)7 BidRequesterListener (org.prebid.mobile.rendering.bidding.listeners.BidRequesterListener)6 MoPubBannerMediationUtils (com.mopub.mediation.MoPubBannerMediationUtils)2 HashMap (java.util.HashMap)2 InterstitialController (org.prebid.mobile.rendering.bidding.display.InterstitialController)2 BannerEventListener (org.prebid.mobile.rendering.bidding.listeners.BannerEventListener)2 OnFetchCompleteListener (org.prebid.mobile.rendering.bidding.listeners.OnFetchCompleteListener)2 Activity (android.app.Activity)1 Nullable (androidx.annotation.Nullable)1 AdError (com.google.android.gms.ads.AdError)1 MoPubRewardedVideoMediationUtils (com.mopub.mediation.MoPubRewardedVideoMediationUtils)1 MoPubView (com.mopub.mobileads.MoPubView)1 Before (org.junit.Before)1 OpenMediationBaseAdUnit (org.prebid.mobile.mopub.mock.OpenMediationBaseAdUnit)1 OpenMediationRewardedVideoAdUnit (org.prebid.mobile.mopub.mock.OpenMediationRewardedVideoAdUnit)1 DisplayView (org.prebid.mobile.rendering.bidding.display.DisplayView)1