Skip to content

Commit

Permalink
DMX: Enforcing w and h in imp (#1778)
Browse files Browse the repository at this point in the history
Co-authored-by: steve-a-districtm <[email protected]>
  • Loading branch information
stevealliance and steve-a-districtm authored Mar 31, 2021
1 parent 690fe2d commit 056b7cc
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 10 deletions.
50 changes: 40 additions & 10 deletions adapters/dmx/dmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type dmxParams struct {
Bidfloor float64 `json:"bidfloor,omitempty"`
}

var protocols = []openrtb2.Protocol{2, 3, 5, 6, 7, 8}

func UserSellerOrPubId(str1, str2 string) string {
if str1 != "" {
return str1
Expand Down Expand Up @@ -100,6 +102,12 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
if dmxReq.App.ID != "" {
anyHasId = true
}
if anyHasId == false {
if idfa, valid := getIdfa(request); valid {
dmxReq.App.ID = idfa
anyHasId = true
}
}
} else {
dmxReq.App = nil
}
Expand Down Expand Up @@ -147,13 +155,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
}
}

if anyHasId == false {
return nil, []error{errors.New("This request contained no identifier")}
}

for _, inst := range dmxReq.Imp {
var banner *openrtb2.Banner
var video *openrtb2.Video
var ins openrtb2.Imp
var params dmxExt
const intVal int8 = 1
Expand All @@ -164,19 +166,19 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
if isDmxParams(params.Bidder) {
if inst.Banner != nil {
if len(inst.Banner.Format) != 0 {
banner = inst.Banner
bannerCopy := *inst.Banner
if params.Bidder.PublisherId != "" || params.Bidder.MemberId != "" {
imps = fetchParams(params, inst, ins, imps, banner, nil, intVal)
imps = fetchParams(params, inst, ins, imps, &bannerCopy, nil, intVal)
} else {
return nil, []error{errors.New("Missing Params for auction to be send")}
}
}
}

if inst.Video != nil {
video = inst.Video
videoCopy := *inst.Video
if params.Bidder.PublisherId != "" || params.Bidder.MemberId != "" {
imps = fetchParams(params, inst, ins, imps, nil, video, intVal)
imps = fetchParams(params, inst, ins, imps, nil, &videoCopy, intVal)
} else {
return nil, []error{errors.New("Missing Params for auction to be send")}
}
Expand All @@ -187,6 +189,10 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt

dmxReq.Imp = imps

if anyHasId == false {
return nil, []error{errors.New("This request contained no identifier")}
}

oJson, err := json.Marshal(dmxReq)

if err != nil {
Expand Down Expand Up @@ -271,10 +277,15 @@ func fetchParams(params dmxExt, inst openrtb2.Imp, ins openrtb2.Imp, imps []open
tempimp.Secure = &intVal
}
if banner != nil {
if banner.H == nil || banner.W == nil {
banner.H = &banner.Format[0].H
banner.W = &banner.Format[0].W
}
tempimp.Banner = banner
}

if video != nil {
video.Protocols = checkProtocols(video)
tempimp.Video = video
}

Expand Down Expand Up @@ -327,3 +338,22 @@ func isDmxParams(t interface{}) bool {
return false
}
}

func getIdfa(request *openrtb2.BidRequest) (string, bool) {
if request.Device == nil {
return "", false
}

device := request.Device

if device.IFA != "" {
return device.IFA, true
}
return "", false
}
func checkProtocols(imp *openrtb2.Video) []openrtb2.Protocol {
if len(imp.Protocols) > 0 {
return imp.Protocols
}
return protocols
}
148 changes: 148 additions & 0 deletions adapters/dmx/dmxtest/exemplary/idfa-to-app-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app":{
"bundle":"302324249",
"name":"Skout - iOS Match Buy",
"publisher":{
"id":"10400"
},
"storeurl":"https://itunes.apple.com/app/id302324249"
},
"device": {
"ifa": "ed6207cefff74c14878963566683c070"
},
"imp": [
{

"id": "test-imp-id",
"banner": {
"w": 300,
"h": 250,
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"dmxid": "123454",
"publisher_id": "10400"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "",
"body": {
"id": "test-request-id",
"app":{
"bundle":"302324249",
"id":"ed6207cefff74c14878963566683c070",
"name":"Skout - iOS Match Buy",
"publisher":{
"id":"10400",
"ext": {
"dmx": {
"id": "10400"
}
}
},
"storeurl":"https://itunes.apple.com/app/id302324249"
},
"device": {
"ifa": "ed6207cefff74c14878963566683c070"
},
"imp": [
{
"id": "test-imp-id",
"tagid": "123454",
"secure": 1,
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
],
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"publisher_id": "10400",
"dmxid": "123454"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 1.75,
"adid": "29681110",
"adm": "<div>banner-ads</div>",
"adomain": ["dmx.districtm.io"],
"iurl": "https://dmx.districtm.io/b/v2",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300
}]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 1.75,
"adm": "<div>banner-ads</div>",
"adid": "29681110",
"adomain": ["dmx.districtm.io"],
"iurl": "https://dmx.districtm.io/b/v2",
"cid": "958",
"crid": "29681110",
"w": 300,
"h": 250

},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit 056b7cc

Please sign in to comment.