diff --git a/adapters/eplanning/eplanning.go b/adapters/eplanning/eplanning.go index 21c613895be..8d0f7e8b662 100644 --- a/adapters/eplanning/eplanning.go +++ b/adapters/eplanning/eplanning.go @@ -26,6 +26,9 @@ const sec = "ROS" const dfpClientID = "1" const requestTargetInventory = "1" +var priorityOrderForMobileSizesAsc = []string{"1x1", "300x50", "320x50", "300x250"} +var priorityOrderForDesktopSizesAsc = []string{"1x1", "970x90", "970x250", "160x600", "300x600", "728x90", "300x250"} + var cleanNameSteps = []cleanNameStep{ {regexp.MustCompile(`_|\.|-|\/`), ""}, {regexp.MustCompile(`\)\(|\(|\)|:`), "_"}, @@ -67,10 +70,11 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb.BidRequest, reqIn spacesStrings := make([]string, 0, totalImps) totalRequests := 0 clientID := "" + isMobile := isMobileDevice(request) for i := 0; i < totalImps; i++ { imp := request.Imp[i] - extImp, err := verifyImp(&imp) + extImp, err := verifyImp(&imp, isMobile) if err != nil { errors = append(errors, err) continue @@ -187,6 +191,10 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb.BidRequest, reqIn return requests, errors } +func isMobileDevice(request *openrtb.BidRequest) bool { + return request.Device != nil && (request.Device.DeviceType == openrtb.DeviceTypeMobileTablet || request.Device.DeviceType == openrtb.DeviceTypePhone || request.Device.DeviceType == openrtb.DeviceTypeTablet) +} + func cleanName(name string) string { for _, step := range cleanNameSteps { name = step.expression.ReplaceAllString(name, step.replacementString) @@ -194,7 +202,7 @@ func cleanName(name string) string { return name } -func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) { +func verifyImp(imp *openrtb.Imp, isMobile bool) (*openrtb_ext.ExtImpEPlanning, error) { var bidderExt adapters.ExtImpBidder if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { @@ -217,7 +225,7 @@ func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) { } } - width, height := getSizeFromImp(imp) + width, height := getSizeFromImp(imp, isMobile) if width == 0 && height == 0 { impExt.SizeString = nullSize @@ -232,17 +240,34 @@ func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) { return &impExt, nil } -func getSizeFromImp(imp *openrtb.Imp) (uint64, uint64) { +func searchSizePriority(hashedFormats map[string]int, format []openrtb.Format, priorityOrderForSizesAsc []string) (uint64, uint64) { + for i := len(priorityOrderForSizesAsc) - 1; i >= 0; i-- { + if formatIndex, wasFound := hashedFormats[priorityOrderForSizesAsc[i]]; wasFound { + return format[formatIndex].W, format[formatIndex].H + } + } + return format[0].W, format[0].H +} + +func getSizeFromImp(imp *openrtb.Imp, isMobile bool) (uint64, uint64) { if imp.Banner.W != nil && imp.Banner.H != nil { return *imp.Banner.W, *imp.Banner.H } if imp.Banner.Format != nil { - for _, format := range imp.Banner.Format { + hashedFormats := make(map[string]int, len(imp.Banner.Format)) + + for i, format := range imp.Banner.Format { if format.W != 0 && format.H != 0 { - return format.W, format.H + hashedFormats[fmt.Sprintf("%dx%d", format.W, format.H)] = i } } + + if isMobile { + return searchSizePriority(hashedFormats, imp.Banner.Format, priorityOrderForMobileSizesAsc) + } else { + return searchSizePriority(hashedFormats, imp.Banner.Format, priorityOrderForDesktopSizesAsc) + } } return 0, 0 @@ -278,12 +303,14 @@ func (adapter *EPlanningAdapter) MakeBids(internalRequest *openrtb.BidRequest, e }} } + isMobile := isMobileDevice(internalRequest) + bidResponse := adapters.NewBidderResponse() spaceNameToImpID := make(map[string]string) for _, imp := range internalRequest.Imp { - extImp, err := verifyImp(&imp) + extImp, err := verifyImp(&imp, isMobile) if err != nil { continue } diff --git a/adapters/eplanning/eplanningtest/supplemental/banner-2-sizes-in-priority-list-mobile.json b/adapters/eplanning/eplanningtest/supplemental/banner-2-sizes-in-priority-list-mobile.json new file mode 100644 index 00000000000..b1f0677cb3c --- /dev/null +++ b/adapters/eplanning/eplanningtest/supplemental/banner-2-sizes-in-priority-list-mobile.json @@ -0,0 +1,81 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "device": { + "devicetype": 4 + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 1, + "h": 1 + } + ] + }, + "ext": { + "bidder": { + "ci": "12345" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=300x250%3A300x250&ncb=1&ur=FILE", + "body": {} + }, + "mockResponse": { + "status": 200, + "body": { + "sI": { "k": "12345" }, + "sec": "ROS", + "sp": [ + { + "k": "300x250", + "a": [{ + "i": "123456789abcdef", + "pr": "0.5", + "adm": "
test
", + "crid": "abcdef123456789", + "id": "adid12345", + "w": 300, + "h": 250 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "123456789abcdef", + "impid": "test-imp-id", + "price": 0.5, + "adm": "
test
", + "adid": "adid12345", + "crid": "abcdef123456789", + "w": 300, + "h": 250 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-desktop.json b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-desktop.json new file mode 100644 index 00000000000..31197c383e2 --- /dev/null +++ b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-desktop.json @@ -0,0 +1,85 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "device": { + "devicetype": 2 + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 970, + "h": 250 + }, + { + "w": 300, + "h": 600 + }, + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "ci": "12345" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=300x250%3A300x250&ncb=1&ur=FILE", + "body": {} + }, + "mockResponse": { + "status": 200, + "body": { + "sI": { "k": "12345" }, + "sec": "ROS", + "sp": [ + { + "k": "300x250", + "a": [{ + "i": "123456789abcdef", + "pr": "0.5", + "adm": "
test
", + "crid": "abcdef123456789", + "id": "adid12345", + "w": 300, + "h": 250 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "123456789abcdef", + "impid": "test-imp-id", + "price": 0.5, + "adm": "
test
", + "adid": "adid12345", + "crid": "abcdef123456789", + "w": 300, + "h": 250 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-mobile.json b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-mobile.json new file mode 100644 index 00000000000..661955e8706 --- /dev/null +++ b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-in-priority-list-mobile.json @@ -0,0 +1,85 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "device": { + "devicetype": 4 + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 1, + "h": 1 + }, + { + "w": 300, + "h": 50 + }, + { + "w": 320, + "h": 50 + } + ] + }, + "ext": { + "bidder": { + "ci": "12345" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=320x50%3A320x50&ncb=1&ur=FILE", + "body": {} + }, + "mockResponse": { + "status": 200, + "body": { + "sI": { "k": "12345" }, + "sec": "ROS", + "sp": [ + { + "k": "320x50", + "a": [{ + "i": "123456789abcdef", + "pr": "0.5", + "adm": "
test
", + "crid": "abcdef123456789", + "id": "adid12345", + "w": 320, + "h": 50 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "123456789abcdef", + "impid": "test-imp-id", + "price": 0.5, + "adm": "
test
", + "adid": "adid12345", + "crid": "abcdef123456789", + "w": 320, + "h": 50 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-inout-priority-list-mobile.json b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-inout-priority-list-mobile.json new file mode 100644 index 00000000000..f13df90ddc2 --- /dev/null +++ b/adapters/eplanning/eplanningtest/supplemental/banner-3-sizes-inout-priority-list-mobile.json @@ -0,0 +1,85 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "device": { + "devicetype": 1 + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 970, + "h": 250 + }, + { + "w": 300, + "h": 70 + }, + { + "w": 160, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "ci": "12345" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=970x250%3A970x250&ncb=1&ur=FILE", + "body": {} + }, + "mockResponse": { + "status": 200, + "body": { + "sI": { "k": "12345" }, + "sec": "ROS", + "sp": [ + { + "k": "970x250", + "a": [{ + "i": "123456789abcdef", + "pr": "0.5", + "adm": "
test
", + "crid": "abcdef123456789", + "id": "adid12345", + "w": 970, + "h": 250 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "123456789abcdef", + "impid": "test-imp-id", + "price": 0.5, + "adm": "
test
", + "adid": "adid12345", + "crid": "abcdef123456789", + "w": 970, + "h": 250 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/eplanning/eplanningtest/supplemental/banner-4-sizes-in-priority-list-desktop.json b/adapters/eplanning/eplanningtest/supplemental/banner-4-sizes-in-priority-list-desktop.json new file mode 100644 index 00000000000..103be4e46c9 --- /dev/null +++ b/adapters/eplanning/eplanningtest/supplemental/banner-4-sizes-in-priority-list-desktop.json @@ -0,0 +1,89 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "device": { + "devicetype": 4 + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 1, + "h": 1 + }, + { + "w": 300, + "h": 50 + }, + { + "w": 320, + "h": 50 + }, + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "ci": "12345" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=300x250%3A300x250&ncb=1&ur=FILE", + "body": {} + }, + "mockResponse": { + "status": 200, + "body": { + "sI": { "k": "12345" }, + "sec": "ROS", + "sp": [ + { + "k": "300x250", + "a": [{ + "i": "123456789abcdef", + "pr": "0.5", + "adm": "
test
", + "crid": "abcdef123456789", + "id": "adid12345", + "w": 300, + "h": 250 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "123456789abcdef", + "impid": "test-imp-id", + "price": 0.5, + "adm": "
test
", + "adid": "adid12345", + "crid": "abcdef123456789", + "w": 300, + "h": 250 + }, + "type": "banner" + } + ] + } + ] +}