From d68a1132cc8ec6fc1decbdea21926704e5f3d01c Mon Sep 17 00:00:00 2001 From: pm-avinash-kapre <112699665+AvinashKapre@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:36:28 +0530 Subject: [PATCH] UOE-11477: Cherry-Pick Displayio bidder changes (#966) --- adapters/displayio/displayio.go | 188 ++++++++++++++++ adapters/displayio/displayio_test.go | 22 ++ .../displayiotest/exemplary/multi-format.json | 147 ++++++++++++ .../displayiotest/exemplary/multi-imp.json | 211 ++++++++++++++++++ .../exemplary/simple-banner.json | 117 ++++++++++ .../displayiotest/exemplary/simple-video.json | 124 ++++++++++ .../supplemental/bad-response.json | 77 +++++++ .../supplemental/currency-conversion.json | 95 ++++++++ .../displayiotest/supplemental/ext.json | 30 +++ .../supplemental/nobid-response.json | 72 ++++++ .../supplemental/response-code-invalid.json | 74 ++++++ .../supplemental/seatbid-response.json | 77 +++++++ .../supplemental/unexpected-media-type.json | 105 +++++++++ adapters/displayio/params_test.go | 48 ++++ exchange/adapter_builders.go | 2 + .../adapters/default_bidder_parameter_test.go | 4 +- openrtb_ext/bidders.go | 2 + openrtb_ext/imp_displayio.go | 7 + static/bidder-info/displayio.yaml | 16 ++ static/bidder-params/displayio.json | 25 +++ 20 files changed, 1441 insertions(+), 2 deletions(-) create mode 100644 adapters/displayio/displayio.go create mode 100644 adapters/displayio/displayio_test.go create mode 100644 adapters/displayio/displayiotest/exemplary/multi-format.json create mode 100644 adapters/displayio/displayiotest/exemplary/multi-imp.json create mode 100644 adapters/displayio/displayiotest/exemplary/simple-banner.json create mode 100644 adapters/displayio/displayiotest/exemplary/simple-video.json create mode 100644 adapters/displayio/displayiotest/supplemental/bad-response.json create mode 100644 adapters/displayio/displayiotest/supplemental/currency-conversion.json create mode 100644 adapters/displayio/displayiotest/supplemental/ext.json create mode 100644 adapters/displayio/displayiotest/supplemental/nobid-response.json create mode 100644 adapters/displayio/displayiotest/supplemental/response-code-invalid.json create mode 100644 adapters/displayio/displayiotest/supplemental/seatbid-response.json create mode 100644 adapters/displayio/displayiotest/supplemental/unexpected-media-type.json create mode 100644 adapters/displayio/params_test.go create mode 100644 openrtb_ext/imp_displayio.go create mode 100644 static/bidder-info/displayio.yaml create mode 100644 static/bidder-params/displayio.json diff --git a/adapters/displayio/displayio.go b/adapters/displayio/displayio.go new file mode 100644 index 00000000000..b54998553b3 --- /dev/null +++ b/adapters/displayio/displayio.go @@ -0,0 +1,188 @@ +package displayio + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" + "text/template" + + "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v2/adapters" + "github.com/prebid/prebid-server/v2/config" + "github.com/prebid/prebid-server/v2/errortypes" + "github.com/prebid/prebid-server/v2/macros" + "github.com/prebid/prebid-server/v2/openrtb_ext" +) + +type adapter struct { + endpoint *template.Template +} + +type reqDioExt struct { + UserSession string `json:"userSession,omitempty"` + PlacementId string `json:"placementId"` + InventoryId string `json:"inventoryId"` +} + +func (adapter *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Add("x-openrtb-version", "2.5") + + result := make([]*adapters.RequestData, 0, len(request.Imp)) + errs := make([]error, 0, len(request.Imp)) + + for _, impression := range request.Imp { + var requestExt map[string]interface{} + + if impression.BidFloorCur == "" || impression.BidFloor == 0 { + impression.BidFloorCur = "USD" + } else if impression.BidFloorCur != "USD" { + convertedValue, err := requestInfo.ConvertCurrency(impression.BidFloor, impression.BidFloorCur, "USD") + + if err != nil { + errs = append(errs, err) + continue + } + + impression.BidFloor = convertedValue + impression.BidFloorCur = "USD" + } + + if len(impression.Ext) == 0 { + errs = append(errs, errors.New("impression extensions required")) + continue + } + + var bidderExt adapters.ExtImpBidder + err := json.Unmarshal(impression.Ext, &bidderExt) + + if err != nil { + errs = append(errs, err) + continue + } + + var impressionExt openrtb_ext.ExtImpDisplayio + err = json.Unmarshal(bidderExt.Bidder, &impressionExt) + if err != nil { + errs = append(errs, err) + continue + } + + dioExt := reqDioExt{PlacementId: impressionExt.PlacementId, InventoryId: impressionExt.InventoryId} + + requestCopy := *request + + err = json.Unmarshal(requestCopy.Ext, &requestExt) + if err != nil { + requestExt = make(map[string]interface{}) + } + + requestExt["displayio"] = dioExt + + requestCopy.Ext, err = json.Marshal(requestExt) + if err != nil { + errs = append(errs, err) + continue + } + + requestCopy.Imp = []openrtb2.Imp{impression} + body, err := json.Marshal(requestCopy) + if err != nil { + errs = append(errs, err) + continue + } + + url, err := adapter.buildEndpointURL(&impressionExt) + if err != nil { + return nil, []error{err} + } + + result = append(result, &adapters.RequestData{ + Method: "POST", + Uri: url, + Body: body, + Headers: headers, + ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp), + }) + } + + if len(result) == 0 { + return nil, errs + } + return result, errs +} + +// MakeBids translates Displayio bid response to prebid-server specific format +func (adapter *adapter) MakeBids(internalRequest *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { + + if adapters.IsResponseStatusCodeNoContent(responseData) { + return nil, nil + } + + if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { + return nil, []error{err} + } + + var bidResp openrtb2.BidResponse + + if err := json.Unmarshal(responseData.Body, &bidResp); err != nil { + msg := fmt.Sprintf("Bad server response: %d", err) + return nil, []error{&errortypes.BadServerResponse{Message: msg}} + } + + if len(bidResp.SeatBid) != 1 { + msg := fmt.Sprintf("Invalid SeatBids count: %d", len(bidResp.SeatBid)) + return nil, []error{&errortypes.BadServerResponse{Message: msg}} + } + + var errs []error + bidResponse := adapters.NewBidderResponse() + + for _, sb := range bidResp.SeatBid { + for i := range sb.Bid { + bidType, err := getBidMediaTypeFromMtype(&sb.Bid[i]) + if err != nil { + errs = append(errs, err) + } else { + b := &adapters.TypedBid{ + Bid: &sb.Bid[i], + BidType: bidType, + } + bidResponse.Bids = append(bidResponse.Bids, b) + } + } + } + + return bidResponse, errs +} + +func Builder(_ openrtb_ext.BidderName, config config.Adapter, _ config.Server) (adapters.Bidder, error) { + endpoint, err := template.New("endpointTemplate").Parse(config.Endpoint) + if err != nil { + return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) + } + + bidder := &adapter{ + endpoint: endpoint, + } + return bidder, nil +} + +func getBidMediaTypeFromMtype(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { + switch bid.MType { + case openrtb2.MarkupBanner: + return openrtb_ext.BidTypeBanner, nil + case openrtb2.MarkupVideo: + return openrtb_ext.BidTypeVideo, nil + default: + return "", fmt.Errorf("unexpected media type for bid: %s", bid.ImpID) + } +} + +func (adapter *adapter) buildEndpointURL(params *openrtb_ext.ExtImpDisplayio) (string, error) { + endpointParams := macros.EndpointTemplateParams{PublisherID: params.PublisherId} + return macros.ResolveMacros(adapter.endpoint, endpointParams) +} diff --git a/adapters/displayio/displayio_test.go b/adapters/displayio/displayio_test.go new file mode 100644 index 00000000000..9f41a59e2a0 --- /dev/null +++ b/adapters/displayio/displayio_test.go @@ -0,0 +1,22 @@ +package displayio + +import ( + "testing" + + "github.com/prebid/prebid-server/v2/adapters/adapterstest" + "github.com/prebid/prebid-server/v2/config" + "github.com/prebid/prebid-server/v2/openrtb_ext" +) + +func TestJsonSamples(t *testing.T) { + bidder, buildErr := Builder(openrtb_ext.BidderDisplayio, + config.Adapter{Endpoint: "https://adapter.endpoint/?macro={{.PublisherID}}"}, + config.Server{ExternalUrl: "https://server.endpoint/"}, + ) + + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } + + adapterstest.RunJSONBidderTest(t, "displayiotest", bidder) +} diff --git a/adapters/displayio/displayiotest/exemplary/multi-format.json b/adapters/displayio/displayiotest/exemplary/multi-format.json new file mode 100644 index 00000000000..c0e149a8c46 --- /dev/null +++ b/adapters/displayio/displayiotest/exemplary/multi-format.json @@ -0,0 +1,147 @@ +{ + "mockBidRequest": { + "id": "requestId10111011101110111011", + "app": { + "id": "1011" + }, + "imp": [ + { + "id": "impId10111011101110111011", + "tagid": "1011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + }, + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 5 + ], + "w": 640, + "h": 480 + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "requestId10111011101110111011", + "app": { + "id": "1011" + }, + "imp": [ + { + "id": "impId10111011101110111011", + "tagid": "1011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + }, + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 5 + ], + "w": 640, + "h": 480 + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ], + "ext": { + "displayio": { + "placementId": "1011", + "inventoryId": "1011" + } + } + }, + "impIDs": [ + "impId10111011101110111011" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "bidid": "5778926625248726496", + "seatbid": [ + { + "seat": "seat1", + "bid": [ + { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 0.01, + "adm": "", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 1 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 0.01, + "adm": "", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/exemplary/multi-imp.json b/adapters/displayio/displayiotest/exemplary/multi-imp.json new file mode 100644 index 00000000000..8588ea5bf01 --- /dev/null +++ b/adapters/displayio/displayiotest/exemplary/multi-imp.json @@ -0,0 +1,211 @@ +{ + "mockBidRequest": { + "id": "test-request-multi-id", + "imp": [ + { + "id": "test-imp-id-1", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "placementId": "1010", + "publisherId": "2020", + "inventoryId": "3030" + } + }, + "bidfloor": 0.5 + }, + { + "id": "test-imp-id-2", + "banner": { + "format": [ + { + "w": 300, + "h": 150 + } + ] + }, + "ext": { + "bidder": { + "placementId": "4040", + "publisherId": "5050", + "inventoryId": "6060" + } + }, + "bidfloor": 0.5 + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=2020", + "body": { + "id": "test-request-multi-id", + "imp": [ + { + "id": "test-imp-id-1", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "placementId": "1010", + "publisherId": "2020", + "inventoryId": "3030" + } + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ], + "ext": { + "displayio": { + "placementId": "1010", + "inventoryId": "3030" + } + } + }, + "impIDs": [ + "test-imp-id-1" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-multi-id", + "seatbid": [ + { + "seat": "seat1", + "bid": [ + { + "id": "testid1", + "impid": "test-imp-id-1", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "crid_10", + "mtype": 1, + "h": 90, + "w": 728 + } + ] + } + ], + "cur": "USD" + } + } + }, + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=5050", + "body": { + "id": "test-request-multi-id", + "imp": [ + { + "id": "test-imp-id-2", + "banner": { + "format": [ + { + "w": 300, + "h": 150 + } + ] + }, + "ext": { + "bidder": { + "placementId": "4040", + "publisherId": "5050", + "inventoryId": "6060" + } + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ], + "ext": { + "displayio": { + "placementId": "4040", + "inventoryId": "6060" + } + } + }, + "impIDs": [ + "test-imp-id-2" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-multi-id", + "seatbid": [ + { + "seat": "seat2", + "bid": [ + { + "id": "testid2", + "impid": "test-imp-id-2", + "price": 0.800000, + "adm": "some-test-ad", + "crid": "crid_11", + "mtype": 1, + "h": 150, + "w": 300 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "testid1", + "impid": "test-imp-id-1", + "price": 0.5, + "adm": "some-test-ad", + "crid": "crid_10", + "mtype": 1, + "w": 728, + "h": 90 + }, + "type": "banner" + } + ] + }, + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "testid2", + "impid": "test-imp-id-2", + "price": 0.8, + "adm": "some-test-ad", + "crid": "crid_11", + "mtype": 1, + "w": 300, + "h": 150 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/displayio/displayiotest/exemplary/simple-banner.json b/adapters/displayio/displayiotest/exemplary/simple-banner.json new file mode 100644 index 00000000000..15a5f913210 --- /dev/null +++ b/adapters/displayio/displayiotest/exemplary/simple-banner.json @@ -0,0 +1,117 @@ +{ + "mockBidRequest": { + "app": { + "id": "1011" + }, + "id": "requestId10111011101110111011", + "imp": [ + { + "banner": { + "h": 250, + "w": 300 + }, + "bidfloor": 0.225, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "requestId10111011101110111011", + "app": { + "id": "1011" + }, + "imp": [ + { + "banner": { + "h": 250, + "w": 300 + }, + "bidfloor": 0.225, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1011", + "inventoryId": "1011" + } + } + }, + "impIDs": [ + "impId10111011101110111011" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "958", + "bid": [ + { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 0.01, + "adm": "", + "adid": "12235", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 1 + } + ] + } + ], + "bidid": "5778926625248726496", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 0.01, + "adm": "", + "adid": "12235", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/exemplary/simple-video.json b/adapters/displayio/displayiotest/exemplary/simple-video.json new file mode 100644 index 00000000000..b5d027f33ba --- /dev/null +++ b/adapters/displayio/displayiotest/exemplary/simple-video.json @@ -0,0 +1,124 @@ +{ + "mockBidRequest": { + "app": { + "id": "1011" + }, + "id": "requestId10111011101110111011", + "imp": [ + { + "video": { + "mimes": [ + "video/mp4" + ], + "w": 300, + "h": 250 + }, + "bidfloor": 0.5, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "app": { + "id": "1011" + }, + "id": "requestId10111011101110111011", + "imp": [ + { + "video": { + "mimes": [ + "video/mp4" + ], + "w": 300, + "h": 250 + }, + "bidfloor": 0.5, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1011", + "inventoryId": "1011" + } + } + }, + "impIDs": [ + "impId10111011101110111011" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "requestId10111011101110111011", + "seatbid": [ + { + "bid": [ + { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 2, + "adm": "", + "adid": "12235", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 2 + } + ], + "seat": "displayio123", + "group": 1 + } + ], + "bidid": "test123", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 2, + "adm": "", + "adid": "12235", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 2 + }, + "type": "video" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/bad-response.json b/adapters/displayio/displayiotest/supplemental/bad-response.json new file mode 100644 index 00000000000..98cc44e8626 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/bad-response.json @@ -0,0 +1,77 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "bidfloor": 0.01, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "testid", + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "id": "testimpid", + "bidfloor": 0.01, + "bidfloorcur": "USD", + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1101", + "inventoryId": "1101" + } + } + }, + "impIDs": [ + "testimpid" + ] + }, + "mockResponse": { + "status": 200, + "body": "" + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Bad server response: .*", + "comparison": "regex" + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/currency-conversion.json b/adapters/displayio/displayiotest/supplemental/currency-conversion.json new file mode 100644 index 00000000000..32b6b2a16b4 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/currency-conversion.json @@ -0,0 +1,95 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + }, + "bidfloor": 100, + "bidfloorcur": "RUB" + } + ], + "ext": { + "prebid": { + "currency": { + "rates": { + "RUB": { + "USD": 0.01 + } + }, + "usepbsrates": false + } + } + } + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "testid", + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "id": "testimpid", + "bidfloorcur": "USD", + "bidfloor": 1, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1101", + "inventoryId": "1101" + }, + "prebid": { + "currency": { + "rates": { + "RUB": { + "USD": 0.01 + } + }, + "usepbsrates": false + } + } + } + }, + "impIDs": [ + "testimpid" + ] + }, + "mockResponse": { + "status": 204 + } + } + ], + "expectedMakeRequestsErrors": [], + "expectedBidResponses": [] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/ext.json b/adapters/displayio/displayiotest/supplemental/ext.json new file mode 100644 index 00000000000..ad0835d1c61 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/ext.json @@ -0,0 +1,30 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 320, + "h": 50 + } + ] + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "impression extensions required", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/nobid-response.json b/adapters/displayio/displayiotest/supplemental/nobid-response.json new file mode 100644 index 00000000000..ccfb2c12ca8 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/nobid-response.json @@ -0,0 +1,72 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + }, + "bidfloor": 0.5, + "bidfloorcur": "USD" + } + ], + "ext": { + "displayio": { + "placementId": "1101", + "inventoryId": "1101" + } + } + }, + "impIDs": [ + "testimpid" + ] + }, + "mockResponse": { + "status": 204 + } + } + ], + "expectedBidResponses": [] +} diff --git a/adapters/displayio/displayiotest/supplemental/response-code-invalid.json b/adapters/displayio/displayiotest/supplemental/response-code-invalid.json new file mode 100644 index 00000000000..4bfa579c672 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/response-code-invalid.json @@ -0,0 +1,74 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "bidfloor": 0.01, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "testid", + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "bidfloor": 0.01, + "bidfloorcur": "USD", + "id": "testimpid", + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1101", + "inventoryId": "1101" + } + } + }, + "impIDs":["testimpid"] + }, + "mockResponse": { + "status": 400 + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: [0-9]{3,3}. Run with request.debug = 1 for more info", + "comparison": "regex" + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/seatbid-response.json b/adapters/displayio/displayiotest/supplemental/seatbid-response.json new file mode 100644 index 00000000000..f0467d1f0bb --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/seatbid-response.json @@ -0,0 +1,77 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "bidfloor": 0.01, + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "testid", + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "id": "testimpid", + "bidfloor": 0.01, + "bidfloorcur": "USD", + "ext": { + "bidder": { + "placementId": "1101", + "inventoryId": "1101", + "publisherId": "101" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1101", + "inventoryId": "1101" + } + } + }, + "impIDs":["testimpid"] + }, + "mockResponse": { + "status": 200, + "body": { + "seatbid": [] + } + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Invalid SeatBids count: 0", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/displayiotest/supplemental/unexpected-media-type.json b/adapters/displayio/displayiotest/supplemental/unexpected-media-type.json new file mode 100644 index 00000000000..be66747a4c4 --- /dev/null +++ b/adapters/displayio/displayiotest/supplemental/unexpected-media-type.json @@ -0,0 +1,105 @@ +{ + "mockBidRequest": { + "app": { + "id": "1011" + }, + "id": "requestId10111011101110111011", + "imp": [ + { + "banner": { + "h": 250, + "w": 300 + }, + "bidfloor": 0.225, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adapter.endpoint/?macro=101", + "body": { + "id": "requestId10111011101110111011", + "app": { + "id": "1011" + }, + "imp": [ + { + "banner": { + "h": 250, + "w": 300 + }, + "bidfloor": 0.225, + "bidfloorcur": "USD", + "id": "impId10111011101110111011", + "ext": { + "bidder": { + "placementId": "1011", + "publisherId": "101", + "inventoryId": "1011" + } + } + } + ], + "ext": { + "displayio": { + "placementId": "1011", + "inventoryId": "1011" + } + } + }, + "impIDs": [ + "impId10111011101110111011" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "958", + "bid": [ + { + "id": "12345", + "impid": "impId10111011101110111011", + "price": 0.01, + "adm": "", + "adomain": [ + "domain.test" + ], + "w": 300, + "h": 250, + "mtype": 5 + } + ] + } + ], + "bidid": "5778926625248726496", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [] + } + ], + "expectedMakeBidsErrors": [ + { + "value": "unexpected media type for bid: .*", + "comparison": "regex" + } + ] +} \ No newline at end of file diff --git a/adapters/displayio/params_test.go b/adapters/displayio/params_test.go new file mode 100644 index 00000000000..f3e1de922a2 --- /dev/null +++ b/adapters/displayio/params_test.go @@ -0,0 +1,48 @@ +package displayio + +import ( + "encoding/json" + "testing" + + "github.com/prebid/prebid-server/v2/openrtb_ext" +) + +func TestValidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, validParam := range validParams { + if err := validator.Validate(openrtb_ext.BidderDisplayio, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected dmx params: %s", validParam) + } + } + for _, invalidParam := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderDisplayio, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema was not supposed to be valid: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"placementId": "anyPlacementId", "publisherId":"anyPublisherId", "inventoryId":"anyInventoryId"}`, +} + +var invalidParams = []string{ + `null`, + `nil`, + ``, + `[]`, + `true`, + `{}`, + `{"placementId": 1, "publisherId":"anyPublisherId", "inventoryId":"anyInventoryId"}`, + `{"placementId": "anyPlacementId", "publisherId":1, "inventoryId":"anyInventoryId"}`, + `{"placementId": "anyPlacementId", "publisherId":"anyPublisherId", "inventoryId":1}`, + `{"publisherId":"anyPublisherId", "inventoryId":"anyInventoryId"}`, + `{"placementId": "anyPlacementId", "inventoryId":"anyInventoryId"}`, + `{"placementId": "anyPlacementId", "publisherId":"anyPublisherId"}`, + `{"placementId": "anyPlacementId"}`, + `{"inventoryId":"anyInventoryId"}`, + `{"publisherId":"anyPublisherId"}`, +} diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index 46191fc3f09..cc1ece2a43b 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -1,6 +1,7 @@ package exchange import ( + "github.com/PubMatic-OpenWrap/prebid-server/v2/adapters/displayio" "github.com/prebid/prebid-server/v2/adapters" ttx "github.com/prebid/prebid-server/v2/adapters/33across" "github.com/prebid/prebid-server/v2/adapters/aax" @@ -290,6 +291,7 @@ func newAdapterBuilders() map[openrtb_ext.BidderName]adapters.Builder { openrtb_ext.BidderDeepintent: deepintent.Builder, openrtb_ext.BidderDefinemedia: definemedia.Builder, openrtb_ext.BidderDianomi: dianomi.Builder, + openrtb_ext.BidderDisplayio: displayio.Builder, openrtb_ext.BidderEdge226: edge226.Builder, openrtb_ext.BidderDmx: dmx.Builder, openrtb_ext.BidderDXKulture: dxkulture.Builder, diff --git a/modules/pubmatic/openwrap/adapters/default_bidder_parameter_test.go b/modules/pubmatic/openwrap/adapters/default_bidder_parameter_test.go index 0b12962c5ba..ac7d1a78d34 100644 --- a/modules/pubmatic/openwrap/adapters/default_bidder_parameter_test.go +++ b/modules/pubmatic/openwrap/adapters/default_bidder_parameter_test.go @@ -111,7 +111,7 @@ func TestGetType(t *testing.T) { func TestParseBidderParams(t *testing.T) { parseBidderParams("../../static/bidder-params") - assert.Equal(t, 167, len(adapterParams), "Length of expected entries should match") + assert.Equal(t, 168, len(adapterParams), "Length of expected entries should match") // calculate this number using X-Y // where X is calculated using command - `ls -l | wc -l` (substract 1 from result) // Y is calculated using command `grep -EinR 'oneof|not|anyof|dependenc' static/bidder-params | grep -v "description" | grep -oE './.*.json' | uniq | wc -l` @@ -119,7 +119,7 @@ func TestParseBidderParams(t *testing.T) { func TestParseBidderSchemaDefinitions(t *testing.T) { schemaDefinitions, _ := parseBidderSchemaDefinitions("../../../../static/bidder-params") - assert.Equal(t, 208, len(schemaDefinitions), "Length of expected entries should match") + assert.Equal(t, 209, len(schemaDefinitions), "Length of expected entries should match") // calculate this number using command - `ls -l | wc -l` (substract 1 from result) } diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index b9d9d051fb1..2b58eb37acd 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -93,6 +93,7 @@ var coreBidderNames []BidderName = []BidderName{ BidderDeepintent, BidderDefinemedia, BidderDianomi, + BidderDisplayio, BidderEdge226, BidderDmx, BidderDXKulture, @@ -385,6 +386,7 @@ const ( BidderDeepintent BidderName = "deepintent" BidderDefinemedia BidderName = "definemedia" BidderDianomi BidderName = "dianomi" + BidderDisplayio BidderName = "displayio" BidderEdge226 BidderName = "edge226" BidderDmx BidderName = "dmx" BidderDXKulture BidderName = "dxkulture" diff --git a/openrtb_ext/imp_displayio.go b/openrtb_ext/imp_displayio.go new file mode 100644 index 00000000000..bb8c2020276 --- /dev/null +++ b/openrtb_ext/imp_displayio.go @@ -0,0 +1,7 @@ +package openrtb_ext + +type ExtImpDisplayio struct { + PublisherId string `json:"publisherId"` + InventoryId string `json:"inventoryId"` + PlacementId string `json:"placementId"` +} diff --git a/static/bidder-info/displayio.yaml b/static/bidder-info/displayio.yaml new file mode 100644 index 00000000000..4b3b28b745a --- /dev/null +++ b/static/bidder-info/displayio.yaml @@ -0,0 +1,16 @@ +endpoint: "https://prebid.display.io/?publisher={{.PublisherID}}" +endpointCompression: gzip +geoscope: + - global +maintainer: + email: contact@display.io +modifyingVastXmlAllowed: true +capabilities: + app: + mediaTypes: + - banner + - video + site: + mediaTypes: + - banner + - video \ No newline at end of file diff --git a/static/bidder-params/displayio.json b/static/bidder-params/displayio.json new file mode 100644 index 00000000000..1a3fe3875d4 --- /dev/null +++ b/static/bidder-params/displayio.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Display.io Adapter Params", + "description": "A schema which validates params accepted by the Display.io adapter", + "type": "object", + "properties": { + "publisherId": { + "type": "string", + "description": "Publisher Id" + }, + "inventoryId": { + "type": "string", + "description": "Inventory Id" + }, + "placementId": { + "type": "string", + "description": "Placement Id" + } + }, + "required": [ + "publisherId", + "inventoryId", + "placementId" + ] +} \ No newline at end of file