Search in sources :

Example 1 with MacrosModel

use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.

the class Bid method substituteMacros.

private static void substituteMacros(Bid bid) {
    Map<String, MacrosModel> macrosModelMap = new HashMap<>();
    String priceText = String.valueOf(bid.getPrice());
    String base64PriceText = Base64.encodeToString(priceText.getBytes(), Base64.NO_WRAP);
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(priceText));
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(base64PriceText));
    bid.mAdm = MacrosResolutionHelper.resolveAuctionMacros(bid.mAdm, macrosModelMap);
    bid.mNurl = MacrosResolutionHelper.resolveAuctionMacros(bid.mNurl, macrosModelMap);
}
Also used : HashMap(java.util.HashMap) MacrosModel(org.prebid.mobile.rendering.models.internal.MacrosModel)

Example 2 with MacrosModel

use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.

the class MacrosResolutionHelperTest method resolveAuctionMacros_ReplaceValueIsNull_LocatedMacrosAreReplacedWithEmptyString.

@Test
public void resolveAuctionMacros_ReplaceValueIsNull_LocatedMacrosAreReplacedWithEmptyString() throws IOException {
    String actualResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros.json");
    String expectedResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros_expected_empty.json");
    Map<String, MacrosModel> macrosModelMap = new HashMap<>();
    macrosModelMap.put(MACROS_AUCTION_BID_ID, new MacrosModel(null));
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(null));
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(null));
    String macrosAfterResolution = MacrosResolutionHelper.resolveAuctionMacros(actualResponseWithMacros, macrosModelMap);
    assertEquals(expectedResponseWithMacros, macrosAfterResolution);
}
Also used : HashMap(java.util.HashMap) MacrosModel(org.prebid.mobile.rendering.models.internal.MacrosModel) Test(org.junit.Test)

Example 3 with MacrosModel

use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.

the class MacrosResolutionHelperTest method resolveAuctionMacros_MultipleMatch_LocatedMacrosAreReplaced.

@Test
public void resolveAuctionMacros_MultipleMatch_LocatedMacrosAreReplaced() throws IOException, JSONException {
    String actualResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros.json");
    String expectedResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros_expected.json");
    Map<String, MacrosModel> macrosModelMap = new HashMap<>();
    Bid bid = Bid.fromJSONObject(new JSONObject(actualResponseWithMacros));
    String id = bid.getId();
    String price = String.valueOf(bid.getPrice());
    String base64Price = Base64.getEncoder().encodeToString(price.getBytes());
    macrosModelMap.put(MACROS_AUCTION_BID_ID, new MacrosModel(id));
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(price));
    macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(base64Price));
    String macrosAfterResolution = MacrosResolutionHelper.resolveAuctionMacros(actualResponseWithMacros, macrosModelMap);
    assertEquals(expectedResponseWithMacros, macrosAfterResolution);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Bid(org.prebid.mobile.rendering.bidding.data.bid.Bid) MacrosModel(org.prebid.mobile.rendering.models.internal.MacrosModel) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 MacrosModel (org.prebid.mobile.rendering.models.internal.MacrosModel)3 Test (org.junit.Test)2 JSONObject (org.json.JSONObject)1 Bid (org.prebid.mobile.rendering.bidding.data.bid.Bid)1