-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Gjirafa Bidder Adapter #1944
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
Merged
Merged
Gjirafa Bidder Adapter #1944
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1fc41ec
Added Gjirafa adapter
agon-qurdina 8600e29
Add gjirafa adapter unit test
agon-qurdina cb848d9
adapter update
agon-qurdina 65bcfd6
New line
agon-qurdina 3d12027
Requested changes
agon-qurdina c1a65f0
change hello_world.html to one bid
agon-qurdina 40f792c
change hello_world.html to one bid
agon-qurdina 8efef0f
Dropping changes in gitignore and hello_world example
agon-qurdina ae713a4
hello_world changes
agon-qurdina 32eeed8
Drop hello_world and gitignore
agon-qurdina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,5 @@ typings/ | |
|
||
# MacOS system files | ||
.DS_Store | ||
|
||
modules.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'gjirafa'; | ||
const ENDPOINT_URL = 'https://gjc.gjirafa.com/Home/GetBid'; | ||
const DIMENSION_SEPARATOR = 'x'; | ||
const SIZE_SEPARATOR = ';'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
/** | ||
* 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 bid.params && (!!bid.params.placementId || (!!bid.params.minCPM && !!bid.params.minCPC)); | ||
}, | ||
/** | ||
* 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) { | ||
return validBidRequests.map(bidRequest => { | ||
let gjid = Math.floor(Math.random() * 99999999); | ||
let sizes = generateSizeParam(bidRequest.sizes); | ||
let configId = bidRequest.params.placementId || ''; | ||
let minCPM = bidRequest.params.minCPM || 0.0; | ||
let minCPC = bidRequest.params.minCPC || 0.0; | ||
let allowExplicit = bidRequest.params.explicit || 0; | ||
const body = { | ||
gjid: gjid, | ||
sizes: sizes, | ||
configId: configId, | ||
minCPM: minCPM, | ||
minCPC: minCPC, | ||
allowExplicit: allowExplicit, | ||
referrer: utils.getTopWindowUrl(), | ||
requestid: bidRequest.bidderRequestId, | ||
bidid: bidRequest.bidId | ||
}; | ||
if (document.referrer) { | ||
body.referrer = document.referrer; | ||
} | ||
return { | ||
method: 'GET', | ||
url: ENDPOINT_URL, | ||
data: body | ||
}; | ||
}); | ||
}, | ||
/** | ||
* 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 serverBody = serverResponse.body; | ||
const bidResponses = []; | ||
const bidResponse = { | ||
requestId: bidRequest.data.bidid, | ||
cpm: serverBody.CPM, | ||
width: serverBody.Width, | ||
height: serverBody.Height, | ||
creativeId: serverBody.CreativeId, | ||
currency: serverBody.Currency, | ||
netRevenue: serverBody.NetRevenue, | ||
ttl: serverBody.TTL, | ||
referrer: serverBody.Referrer, | ||
ad: serverBody.Ad | ||
}; | ||
bidResponses.push(bidResponse); | ||
return bidResponses; | ||
} | ||
} | ||
|
||
/** | ||
* Generate size param for bid request using sizes array | ||
* | ||
* @param {Array} sizes Possible sizes for the ad unit. | ||
* @return {string} Processed sizes param to be used for the bid request. | ||
*/ | ||
function generateSizeParam(sizes) { | ||
return sizes.map(size => size.join(DIMENSION_SEPARATOR)).join(SIZE_SEPARATOR); | ||
} | ||
|
||
registerBidder(spec); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Overview | ||
Module Name: Gjirafa Bidder Adapter Module | ||
Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
Gjirafa Bidder Adapter for Prebid.js. | ||
|
||
# Test Parameters | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
sizes: [[728, 90]], // leaderboard | ||
bids: [ | ||
{ | ||
bidder: 'gjirafa', | ||
params: { | ||
placementId: '71-3' | ||
} | ||
} | ||
] | ||
},{ | ||
code: 'test-div', | ||
sizes: [[300, 250]], // mobile rectangle | ||
bids: [ | ||
{ | ||
bidder: 'gjirafa', | ||
params: { | ||
minCPM: 0.0001, | ||
minCPC: 0.001, | ||
explicit: true | ||
} | ||
} | ||
] | ||
} | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/gjirafaBidAdapter'; | ||
|
||
describe('gjirafaAdapterTest', () => { | ||
describe('bidRequestValidity', () => { | ||
it('bidRequest with placementId, minCPM and minCPC params', () => { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'gjirafa', | ||
params: { | ||
placementId: 'test-div', | ||
minCPM: 0.0001, | ||
minCPC: 0.001 | ||
} | ||
})).to.equal(true); | ||
}); | ||
|
||
it('bidRequest with only placementId param', () => { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'gjirafa', | ||
params: { | ||
placementId: 'test-div' | ||
} | ||
})).to.equal(true); | ||
}); | ||
|
||
it('bidRequest with minCPM and minCPC params', () => { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'gjirafa', | ||
params: { | ||
minCPM: 0.0001, | ||
minCPC: 0.001 | ||
} | ||
})).to.equal(true); | ||
}); | ||
|
||
it('bidRequest with no placementId, minCPM or minCPC params', () => { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'gjirafa', | ||
params: { | ||
} | ||
})).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('bidRequest', () => { | ||
const bidRequests = [{ | ||
'bidder': 'gjirafa', | ||
'params': { | ||
'placementId': '71-3' | ||
}, | ||
'adUnitCode': 'hb-leaderboard', | ||
'transactionId': 'b6b889bb-776c-48fd-bc7b-d11a1cf0425e', | ||
'sizes': [[728, 90], [980, 200], [980, 150], [970, 90], [970, 250]], | ||
'bidId': '10bdc36fe0b48c8', | ||
'bidderRequestId': '70deaff71c281d', | ||
'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' | ||
}, | ||
{ | ||
'bidder': 'gjirafa', | ||
'params': { | ||
'minCPM': 0.0001, | ||
'minCPC': 0.001, | ||
'explicit': true | ||
}, | ||
'adUnitCode': 'hb-inarticle', | ||
'transactionId': '8757194d-ea7e-4c06-abc0-cfe92bfc5295', | ||
'sizes': [[300, 250]], | ||
'bidId': '81a6dcb65e2bd9', | ||
'bidderRequestId': '70deaff71c281d', | ||
'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' | ||
}]; | ||
|
||
it('bidRequest HTTP method', () => { | ||
const requests = spec.buildRequests(bidRequests); | ||
requests.forEach(function(requestItem) { | ||
expect(requestItem.method).to.equal('GET'); | ||
}); | ||
}); | ||
|
||
it('bidRequest url', () => { | ||
const endpointUrl = 'https://gjc.gjirafa.com/Home/GetBid'; | ||
const requests = spec.buildRequests(bidRequests); | ||
requests.forEach(function(requestItem) { | ||
expect(requestItem.url).to.match(new RegExp(`${endpointUrl}`)); | ||
}); | ||
}); | ||
|
||
it('bidRequest data', () => { | ||
const requests = spec.buildRequests(bidRequests); | ||
requests.forEach(function(requestItem) { | ||
expect(requestItem.data).to.exists; | ||
}); | ||
}); | ||
|
||
it('bidRequest sizes', () => { | ||
const requests = spec.buildRequests(bidRequests); | ||
expect(requests[0].data.sizes).to.equal('728x90;980x200;980x150;970x90;970x250'); | ||
expect(requests[1].data.sizes).to.equal('300x250'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', () => { | ||
const bidRequest = { | ||
'method': 'GET', | ||
'url': 'https://gjc.gjirafa.com/Home/GetBid', | ||
'data': { | ||
'gjid': 2323007, | ||
'sizes': '728x90;980x200;980x150;970x90;970x250', | ||
'configId': '71-3', | ||
'minCPM': 0, | ||
'minCPC': 0, | ||
'allowExplicit': 0, | ||
'referrer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', | ||
'requestid': '26ee8fe87940da7', | ||
'bidid': '2962dbedc4768bf' | ||
} | ||
}; | ||
|
||
const bidResponse = { | ||
body: [{ | ||
'CPM': 1, | ||
'Width': 728, | ||
'Height': 90, | ||
'Referrer': 'https://example.com/', | ||
'Ad': 'test ad', | ||
'CreativeId': '123abc', | ||
'NetRevenue': false, | ||
'Currency': 'EUR', | ||
'TTL': 360 | ||
}], | ||
headers: {} | ||
}; | ||
|
||
it('all keys present', () => { | ||
const result = spec.interpretResponse(bidResponse, bidRequest); | ||
|
||
let keys = [ | ||
'requestId', | ||
'cpm', | ||
'width', | ||
'height', | ||
'creativeId', | ||
'currency', | ||
'netRevenue', | ||
'ttl', | ||
'referrer', | ||
'ad' | ||
]; | ||
|
||
let resultKeys = Object.keys(result[0]); | ||
console.log(resultKeys); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove all console.log |
||
resultKeys.forEach(function(key) { | ||
console.log(key); | ||
console.log(keys.indexOf(key)); | ||
expect(keys.indexOf(key) !== -1).to.equal(true); | ||
}); | ||
}) | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped