use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class Creative method createSample.
/**
* Creates a sample of the ADM field, useful for testing your ad markup to
* make sure it works.
*
* @param camp
* Campaign. The campaign to use with this creative.
* @return String. The ad markup HTML.
*/
public String createSample(Campaign camp) {
BidRequest request = new Nexage();
String page = null;
String str = null;
File temp = null;
Impression imp = new Impression();
imp.w = 666;
imp.h = 666;
BidResponse br = null;
try {
if (this.isVideo()) {
br = new BidResponse(request, imp, camp, this, "123", 1.0, null, 0);
imp.video = new Video();
imp.video.linearity = this.videoLinearity;
imp.video.protocol.add(this.videoProtocol);
imp.video.maxduration = this.videoDuration + 1;
imp.video.minduration = this.videoDuration - 1;
str = br.getAdmAsString();
/**
* Read in the stubbed video page and patch the VAST into it
*/
page = new String(Files.readAllBytes(Paths.get("web/videostub.html")), StandardCharsets.UTF_8);
page = page.replaceAll("___VIDEO___", "http://localhost:8080/vast/onion270.xml");
} else if (this.isNative()) {
// br = new BidResponse(request, camp, this,"123",0);
// request.nativead = true;
// request.nativePart = new NativePart();
// str = br.getAdmAsString();
page = "<html><title>Test Creative</title><body><img src='images/under-construction.gif'></img></body></html>";
} else {
br = new BidResponse(request, imp, camp, this, "123", 1.0, null, 0);
str = br.getAdmAsString();
page = "<html><title>Test Creative</title><body><xmp>" + str + "</xmp>" + str + "</body></html>";
}
page = page.replaceAll("\\{AUCTION_PRICE\\}", "0.2");
page = page.replaceAll("\\$", "");
temp = File.createTempFile("test", ".html", new File("www/temp"));
temp.deleteOnExit();
Files.write(Paths.get(temp.getAbsolutePath()), page.getBytes());
} catch (Exception error) {
error.printStackTrace();
}
return "temp/" + temp.getName();
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class Appnexus method buildNewBidResponse.
@Override
public BidResponse buildNewBidResponse(Impression imp, List<SelectedCreative> multi, int xtime) throws Exception {
for (int i = 0; i < multi.size(); i++) {
SelectedCreative x = multi.get(i);
Creative c = x.getCreative();
if (c.extensions == null || c.extensions.size() == 0)
throw new Exception(x.getCampaign().adId + "/" + c.impid + " is missing required extensions for Appnexus SSP");
String adid = c.extensions.get("appnexus_crid");
if (adid == null)
adid = "invalid:unassigned";
c.alternateAdId = adid;
}
BidResponse response = new BidResponse(this, imp, multi, xtime);
StringBuilder sb = response.getResponseBuffer();
return response;
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class Record method getInstance.
public static synchronized Record getInstance(Object x) {
long time = 0;
long wins = 0;
long bids = 0;
long requests = 0;
double bidPrice = 0;
double winCost = 0;
if (x instanceof Map) {
Map r = (Map) x;
r = (Map) r.get("ext");
time = (long) r.get("timestamp");
requests++;
} else if (x instanceof BidResponse) {
BidResponse r = (BidResponse) x;
time = r.utc;
bids++;
bidPrice = r.cost;
} else if (x instanceof WinObject) {
WinObject r = (WinObject) x;
time = r.utc;
wins++;
winCost = Double.parseDouble(r.price);
}
Date date = new Date(time);
String key = format.format(date);
Record r = records.get(key);
if (r == null) {
r = new Record(x);
records.put(key, r);
}
r.bidPrice.add(bidPrice);
r.winPrice.add(winCost);
r.bids.add(bids);
r.wins.add(wins);
r.requests.add(requests);
return r;
}
Aggregations