Skip to content

Commit

Permalink
Update dgadsBidAdapter (prebid#3048)
Browse files Browse the repository at this point in the history
* Add dgads adapter

* Add dgads adapter

* Add spec file for dgads

* Add spec file for dgads

* Add dgads bid adapter

* Add dgads bid adapter

* fix

* fix

* fix email

* remove  semi-colon

* Add mediaType native

* Add import medaTypes

* Change method to 'GET' and Change parameter name and Add get cookie.

* fix camelcase

* fix space

* revert to normal function
  • Loading branch information
r-sato authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 870e134 commit f55b34e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
21 changes: 18 additions & 3 deletions modules/dgadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as utils from 'src/utils';
import { BANNER, NATIVE } from 'src/mediaTypes';

const BIDDER_CODE = 'dgads';
const UID_NAME = 'dgads_uid';
const ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid';

export const spec = {
Expand All @@ -27,13 +28,15 @@ export const spec = {
const params = bidRequest.params;
const data = {};

data['location_id'] = params.location_id;
data['site_id'] = params.site_id;
data['_loc'] = params.location_id;
data['_medium'] = params.site_id;
data['transaction_id'] = bidRequest.transactionId;
data['bid_id'] = bidRequest.bidId;
data['referer'] = utils.getTopWindowUrl();
data['_uid'] = getCookieUid(UID_NAME);

return {
method: 'POST',
method: 'GET',
url: ENDPOINT,
data,
};
Expand Down Expand Up @@ -84,5 +87,17 @@ function setNativeResponse(ad) {
nativeResponce.impressionTrackers = ad.impressionTrackers || [];
return nativeResponce;
}
export function getCookieUid(uidName) {
if (utils.cookiesAreEnabled()) {
let cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let value = cookies[i].split('=');
if (value[0].indexOf(uidName) > -1) {
return value[1];
}
}
}
return '';
}

registerBidder(spec);
20 changes: 14 additions & 6 deletions test/spec/modules/dgadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {expect} from 'chai';
import * as utils from 'src/utils';
import {spec} from 'modules/dgadsBidAdapter';
import {spec, getCookieUid} from 'modules/dgadsBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';
import { BANNER, NATIVE } from 'src/mediaTypes';

describe('dgadsBidAdapter', function () {
const adapter = newBidder(spec);
const UID_NAME = 'dgads_uid';
const VALID_ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid';

describe('inherited functions', function () {
Expand Down Expand Up @@ -101,23 +102,30 @@ describe('dgadsBidAdapter', function () {
const noBidRequests = [];
expect(Object.keys(spec.buildRequests(noBidRequests)).length).to.equal(0);
});
it('getCookieUid return empty if cookie not found', function () {
expect(getCookieUid(UID_NAME)).to.equal('');
});
const data = {
location_id: '1',
site_id: '1',
transaction_id: 'c1f1eff6-23c6-4844-a321-575212939e37',
bid_id: '2db3101abaec66'
bid_id: '2db3101abaec66',
referer: utils.getTopWindowUrl(),
_uid: ''
};
it('sends bid request to VALID_ENDPOINT via POST', function () {
it('sends bid request to VALID_ENDPOINT via GET', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.url).to.equal(VALID_ENDPOINT);
expect(request.method).to.equal('POST');
expect(request.method).to.equal('GET');
});
it('should attache params to the request', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.data['location_id']).to.equal(data['location_id']);
expect(request.data['site_id']).to.equal(data['site_id']);
expect(request.data['_loc']).to.equal(data['location_id']);
expect(request.data['_medium']).to.equal(data['site_id']);
expect(request.data['transaction_id']).to.equal(data['transaction_id']);
expect(request.data['bid_id']).to.equal(data['bid_id']);
expect(request.data['referer']).to.equal(data['referer']);
expect(request.data['_uid']).to.equal(data['_uid']);
});
});

Expand Down

0 comments on commit f55b34e

Please sign in to comment.