Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bid adapter for Missena #6247

Merged
16 commits merged into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as utils from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'missena';
const ENDPOINT_URL = 'https://bid.missena.io/';

export const spec = {
This conversation was marked as resolved.
Show resolved Hide resolved
aliases: [BIDDER_CODE],
code: BIDDER_CODE,
gvlid: 687,
supportedMediaTypes: [BANNER],

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return typeof bid == 'object' && !!bid.params.apiKey;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
This conversation was marked as resolved.
Show resolved Hide resolved
return validBidRequests.map((bidRequest) => {
const payload = {
request_id: bidRequest.bidId,
timeout: bidderRequest.timeout,
};

if (bidderRequest && bidderRequest.refererInfo) {
payload.referer = bidderRequest.refererInfo.referer;
payload.referer_canonical = bidderRequest.refererInfo.canonicalUrl;
}

if (bidderRequest && bidderRequest.gdprConsent) {
payload.consent_string = bidderRequest.gdprConsent.consentString;
payload.consent_required = bidderRequest.gdprConsent.gdprApplies;
}

return {
method: 'POST',
url:
ENDPOINT_URL +
'?' +
utils.formatQS({
t: bidRequest.params.apiKey,
}),
data: JSON.stringify(payload),
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;

if (response && !response.timeout && !!response.ad) {
bidResponses.push(response);
}

return bidResponses;
},

/**
* Register bidder specific code, which will execute if bidder timed out after an auction
* @param {data} Containing timeout specific data
*/
onTimeout: function onTimeout(timeoutData) {
utils.logInfo('Missena - Timeout from adapter', timeoutData);
},

/**
* Register bidder specific code, which@ will execute if a bid from this bidder won the auction
* @param {Bid} The bid that won the auction
*/
onBidWon: function (bid) {
utils.logInfo('Missena - Bid won', bid);
},
};

registerBidder(spec);
70 changes: 70 additions & 0 deletions modules/missenaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Overview

```
Module Name: Missena Bid Adapter
Module Type: Bidder Adapter
Maintainer: jney@missena.com
```

## Introduction

Connects to Missena for bids.

**Note:** this adapter doesn't support SafeFrame.

Useful resources:

- [README](../README.md#Build)
- [https://docs.prebid.org/dev-docs/bidder-adaptor.html](https://docs.prebid.org/dev-docs/bidder-adaptor.html)

## Develop

Setup the missena adapter in `integrationExamples/gpt/userId_example.html`.

For example:

```js
const AD_UNIT_CODE = "test-div";
const PUBLISHER_MISSENA_TOKEN = "PA-34745704";

var adUnits = [
{
code: AD_UNIT_CODE,
mediaTypes: {
banner: {
sizes: [1, 1],
},
},
bids: [
{
bidder: "missena",
params: {
apiKey: PUBLISHER_MISSENA_TOKEN,
},
},
],
},
];
```

Then start the demo app:

```shell
gulp serve-fast --modules=missenaBidAdapter
```

And open [http://localhost:9999/integrationExamples/gpt/userId_example.html](http://localhost:9999/integrationExamples/gpt/userId_example.html)

## Test

```shell
gulp test --file test/spec/modules/missenaBidAdapter_spec.js
```

Add the `--watch` option to re-run unit tests whenever the source code changes.

## Build

```shell
gulp build --modules=missenaBidAdapter
```
131 changes: 131 additions & 0 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { expect } from 'chai';
import { spec, _getPlatform } from 'modules/missenaBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';

describe('Missena Adapter', function () {
const adapter = newBidder(spec);

const bidId = 'abc';

const bid = {
bidder: 'missena',
bidId: bidId,
sizes: [[1, 1]],
params: {
apiKey: 'PA-34745704',
},
};

describe('codes', function () {
it('should return a bidder code of missena', function () {
expect(spec.code).to.equal('missena');
});
});

describe('isBidRequestValid', function () {
it('should return true if the apiKey param is present', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false if the apiKey is missing', function () {
expect(
spec.isBidRequestValid(Object.assign(bid, { params: {} }))
).to.equal(false);
});

it('should return false if the apiKey is an empty string', function () {
expect(
spec.isBidRequestValid(Object.assign(bid, { params: { apiKey: '' } }))
).to.equal(false);
});
});

describe('buildRequests', function () {
const consentString = 'AAAAAAAAA==';

const bidderRequest = {
gdprConsent: {
consentString: consentString,
gdprApplies: true,
},
refererInfo: {
referer: 'https://referer',
canonicalUrl: 'https://canonical',
},
};

const requests = spec.buildRequests([bid, bid], bidderRequest);
const request = requests[0];
const payload = JSON.parse(request.data);

it('should return as many server requests as bidder requests', function () {
expect(requests.length).to.equal(2);
});

it('should have a post method', function () {
expect(request.method).to.equal('POST');
});

it('should send the bidder id', function () {
expect(payload.request_id).to.equal(bidId);
});

it('should send referer information to the request', function () {
expect(payload.referer).to.equal('https://referer');
expect(payload.referer_canonical).to.equal('https://canonical');
});

it('should send gdpr consent information to the request', function () {
expect(payload.consent_string).to.equal(consentString);
expect(payload.consent_required).to.equal(true);
});
});

describe('interpretResponse', function () {
const serverResponse = {
requestId: bidId,
cpm: 0.5,
currency: 'USD',
ad: '<!-- -->',
};

const serverTimeoutResponse = {
requestId: bidId,
timeout: true,
ad: '<!-- -->',
};

const serverEmptyAdResponse = {
requestId: bidId,
cpm: 0.5,
currency: 'USD',
ad: '',
};

it('should return a proper bid response', function () {
const result = spec.interpretResponse({ body: serverResponse }, bid);

expect(result.length).to.equal(1);

expect(Object.keys(result[0])).to.have.members(
Object.keys(serverResponse)
);
});

it('should return an empty response when the server answers with a timeout', function () {
const result = spec.interpretResponse(
{ body: serverTimeoutResponse },
bid
);
expect(result).to.deep.equal([]);
});

it('should return an empty response when the server answers with an empty ad', function () {
const result = spec.interpretResponse(
{ body: serverEmptyAdResponse },
bid
);
expect(result).to.deep.equal([]);
});
});
});