diff --git a/adapters/emx_digital/emx_digital.go b/adapters/emx_digital/emx_digital.go index ccaa96e67ad..4bdb25fd155 100644 --- a/adapters/emx_digital/emx_digital.go +++ b/adapters/emx_digital/emx_digital.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "time" "github.com/mxmCherry/openrtb" @@ -110,7 +111,6 @@ func unpackImpExt(imp *openrtb.Imp) (*openrtb_ext.ExtImpEmxDigital, error) { } func buildImpBanner(imp *openrtb.Imp) error { - imp.Ext = nil if imp.Banner == nil { return &errortypes.BadInput{ @@ -137,6 +137,40 @@ func buildImpBanner(imp *openrtb.Imp) error { return nil } +func buildImpVideo(imp *openrtb.Imp) error { + + 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 := make([]openrtb.Protocol, 0, len(protocols)) + + 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 @@ -170,14 +204,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 } } + 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 { @@ -187,10 +229,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) } @@ -229,7 +278,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].AdM), }) } } @@ -238,6 +287,24 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern } +func getBidType(bidAdm string) openrtb_ext.BidType { + if bidAdm != "" && ContainsAny(bidAdm, []string{"", + "id": "some_test_ad_id_1", + "impid": "some_test_ad_id_1", + "ttl": 300, + "crid": "94395500", + "w": 300, + "price": 2.942808, + "adid": "94395500", + "h": 250 + }] + }, + { + "seat": "45678", + "bid": [{ + "adm": "00:00:15", + "id": "some_test_ad_id_2", + "impid": "some_test_ad_id_2", + "ttl": 300, + "crid": "9999999", + "w": 1020, + "price": 1, + "adid": "9999999", + "h": 1000 + } + ] + }], + "cur": "USD" + } + } + }], + + "expectedBids": [ + { + "bid": { + "adm": "
", + "id": "some_test_ad_id_1", + "impid": "some_test_ad_id_1", + "ttl": 300, + "crid": "94395500", + "w": 300, + "price": 2.942808, + "adid": "94395500", + "h": 250 + }, + "type": "banner" + }, + { + "bid": { + "adm": "00:00:15", + "id": "some_test_ad_id_2", + "impid": "some_test_ad_id_2", + "ttl": 300, + "crid": "9999999", + "w": 1020, + "price": 1, + "adid": "9999999", + "h": 1000 + }, + "type": "video" + } + ] +} + \ No newline at end of file diff --git a/adapters/emx_digital/emx_digitaltest/exemplary/banner-and-video-site.json b/adapters/emx_digital/emx_digitaltest/exemplary/banner-and-video-site.json new file mode 100644 index 00000000000..c2b20cf1c5d --- /dev/null +++ b/adapters/emx_digital/emx_digitaltest/exemplary/banner-and-video-site.json @@ -0,0 +1,200 @@ +{ + "mockBidRequest": { + "id": "some_test_auction", + "imp": [{ + "id": "some_test_ad_id_1", + "banner": { + "format": [{ + "w": 300, + "h": 250 + }], + "w": 300, + "h": 250 + }, + "ext": { + "bidder": { + "tagid": "25251" + } + } + }, + { + "id": "some_test_ad_id_2", + "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 + }, + "site": { + "domain": "www.publisher.com", + "page": "http://www.publisher.com/awesome/site?with=some¶meters=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" + ], + "Referer": [ + "http://www.publisher.com/awesome/site?with=some¶meters=here" + ], + "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_1", + "banner": { + "format": [{ + "w": 300, + "h": 250 + }], + "w": 300, + "h": 250 + }, + "ext": { + "bidder": { + "tagid": "25251" + } + }, + "tagid": "25251", + "secure": 0 + }, + { + "id": "some_test_ad_id_2", + "video":{ + "mimes": [ + "video/mp4", + "application/javascript" + ], + "protocols":[ + 2, + 3, + 5, + 6 + ], + "w":640, + "h":480 + }, + "ext": { + "bidder": { + "tagid": "25251" + } + }, + "tagid": "25251", + "secure": 0 + }], + "site": { + "domain": "www.publisher.com", + "page": "http://www.publisher.com/awesome/site?with=some¶meters=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": "
", + "id": "some_test_ad_id_1", + "impid": "some_test_ad_id_1", + "ttl": 300, + "crid": "94395500", + "w": 300, + "price": 2.942808, + "adid": "94395500", + "h": 250 + }] + }, + { + "seat": "45678", + "bid": [{ + "adm": "00:00:15", + "id": "some_test_ad_id_2", + "impid": "some_test_ad_id_2", + "ttl": 300, + "crid": "9999999", + "w": 1020, + "price": 1, + "adid": "9999999", + "h": 1000 + } + ] + }], + "cur": "USD" + } + } + }], + + "expectedBids": [{ + "bid": { + "adm": "
", + "id": "some_test_ad_id_1", + "impid": "some_test_ad_id_1", + "ttl": 300, + "crid": "94395500", + "w": 300, + "price": 2.942808, + "adid": "94395500", + "h": 250 + }, + "type": "banner" + }, + { + "bid": { + "adm": "00:00:15", + "id": "some_test_ad_id_2", + "impid": "some_test_ad_id_2", + "ttl": 300, + "crid": "9999999", + "w": 1020, + "price": 1, + "adid": "9999999", + "h": 1000 + }, + "type": "video" + } + ] +} + \ No newline at end of file diff --git a/adapters/emx_digital/emx_digitaltest/exemplary/banner-app.json b/adapters/emx_digital/emx_digitaltest/exemplary/banner-app.json new file mode 100644 index 00000000000..8de90f52192 --- /dev/null +++ b/adapters/emx_digital/emx_digitaltest/exemplary/banner-app.json @@ -0,0 +1,119 @@ +{ + "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" + } + } + }], + "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¶meters=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 + }, + "ext": { + "bidder": { + "tagid": "25251" + } + }, + "tagid": "25251", + "secure": 0 + }], + "app": { + "domain": "www.publisher.com", + "storeurl": "http://www.publisher.com/awesome/site?with=some¶meters=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": "