Search in sources :

Example 1 with User

use of org.prebid.mobile.rendering.models.openrtb.bidRequests.User in project prebid-mobile-android by prebid.

the class BasicParameterBuilderTest method whenAppendParametersAndTargetingUserDataNotEmpty_UserDataAddedToUserExt.

@Test
public void whenAppendParametersAndTargetingUserDataNotEmpty_UserDataAddedToUserExt() throws JSONException {
    Targeting.addUserData("user", "userData");
    AdConfiguration adConfiguration = new AdConfiguration();
    adConfiguration.setConfigId("config");
    BasicParameterBuilder builder = new BasicParameterBuilder(adConfiguration, mContext.getResources(), false);
    AdRequestInput adRequestInput = new AdRequestInput();
    builder.appendBuilderParameters(adRequestInput);
    User user = adRequestInput.getBidRequest().getUser();
    assertTrue(user.getExt().getMap().containsKey("data"));
    JSONObject userDataJson = (JSONObject) user.getExt().getMap().get("data");
    assertTrue(userDataJson.has("user"));
    assertEquals("userData", userDataJson.getJSONArray("user").get(0));
}
Also used : User(org.prebid.mobile.rendering.models.openrtb.bidRequests.User) JSONObject(org.json.JSONObject) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) BasicParameterBuilder(org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder) Test(org.junit.Test)

Example 2 with User

use of org.prebid.mobile.rendering.models.openrtb.bidRequests.User in project prebid-mobile-android by prebid.

the class BasicParameterBuilderTest method whenAppendUserData_UserDataAddedToUser.

@Test
public void whenAppendUserData_UserDataAddedToUser() throws JSONException {
    AdConfiguration adConfiguration = new AdConfiguration();
    adConfiguration.setConfigId("config");
    DataObject dataObject = new DataObject();
    String testName = "testDataObject";
    dataObject.setName(testName);
    adConfiguration.addUserData(dataObject);
    BasicParameterBuilder builder = new BasicParameterBuilder(adConfiguration, mContext.getResources(), false);
    AdRequestInput adRequestInput = new AdRequestInput();
    builder.appendBuilderParameters(adRequestInput);
    User user = adRequestInput.getBidRequest().getUser();
    assertEquals(1, user.dataObjects.size());
    JSONObject jsonUser = user.getJsonObject();
    assertTrue(jsonUser.has("data"));
    JSONArray jsonData = jsonUser.getJSONArray("data");
    JSONObject jsonDataObject = jsonData.getJSONObject(0);
    assertTrue(jsonDataObject.has("name"));
    String dataName = jsonDataObject.getString("name");
    assertEquals(testName, dataName);
}
Also used : DataObject(org.prebid.mobile.DataObject) User(org.prebid.mobile.rendering.models.openrtb.bidRequests.User) JSONObject(org.json.JSONObject) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) JSONArray(org.json.JSONArray) BasicParameterBuilder(org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder) Test(org.junit.Test)

Example 3 with User

use of org.prebid.mobile.rendering.models.openrtb.bidRequests.User in project prebid-mobile-android by prebid.

the class BasicParameterBuilder method appendUserTargetingParameters.

private void appendUserTargetingParameters(AdRequestInput adRequestInput) {
    final BidRequest bidRequest = adRequestInput.getBidRequest();
    final User user = bidRequest.getUser();
    user.id = Targeting.getUserId();
    user.yob = Targeting.getUserYob();
    user.keywords = Targeting.getUserKeyWords();
    user.customData = Targeting.getUserCustomData();
    user.gender = Targeting.getUserGender();
    user.buyerUid = Targeting.getBuyerUid();
    user.ext = Targeting.getUserExt();
    user.dataObjects = mAdConfiguration.getUserData();
    final Map<String, Set<String>> userDataDictionary = Targeting.getUserDataDictionary();
    if (!userDataDictionary.isEmpty()) {
        user.getExt().put("data", Utils.toJson(userDataDictionary));
    }
    if (Targeting.getEids() != null) {
        user.getExt().put("eids", Targeting.getEids());
    }
    final Pair<Float, Float> userLatLng = Targeting.getUserLatLng();
    if (userLatLng != null) {
        final Geo userGeo = user.getGeo();
        userGeo.lat = userLatLng.first;
        userGeo.lon = userLatLng.second;
    }
}
Also used : Geo(org.prebid.mobile.rendering.models.openrtb.bidRequests.devices.Geo) User(org.prebid.mobile.rendering.models.openrtb.bidRequests.User) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest)

