use of com.xrtb.exchanges.Nexage 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();
}
Aggregations