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

Emxd 3336 add app video ctv #1529

Merged
merged 9 commits into from
Oct 21, 2020
75 changes: 69 additions & 6 deletions adapters/emx_digital/emx_digital.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ func buildImpBanner(imp *openrtb.Imp) error {
return nil
}

func buildImpVideo(imp *openrtb.Imp) error {
imp.Ext = nil
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

if len(imp.Video.MIMEs) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Video: missing required field mimes"),
}
}

if imp.Video.H == 0 && imp.Video.W == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Video: Need at least one size to build request"),
}
}

if imp.Video.Protocols != nil {
imp.Video.Protocols = cleanProtocol(imp.Video.Protocols)
}

return nil
}

// not supporting VAST protocol 7 (VAST 4.0);
func cleanProtocol(protocols []openrtb.Protocol) []openrtb.Protocol {
newitems := []openrtb.Protocol{}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

for _, i := range protocols {
if i != openrtb.ProtocolVAST40 {
newitems = append(newitems, i)
}
}

return newitems
}

// Add EMX required properties to Imp object
func addImpProps(imp *openrtb.Imp, secure *int8, emxExt *openrtb_ext.ExtImpEmxDigital) {
imp.TagID = emxExt.TagID
Expand Down Expand Up @@ -170,14 +205,22 @@ func preprocess(request *openrtb.BidRequest) []error {
errors := make([]error, 0, impsCount)
resImps := make([]openrtb.Imp, 0, impsCount)
secure := int8(0)

domain := ""
if request.Site != nil && request.Site.Page != "" {
pageURL, err := url.Parse(request.Site.Page)
if err == nil && pageURL.Scheme == "https" {
secure = int8(1)
domain = request.Site.Page
} else if request.App != nil {
if request.App.Domain != "" {
domain = request.App.Domain
} else if request.App.StoreURL != "" {
domain = request.App.StoreURL
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
}
}

pageURL, err := url.Parse(domain)
if err == nil && pageURL.Scheme == "https" {
secure = int8(1)
}

for _, imp := range request.Imp {
emxExt, err := unpackImpExt(&imp)
if err != nil {
Expand All @@ -187,10 +230,17 @@ func preprocess(request *openrtb.BidRequest) []error {

addImpProps(&imp, &secure, emxExt)

if err := buildImpBanner(&imp); err != nil {
if imp.Video != nil {
if err := buildImpVideo(&imp); err != nil {
errors = append(errors, err)
continue
}
} else if err := buildImpBanner(&imp); err != nil {
errors = append(errors, err)
continue

}

resImps = append(resImps, imp)
}

Expand Down Expand Up @@ -229,7 +279,7 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: "banner",
BidType: getBidType(sb.Bid[i].ImpID, internalRequest.Imp),
})
}
}
Expand All @@ -238,6 +288,19 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern

}

func getBidType(impID string, imps []openrtb.Imp) openrtb_ext.BidType {
bidType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impID {
if imp.Video != nil {
bidType = openrtb_ext.BidTypeVideo
}
break
}
}
return bidType
}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

func NewEmxDigitalBidder(endpoint string) *EmxDigitalAdapter {
return &EmxDigitalAdapter{
endpoint: endpoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"mockBidRequest": {
"id": "some_test_auction",
"imp": [{
"id": "some_test_ad_id",
"banner": {
"format": [{
"w": 300,
"h": 250
}],
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"tagid": "25251"
}
}
},
{
"id": "some_test_ad_id",
"video":{
"mimes": [
"video/mp4",
"application/javascript"
],
"protocols":[
2,
3,
5,
6
],
"w":640,
"h":480
},
"ext": {
"bidder": {
"tagid": "25251"
}
}
}],
"device": {
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
"ip": "123.123.123.123",
"dnt": 1
},
"app": {
"domain": "www.publisher.com",
"storeurl": "http://www.publisher.com/awesome/site?with=some&parameters=here"
}
},

"httpCalls": [{
"expectedRequest": {
"uri": "https://hb.emxdgt.com?t=1000&ts=2060541160",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"X-Forwarded-For": [
"123.123.123.123"
],
"Dnt": [
"1"
],
"User-Agent": [
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
]
},
"body": {
"id": "some_test_auction",
"imp": [{
"id": "some_test_ad_id",
"banner": {
"format": [{
"w": 300,
"h": 250
}],
"w": 300,
"h": 250
},
"tagid": "25251",
"secure": 0
},
{
"id": "some_test_ad_id",
"video":{
"mimes": [
"video/mp4",
"application/javascript"
],
"protocols":[
2,
3,
5,
6
],
"w":640,
"h":480
},
"tagid": "25251",
"secure": 0
}],
"app": {
"domain": "www.publisher.com",
"storeurl": "http://www.publisher.com/awesome/site?with=some&parameters=here"
},
"device": {
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
"ip": "123.123.123.123",
"dnt": 1
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "some_test_auction",
"seatbid": [{
"seat": "12356",
"bid": [{
"adm": "some-test-ad",
"id": "uuid",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
"w": 300,
"price": 2.942808,
"adid": "94395500",
"h": 250
}]
}],
"cur": "USD"
}
}
}],

"expectedBids": [{
"bid": {
"adm": "some-test-ad",
"id": "uuid",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
"w": 300,
"price": 2.942808,
"adid": "94395500",
"h": 250
},
"type": "banner"
}]
}

Loading