Example 4 with User

use of org.prebid.mobile.rendering.models.openrtb.bidRequests.User in project prebid-mobile-android by prebid.

the class BasicParameterBuilderTest method whenAppendParametersAndTargetingParamsWereSet_TargetingParamsWereAppend.

@Test
public void whenAppendParametersAndTargetingParamsWereSet_TargetingParamsWereAppend() throws JSONException {
    AdConfiguration adConfiguration = new AdConfiguration();
    adConfiguration.setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.BANNER);
    adConfiguration.addSize(new AdSize(320, 50));
    Targeting.setUserId(USER_ID);
    Targeting.setUserAge(USER_AGE);
    Targeting.setUserKeywords(USER_KEYWORDS);
    Targeting.setUserCustomData(USER_CUSTOM);
    Targeting.setUserGender(UserParameters.Gender.MALE);
    Targeting.setBuyerUid(USER_BUYER_ID);
    Targeting.setUserExt(new Ext());
    Targeting.setEids(new JSONArray());
    Targeting.setUserLatLng(USER_LAT, USER_LON);
    BasicParameterBuilder builder = new BasicParameterBuilder(adConfiguration, mContext.getResources(), mBrowserActivityAvailable);
    AdRequestInput adRequestInput = new AdRequestInput();
    builder.appendBuilderParameters(adRequestInput);
    User actualUser = adRequestInput.getBidRequest().getUser();
    User expectedUser = getExpectedUser();
    assertEquals(expectedUser.getJsonObject().toString(), actualUser.getJsonObject().toString());
}
Also used : Ext(org.prebid.mobile.rendering.models.openrtb.bidRequests.Ext) User(org.prebid.mobile.rendering.models.openrtb.bidRequests.User) AdSize(org.prebid.mobile.rendering.bidding.data.AdSize) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) JSONArray(org.json.JSONArray) BasicParameterBuilder(org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder) Test(org.junit.Test)

Example 5 with User

use of org.prebid.mobile.rendering.models.openrtb.bidRequests.User in project prebid-mobile-android by prebid.

the class BasicParameterBuilderTest method getExpectedUser.

private User getExpectedUser() {
    final User user = new User();
    user.id = USER_ID;
    user.yob = USER_YOB;
    user.keywords = USER_KEYWORDS;
    user.customData = USER_CUSTOM;
    user.gender = USER_GENDER;
    user.buyerUid = USER_BUYER_ID;
    user.ext = new Ext();
    user.ext.put("eids", Targeting.getEids());
    final Geo userGeo = user.getGeo();
    userGeo.lat = USER_LAT;
    userGeo.lon = USER_LON;
    return user;
}
Also used : Ext(org.prebid.mobile.rendering.models.openrtb.bidRequests.Ext) Geo(org.prebid.mobile.rendering.models.openrtb.bidRequests.devices.Geo) User(org.prebid.mobile.rendering.models.openrtb.bidRequests.User)

Aggregations

User (org.prebid.mobile.rendering.models.openrtb.bidRequests.User)6 Test (org.junit.Test)4 JSONObject (org.json.JSONObject)3 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)3 BasicParameterBuilder (org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder)3 JSONArray (org.json.JSONArray)2 Ext (org.prebid.mobile.rendering.models.openrtb.bidRequests.Ext)2 Geo (org.prebid.mobile.rendering.models.openrtb.bidRequests.devices.Geo)2 ArrayList (java.util.ArrayList)1 DataObject (org.prebid.mobile.DataObject)1 AdSize (org.prebid.mobile.rendering.bidding.data.AdSize)1 BidRequest (org.prebid.mobile.rendering.models.openrtb.BidRequest)1 App (org.prebid.mobile.rendering.models.openrtb.bidRequests.App)1 Device (org.prebid.mobile.rendering.models.openrtb.bidRequests.Device)1 Imp (org.prebid.mobile.rendering.models.openrtb.bidRequests.Imp)1 Regs (org.prebid.mobile.rendering.models.openrtb.bidRequests.Regs)1