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
81 changes: 74 additions & 7 deletions adapters/emx_digital/emx_digital.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/mxmCherry/openrtb"
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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
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 +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)
}

Expand Down Expand Up @@ -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),
})
}
}
Expand All @@ -238,6 +287,24 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern

}

func getBidType(bidAdm string) openrtb_ext.BidType {
if bidAdm != "" && ContainsAny(bidAdm, []string{"<?xml", "<vast"}) {
return openrtb_ext.BidTypeVideo
}
return openrtb_ext.BidTypeBanner
}

func ContainsAny(raw string, keys []string) bool {
lowerCased := strings.ToLower(raw)
for i := 0; i < len(keys); i++ {
if strings.Contains(lowerCased, keys[i]) {
return true
}
}
return false

}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

func NewEmxDigitalBidder(endpoint string) *EmxDigitalAdapter {
return &EmxDigitalAdapter{
endpoint: endpoint,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions adapters/emx_digital/emx_digitaltest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
@@ -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&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
},
"ext": {
"bidder": {
"tagid": "25251"
}
},
"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": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
"id": "some_test_ad_id",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
"w": 300,
"price": 2.942808,
"adid": "94395500",
"h": 250
}]
}],
"cur": "USD"
}
}
}],

"expectedBids": [{
"bid": {
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
"id": "some_test_ad_id",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
"w": 300,
"price": 2.942808,
"adid": "94395500",
"h": 250
},
"type": "banner"
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"tagid": "25251"
}
},
"tagid": "25251",
"secure": 0
}],
Expand All @@ -85,7 +90,7 @@
"seat": "12356",
"bid": [{
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
"id": "uuid",
"id": "some_test_ad_id",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
Expand All @@ -103,7 +108,7 @@
"expectedBids": [{
"bid": {
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
"id": "uuid",
"id": "some_test_ad_id",
"impid": "some_test_ad_id",
"ttl": 300,
"crid": "94395500",
Expand All @@ -114,4 +119,4 @@
},
"type": "banner"
}]
}
}
Loading