Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Brightroll adapter - adding config support (prebid#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
smithaammassamveettil authored Sep 8, 2020
1 parent d517442 commit 66e0076
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 54 deletions.
81 changes: 65 additions & 16 deletions adapters/brightroll/brightroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ import (
"net/http"
"strconv"

"github.com/golang/glog"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

type BrightrollAdapter struct {
URI string
URI string
extraInfo ExtraInfo
}

type ExtraInfo struct {
Accounts []Account `json:"accounts"`
}

type Account struct {
ID string `json:"id"`
Badv []string `json:"badv"`
Bcat []string `json:"bcat"`
Battr []int8 `json:"battr"`
BidFloor float64 `json:"bidfloor"`
}

func (a *BrightrollAdapter) MakeRequests(requestIn *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
Expand Down Expand Up @@ -55,6 +69,23 @@ func (a *BrightrollAdapter) MakeRequests(requestIn *openrtb.BidRequest, reqInfo
errors = append(errors, err)
return nil, errors
}

var account *Account
for _, a := range a.extraInfo.Accounts {
if a.ID == brightrollExt.Publisher {
account = &a
break
}
}

if account == nil {
err = &errortypes.BadInput{
Message: "Invalid publisher",
}
errors = append(errors, err)
return nil, errors
}

validImpExists := false
for i := 0; i < len(request.Imp); i++ {
//Brightroll supports only banner and video impressions as of now
Expand All @@ -65,20 +96,25 @@ func (a *BrightrollAdapter) MakeRequests(requestIn *openrtb.BidRequest, reqInfo
bannerCopy.W = &(firstFormat.W)
bannerCopy.H = &(firstFormat.H)
}
if brightrollExt.Publisher == "adthrive" {
bannerCopy.BAttr = getBlockedCreativetypesForAdThrive()

if len(account.Battr) > 0 {
bannerCopy.BAttr = getBlockedCreativetypes(account.Battr)
}
request.Imp[i].Banner = &bannerCopy
validImpExists = true
} else if request.Imp[i].Video != nil {
validImpExists = true
if brightrollExt.Publisher == "adthrive" {
videoCopy := *request.Imp[i].Video
videoCopy.BAttr = getBlockedCreativetypesForAdThrive()
if len(account.Battr) > 0 {
videoCopy.BAttr = getBlockedCreativetypes(account.Battr)
}
request.Imp[i].Video = &videoCopy
}
}
if validImpExists && request.Imp[i].BidFloor == 0 && account.BidFloor > 0 {
request.Imp[i].BidFloor = account.BidFloor
}
}
if !validImpExists {
err := &errortypes.BadInput{
Expand All @@ -90,8 +126,12 @@ func (a *BrightrollAdapter) MakeRequests(requestIn *openrtb.BidRequest, reqInfo

request.AT = 1 //Defaulting to first price auction for all prebid requests

if brightrollExt.Publisher == "adthrive" {
request.BCat = getBlockedCategoriesForAdthrive()
if len(account.Bcat) > 0 {
request.BCat = account.Bcat
}

if len(account.Badv) > 0 {
request.BAdv = account.Badv
}
reqJSON, err := json.Marshal(request)
if err != nil {
Expand Down Expand Up @@ -159,13 +199,12 @@ func (a *BrightrollAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
return bidResponse, nil
}

//customized request, need following blocked categories
func getBlockedCategoriesForAdthrive() []string {
return []string{"IAB8-5", "IAB8-18", "IAB15-1", "IAB7-30", "IAB14-1", "IAB22-1", "IAB3-7", "IAB7-3", "IAB14-3", "IAB11", "IAB11-1", "IAB11-2", "IAB11-3", "IAB11-4", "IAB11-5", "IAB23", "IAB23-1", "IAB23-2", "IAB23-3", "IAB23-4", "IAB23-5", "IAB23-6", "IAB23-7", "IAB23-8", "IAB23-9", "IAB23-10", "IAB7-39", "IAB9-30", "IAB7-44", "IAB25", "IAB25-1", "IAB25-2", "IAB25-3", "IAB25-4", "IAB25-5", "IAB25-6", "IAB25-7", "IAB26", "IAB26-1", "IAB26-2", "IAB26-3", "IAB26-4"}
}

func getBlockedCreativetypesForAdThrive() []openrtb.CreativeAttribute {
return []openrtb.CreativeAttribute{openrtb.CreativeAttribute(1), openrtb.CreativeAttribute(2), openrtb.CreativeAttribute(3), openrtb.CreativeAttribute(6), openrtb.CreativeAttribute(9), openrtb.CreativeAttribute(10)}
func getBlockedCreativetypes(attr []int8) []openrtb.CreativeAttribute {
var creativeAttr []openrtb.CreativeAttribute
for i := 0; i < len(attr); i++ {
creativeAttr = append(creativeAttr, openrtb.CreativeAttribute(attr[i]))
}
return creativeAttr
}

//Adding header fields to request header
Expand All @@ -189,8 +228,18 @@ func getMediaTypeForImp(impId string, imps []openrtb.Imp) openrtb_ext.BidType {
return mediaType
}

func NewBrightrollBidder(endpoint string) *BrightrollAdapter {
return &BrightrollAdapter{
URI: endpoint,
func NewBrightrollBidder(endpoint string, extraAdapterInfo string) *BrightrollAdapter {

var extraInfo ExtraInfo

if len(extraAdapterInfo) == 0 {
extraAdapterInfo = "{\"accounts\":[]}"
}
err := json.Unmarshal([]byte(extraAdapterInfo), &extraInfo)

if err != nil {
glog.Fatalf("Invalid Brightroll extra adapter info: " + err.Error())
return nil
}
return &BrightrollAdapter{URI: endpoint, extraInfo: extraInfo}
}
28 changes: 27 additions & 1 deletion adapters/brightroll/brightroll_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
package brightroll

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/prebid/prebid-server/adapters/adapterstest"
)

func TestEmptyConfig(t *testing.T) {
output := NewBrightrollBidder("http://test-bid.ybp.yahoo.com/bid/appnexuspbs", "")
ex := ExtraInfo{
Accounts: []Account{},
}
expected := &BrightrollAdapter{
URI: "http://test-bid.ybp.yahoo.com/bid/appnexuspbs",
extraInfo: ex,
}
assert.Equal(t, expected, output, "")
}

func TestNonEmptyConfig(t *testing.T) {
output := NewBrightrollBidder("http://test-bid.ybp.yahoo.com/bid/appnexuspbs", "{\"accounts\": [{\"id\": \"test\",\"bidfloor\":0.1}]}")
ex := ExtraInfo{
Accounts: []Account{{ID: "test", BidFloor: 0.1}},
}

expected := &BrightrollAdapter{
URI: "http://test-bid.ybp.yahoo.com/bid/appnexuspbs",
extraInfo: ex,
}
assert.Equal(t, expected, output, "")
}

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "brightrolltest", NewBrightrollBidder("http://test-bid.ybp.yahoo.com/bid/appnexuspbs"))
adapterstest.RunJSONBidderTest(t, "brightrolltest", NewBrightrollBidder("http://test-bid.ybp.yahoo.com/bid/appnexuspbs", "{\"accounts\": [{\"id\": \"adthrive\",\"badv\": [], \"bcat\": [\"IAB8-5\",\"IAB8-18\"],\"battr\": [1,2,3], \"bidfloor\":0.0}]}"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -30,7 +30,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -43,7 +43,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
}
Expand All @@ -52,14 +52,23 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://test-bid.ybp.yahoo.com/bid/appnexuspbs?publisher=cafemom",
"uri": "http://test-bid.ybp.yahoo.com/bid/appnexuspbs?publisher=adthrive",
"body": {
"id": "test-request-id",
"at":1,
"bcat": [
"IAB8-5",
"IAB8-18"
],
"imp": [
{
"id": "test-imp-id",
"banner": {
"battr": [
1,
2,
3
],
"format": [
{
"w": 300,
Expand All @@ -75,7 +84,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -87,7 +96,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -100,7 +109,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -30,7 +30,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -44,7 +44,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
}
Expand All @@ -53,14 +53,23 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://test-bid.ybp.yahoo.com/bid/appnexuspbs?publisher=cafemom",
"uri": "http://test-bid.ybp.yahoo.com/bid/appnexuspbs?publisher=adthrive",
"body": {
"id": "test-request-id",
"at":1,
"bcat": [
"IAB8-5",
"IAB8-18"
],
"imp": [
{
"id": "test-imp-id",
"banner": {
"battr": [
1,
2,
3
],
"format": [
{
"w": 300,
Expand All @@ -76,7 +85,7 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
Expand All @@ -88,21 +97,26 @@
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
},
{
"id": "test-imp-video-id",
"video": {
"battr": [
1,
2,
3
],
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 1024,
"h": 576
},
"ext": {
"bidder": {
"publisher": "cafemom"
"publisher": "adthrive"
}
}
}
Expand Down
Loading

0 comments on commit 66e0076

Please sign in to comment.