use of org.prebid.mobile.drprebid.model.PrebidServerSettings in project prebid-mobile-android by prebid.
the class AdServerTest method startTest.
public void startTest() {
GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
AdServerSettings adServerSettings = SettingsManager.getInstance(mContext).getAdServerSettings();
PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
switch(generalSettings.getAdSize()) {
case BANNER_300x250:
break;
case BANNER_300x600:
break;
case BANNER_320x50:
break;
case BANNER_320x100:
break;
case BANNER_320x480:
break;
case BANNER_728x90:
break;
}
mKeywords = createMapKeywords(adServerSettings.getBidPrice(), generalSettings.getAdSize(), generalSettings.getAdFormat(), prebidServerSettings.getPrebidServer());
if (adServerSettings.getAdServer() == AdServer.MOPUB) {
String keywords = createStringKeywords();
if (generalSettings.getAdFormat() == AdFormat.BANNER) {
AdSize adSize = generalSettings.getAdSize();
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(DimenUtil.convertPxToDp(mContext, adSize.getWidth()), DimenUtil.convertPxToDp(mContext, adSize.getHeight()));
mMoPubAd = new MoPubView(mContext);
mMoPubAd.setLayoutParams(layoutParams);
mMoPubAd.setAdUnitId(adServerSettings.getAdUnitId());
mMoPubAd.setAutorefreshEnabled(false);
mMoPubAd.setBannerAdListener(this);
mMoPubAd.setKeywords(keywords);
Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
mMoPubAd.loadAd();
} else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
mMoPubInterstitial = new MoPubInterstitial(mContext, adServerSettings.getAdUnitId());
mMoPubInterstitial.setInterstitialAdListener(this);
mMoPubInterstitial.setKeywords(keywords);
Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
mMoPubInterstitial.load();
}
} else if (adServerSettings.getAdServer() == AdServer.GOOGLE_AD_MANAGER) {
PublisherAdRequest adRequest = null;
if (generalSettings.getAdFormat() == AdFormat.BANNER) {
mGoogleAd = new PublisherAdView(mContext);
AdSize adSize = generalSettings.getAdSize();
mGoogleAd.setAdSizes(new com.google.android.gms.ads.AdSize(adSize.getWidth(), adSize.getHeight()));
mGoogleAd.setAdUnitId(adServerSettings.getAdUnitId());
mGoogleAd.setAdListener(mGoogleBannerListener);
} else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
mGoogleInterstitial = new PublisherInterstitialAd(mContext);
mGoogleInterstitial.setAdUnitId(adServerSettings.getAdUnitId());
mGoogleInterstitial.setAdListener(mGoogleInterstitialListener);
}
PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder();
for (String key : mKeywords.keySet()) {
if (mKeywords.containsKey(key)) {
adRequestBuilder.addCustomTargeting(key, mKeywords.get(key));
}
}
adRequest = adRequestBuilder.build();
if (generalSettings.getAdFormat() == AdFormat.BANNER) {
mGoogleAd.loadAd(adRequest);
} else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
mGoogleInterstitial.loadAd(adRequest);
}
checkRequestForKeywordsAM(adRequest);
}
}
use of org.prebid.mobile.drprebid.model.PrebidServerSettings in project prebid-mobile-android by prebid.
the class LineItemKeywordManager method refreshCacheIds.
public void refreshCacheIds(Context context) {
mAppNexusCacheIds = new HashMap<>();
mRubiconCacheIds = new HashMap<>();
mCustomServerCacheIds = new HashMap<>();
PrebidServerSettings serverSettings = SettingsManager.getInstance(context).getPrebidServerSettings();
String customServerCacheUrl = null;
if (TextUtils.isEmpty(serverSettings.getCustomPrebidServerUrl())) {
Uri.Builder uriBuilder = Uri.parse(serverSettings.getCustomPrebidServerUrl()).buildUpon();
uriBuilder.appendPath("cache");
customServerCacheUrl = uriBuilder.build().toString();
}
try {
JSONObject creative300x250 = new JSONObject(CREATIVE_300x250);
JSONObject content300x250 = new JSONObject();
content300x250.put("type", "json");
content300x250.put("value", creative300x250);
JSONObject creative300x600 = new JSONObject(CREATIVE_300x600);
JSONObject content300x600 = new JSONObject();
content300x600.put("type", "json");
content300x600.put("value", creative300x600);
JSONObject creative320x50 = new JSONObject(CREATIVE_320x50);
JSONObject content320x50 = new JSONObject();
content320x50.put("type", "json");
content320x50.put("value", creative320x50);
JSONObject creative320x100 = new JSONObject(CREATIVE_320x100);
JSONObject content320x100 = new JSONObject();
content320x100.put("type", "json");
content320x100.put("value", creative320x100);
JSONObject creative320x480 = new JSONObject(CREATIVE_320x480);
JSONObject content320x480 = new JSONObject();
content320x480.put("type", "json");
content320x480.put("value", creative320x480);
JSONObject creative728x90 = new JSONObject(CREATIVE_728x90);
JSONObject content728x90 = new JSONObject();
content728x90.put("type", "json");
content728x90.put("value", creative728x90);
JSONArray contentArray = new JSONArray();
contentArray.put(content300x250);
contentArray.put(content300x600);
contentArray.put(content320x50);
contentArray.put(content320x100);
contentArray.put(content320x480);
contentArray.put(content728x90);
JSONObject postObject = new JSONObject();
postObject.put("puts", contentArray);
String postBody = postObject.toString();
MediaType jsonMediaType = MediaType.parse("application/json");
OkHttpClient client = new OkHttpClient.Builder().build();
RequestBody body = RequestBody.create(jsonMediaType, postBody);
Request appNexusRequest = new Request.Builder().url(CACHE_ENDPOINT_APPNEXUS).post(body).build();
Request rubiconRequest = new Request.Builder().url(CACHE_ENDPOINT_RUBICON).post(body).build();
client.newCall(appNexusRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
String responseText = IOUtil.getStringFromStream(inputStream);
inputStream.close();
try {
JSONObject responseJson = new JSONObject(responseText);
JSONArray uuids = responseJson.getJSONArray("responses");
mAppNexusCacheIds.put("300x250", uuids.getJSONObject(0).getString("uuid"));
mAppNexusCacheIds.put("300x600", uuids.getJSONObject(1).getString("uuid"));
mAppNexusCacheIds.put("320x50", uuids.getJSONObject(2).getString("uuid"));
mAppNexusCacheIds.put("320x100", uuids.getJSONObject(3).getString("uuid"));
mAppNexusCacheIds.put("320x480", uuids.getJSONObject(4).getString("uuid"));
mAppNexusCacheIds.put("728x90", uuids.getJSONObject(5).getString("uuid"));
} catch (JSONException exception) {
Log.e(TAG, exception.getMessage());
}
}
}
});
client.newCall(rubiconRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
String responseText = IOUtil.getStringFromStream(inputStream);
inputStream.close();
try {
JSONObject responseJson = new JSONObject(responseText);
JSONArray uuids = responseJson.getJSONArray("responses");
mRubiconCacheIds.put("300x250", uuids.getJSONObject(0).getString("uuid"));
mRubiconCacheIds.put("300x600", uuids.getJSONObject(1).getString("uuid"));
mRubiconCacheIds.put("320x50", uuids.getJSONObject(2).getString("uuid"));
mRubiconCacheIds.put("320x100", uuids.getJSONObject(3).getString("uuid"));
mRubiconCacheIds.put("320x480", uuids.getJSONObject(4).getString("uuid"));
mRubiconCacheIds.put("728x90", uuids.getJSONObject(5).getString("uuid"));
} catch (JSONException exception) {
Log.e(TAG, exception.getMessage());
}
}
}
});
if (!TextUtils.isEmpty(customServerCacheUrl)) {
Request customRequest = new Request.Builder().url(customServerCacheUrl).post(body).build();
client.newCall(customRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
String responseText = IOUtil.getStringFromStream(inputStream);
inputStream.close();
try {
JSONObject responseJson = new JSONObject(responseText);
JSONArray uuids = responseJson.getJSONArray("responses");
mCustomServerCacheIds.put("300x250", uuids.getJSONObject(0).getString("uuid"));
mCustomServerCacheIds.put("300x600", uuids.getJSONObject(1).getString("uuid"));
mCustomServerCacheIds.put("320x50", uuids.getJSONObject(2).getString("uuid"));
mCustomServerCacheIds.put("320x100", uuids.getJSONObject(3).getString("uuid"));
mCustomServerCacheIds.put("320x480", uuids.getJSONObject(4).getString("uuid"));
mCustomServerCacheIds.put("728x90", uuids.getJSONObject(5).getString("uuid"));
} catch (JSONException exception) {
Log.e(TAG, exception.getMessage());
}
}
}
});
}
} catch (Exception exception) {
Log.e(TAG, exception.getMessage());
}
}
use of org.prebid.mobile.drprebid.model.PrebidServerSettings in project prebid-mobile-android by prebid.
the class SettingsManager method getPrebidServerSettings.
public PrebidServerSettings getPrebidServerSettings() {
PrebidServerSettings settings = new PrebidServerSettings();
switch(mSharedPreferences.getInt(Constants.Settings.PREBID_SERVER, Constants.Settings.PrebidServerCodes.APPNEXUS)) {
case Constants.Settings.PrebidServerCodes.APPNEXUS:
settings.setPrebidServer(PrebidServer.APPNEXUS);
settings.setCustomPrebidServerUrl("");
break;
case Constants.Settings.PrebidServerCodes.RUBICON:
settings.setPrebidServer(PrebidServer.RUBICON);
settings.setCustomPrebidServerUrl("");
break;
case Constants.Settings.PrebidServerCodes.CUSTOM:
settings.setPrebidServer(PrebidServer.CUSTOM);
settings.setCustomPrebidServerUrl(mSharedPreferences.getString(Constants.Settings.PREBID_SERVER_CUSTOM_URL, ""));
break;
default:
settings.setPrebidServer(PrebidServer.APPNEXUS);
}
settings.setAccountId(mSharedPreferences.getString(Constants.Settings.ACCOUNT_ID, ""));
settings.setConfigId(mSharedPreferences.getString(Constants.Settings.CONFIG_ID, ""));
return settings;
}
Aggregations