diff --git a/adapters/kobler/kobler.go b/adapters/kobler/kobler.go index fe422b0ff2..2468497377 100644 --- a/adapters/kobler/kobler.go +++ b/adapters/kobler/kobler.go @@ -37,6 +37,8 @@ func (a adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.Ex var requestData []*adapters.RequestData var errors []error + testMode := false + if !sliceutil.Contains(request.Cur, supportedCurrency) { request.Cur = append(request.Cur, supportedCurrency) } @@ -46,6 +48,29 @@ func (a adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.Ex errors = append(errors, err) return nil, errors } + + // Check the first Imp for test mode, which decides the endpoint. + if i == 0 && request.Imp[i].Ext != nil { + var bidderExt adapters.ExtImpBidder + if err := jsonutil.Unmarshal(request.Imp[i].Ext, &bidderExt); err != nil { + errors = append(errors, &errortypes.BadInput{ + Message: "Error parsing bidderExt object", + }) + continue + } + + var impExt openrtb_ext.ExtImpKobler + if err := jsonutil.Unmarshal(bidderExt.Bidder, &impExt); err != nil { + errors = append(errors, &errortypes.BadInput{ + Message: "Error parsing impExt object", + }) + continue + } + + if impExt.Test != nil { + testMode = *impExt.Test + } + } } requestJSON, err := jsonutil.Marshal(request) @@ -54,12 +79,19 @@ func (a adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.Ex return nil, errors } + // Use a separate endpoint for testing purposes in the DEV environment. + // Required due to Kobler's internal test campaign setup. + endpoint := a.endpoint + if testMode { + endpoint = a.devEndpoint + } + headers := http.Header{} headers.Add("Content-Type", "application/json;charset=utf-8") requestData = append(requestData, &adapters.RequestData{ Method: "POST", - Uri: a.getEndpoint(request), + Uri: endpoint, Body: requestJSON, ImpIDs: openrtb_ext.GetImpIDs(request.Imp), Headers: headers, @@ -99,16 +131,6 @@ func (a adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.Re return bidResponse, nil } -// Use a separate endpoint for testing purposes in the DEV environment. -// Required due to Kobler's internal test campaign setup. -func (a adapter) getEndpoint(request *openrtb2.BidRequest) string { - if request.Test == 1 { - return a.devEndpoint - } - - return a.endpoint -} - func getMediaTypeForBid(bid openrtb2.Bid) openrtb_ext.BidType { if bid.Ext != nil { var bidExt openrtb_ext.ExtBid diff --git a/adapters/kobler/koblertest/supplemental/correct-endpoint-when-testing.json b/adapters/kobler/koblertest/supplemental/correct-endpoint-when-testing.json index ea9eabdbb7..53c546d86f 100644 --- a/adapters/kobler/koblertest/supplemental/correct-endpoint-when-testing.json +++ b/adapters/kobler/koblertest/supplemental/correct-endpoint-when-testing.json @@ -1,7 +1,6 @@ { "mockBidRequest": { "id": "test-request-id", - "test": 1, "device": { "devicetype": 2 }, @@ -23,6 +22,11 @@ "h": 100 } ] + }, + "ext": { + "bidder": { + "test": true + } } } ] @@ -33,7 +37,6 @@ "uri": "https://bid-service.dev.essrtb.com/bid/prebid_server_rtb_call", "body": { "id": "test-request-id", - "test": 1, "device": { "devicetype": 2 }, @@ -55,6 +58,11 @@ "h": 100 } ] + }, + "ext": { + "bidder": { + "test": true + } } } ], diff --git a/openrtb_ext/imp_kobler.go b/openrtb_ext/imp_kobler.go new file mode 100644 index 0000000000..c02393c803 --- /dev/null +++ b/openrtb_ext/imp_kobler.go @@ -0,0 +1,5 @@ +package openrtb_ext + +type ExtImpKobler struct { + Test *bool `json:"test"` +} diff --git a/static/bidder-params/kobler.json b/static/bidder-params/kobler.json index c4b8de72df..7e85601bfe 100644 --- a/static/bidder-params/kobler.json +++ b/static/bidder-params/kobler.json @@ -4,5 +4,10 @@ "description": "A schema which validates params accepted by the Kobler adapter", "type": "object", - "properties": {} + "properties": { + "test": { + "type": "boolean", + "description": "Whether the request is for testing only. When multiple ad units are submitted together, it is enough to set this parameter on the first one." + } + } }