Skip to content

Commit

Permalink
Support Video for GetIntent adapter (prebid#987)
Browse files Browse the repository at this point in the history
* Update getintent.js

* Update getintent_spec.js

* Update getintent.js

* Update getintent.js

* Update getintent_spec.js

* fix test

* added to list of video adapters

* fixy with closures.

* jshint fixes

* Update getintent.js

fixy

* Update getintent.js

bid.descriptionUrl = bidResponse.vast_url;
  • Loading branch information
dmart28 authored and Will Alexander committed Mar 6, 2017
1 parent 612180e commit f6d9c4e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
7 changes: 6 additions & 1 deletion adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"conversant",
"districtmDMX",
"fidelity",
"getintent",
"gumgum",
"hiromedia",
"indexExchange",
"kruxlink",
"getintent",
"komoona",
"lifestreet",
"mantis",
Expand Down Expand Up @@ -102,6 +102,11 @@
"adkernel": {
"alias": "headbidding"
}
},
{
"getintent": {
"supportedMediaTypes" : ["video"]
}
}

]
43 changes: 27 additions & 16 deletions src/adapters/getintent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*jshint loopfunc: true */

import { STATUS } from 'src/constants';

var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader.js');
Expand Down Expand Up @@ -33,25 +35,34 @@ var GetIntentAdapter = function GetIntentAdapter() {
pid: bidRequest.params.pid, // required
tid: bidRequest.params.tid, // required
known: bidRequest.params.known || 1,
is_video: bidRequest.mediaType === 'video',
video: bidRequest.params.video || {},
size: bidRequest.sizes[0].join("x"),
};
addOptional(bidRequest.params, request, ['cur', 'floor']);
window.gi_hb.makeBid(request, function(bidResponse) {
if (bidResponse.no_bid === 1) {
var nobid = bidfactory.createBid(2);
nobid.bidderCode = bidRequest.bidder;
bidmanager.addBidResponse(bidRequest.placementCode, nobid);
} else {
var size = bidResponse.size.split('x');
var bid = bidfactory.createBid(1);
bid.bidderCode = bidRequest.bidder;
bid.cpm = bidResponse.cpm;
bid.ad = bidResponse.ad;
bid.width = size[0];
bid.height = size[1];
bidmanager.addBidResponse(bidRequest.placementCode, bid);
}
});
(function (r, br) {
window.gi_hb.makeBid(r, function(bidResponse) {
if (bidResponse.no_bid === 1) {
var nobid = bidfactory.createBid(STATUS.NO_BID);
nobid.bidderCode = br.bidder;
bidmanager.addBidResponse(br.placementCode, nobid);
} else {
var bid = bidfactory.createBid(STATUS.GOOD);
var size = bidResponse.size.split('x');
bid.bidderCode = br.bidder;
bid.cpm = bidResponse.cpm;
bid.width = size[0];
bid.height = size[1];
if (br.mediaType === 'video') {
bid.vastUrl = bidResponse.vast_url;
bid.descriptionUrl = bidResponse.vast_url;
} else {
bid.ad = bidResponse.ad;
}
bidmanager.addBidResponse(br.placementCode, bid);
}
});
})(request, bidRequest);
}
}

Expand Down
34 changes: 31 additions & 3 deletions test/spec/adapters/getintent_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Adapter from '../../../src/adapters/getintent';
import bidManager from '../../../src/bidmanager';
import {expect} from 'chai';

var assert = require('chai').assert;

describe('getintent media adapter test', () => {

let adapter;
Expand All @@ -17,10 +19,16 @@ describe('getintent media adapter test', () => {
cpm : 2.71,
size : `${bidRequest.size}`
}, bidRequest);
} else {
} else if (pid == "p3") {
callback({
no_bid: 1
}, bidRequest);
} else if (pid == "p4") {
callback({
vast_url : `http://test.com?pid=${pid}&tid=${tid}`,
cpm : 2.88,
size : `${bidRequest.size}`
}, bidRequest);
}
}
};
Expand Down Expand Up @@ -58,6 +66,17 @@ describe('getintent media adapter test', () => {
tid: "t2",
cur: "USD"
}
},
{
bidder: "getintent",
adUnitCode: "test4",
mediaType: 'video',
sizes: [[480,352]],
params: {
pid: "p4",
tid: "t3",
cur: "USD"
}
}
]
});
Expand All @@ -75,21 +94,23 @@ describe('getintent media adapter test', () => {
let firstBid;
let secondBid;
let thirdBid;
let videoBid;

beforeEach(() => {
sinon.stub(bidManager, 'addBidResponse');
callOut();
firstBid = bidManager.addBidResponse.firstCall.args[1];
secondBid = bidManager.addBidResponse.secondCall.args[1];
thirdBid = bidManager.addBidResponse.thirdCall.args[1];
videoBid = bidManager.addBidResponse.lastCall.args[1];
});

afterEach(() => {
bidManager.addBidResponse.restore();
});

it('was called three times', () => {
sinon.assert.calledThrice(bidManager.addBidResponse);
it('was called four times', () => {
assert.strictEqual(bidManager.addBidResponse.callCount, 4);
});

it('will respond to the first bid', () => {
Expand All @@ -116,6 +137,13 @@ describe('getintent media adapter test', () => {
expect(secondBid).to.have.property('bidderCode', 'getintent');
expect(thirdBid).to.have.property('bidderCode', 'getintent');
});

it('will respond to the video bid', () => {
expect(videoBid).to.have.property('vastUrl', 'http://test.com?pid=p4&tid=t3');
expect(videoBid).to.have.property('cpm', 2.88);
expect(videoBid).to.have.property('width', '480');
expect(videoBid).to.have.property('height', '352');
});
});

});

0 comments on commit f6d9c4e

Please sign in to comment.