diff --git a/adapters/kubient/kubient.go b/adapters/kubient/kubient.go index cb1fe93ff82..acfaa44b6af 100644 --- a/adapters/kubient/kubient.go +++ b/adapters/kubient/kubient.go @@ -24,10 +24,24 @@ type KubientAdapter struct { func (adapter *KubientAdapter) MakeRequests( openRTBRequest *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo, -) ( - requestsToBidder []*adapters.RequestData, - errs []error, -) { +) ([]*adapters.RequestData, []error) { + if len(openRTBRequest.Imp) == 0 { + return nil, []error{&errortypes.BadInput{ + Message: "No impression in the bid request", + }} + } + errs := make([]error, 0, len(openRTBRequest.Imp)) + hasErrors := false + for _, impObj := range openRTBRequest.Imp { + err := checkImpExt(impObj) + if err != nil { + errs = append(errs, err) + hasErrors = true + } + } + if hasErrors { + return nil, errs + } openRTBRequestJSON, err := json.Marshal(openRTBRequest) if err != nil { errs = append(errs, err) @@ -36,17 +50,36 @@ func (adapter *KubientAdapter) MakeRequests( headers := http.Header{} headers.Add("Content-Type", "application/json;charset=utf-8") - requestToBidder := &adapters.RequestData{ + requestsToBidder := []*adapters.RequestData{{ Method: "POST", Uri: adapter.endpoint, Body: openRTBRequestJSON, Headers: headers, - } - requestsToBidder = append(requestsToBidder, requestToBidder) - + }} return requestsToBidder, errs } +func checkImpExt(impObj openrtb.Imp) error { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(impObj.Ext, &bidderExt); err != nil { + return &errortypes.BadInput{ + Message: "ext.bidder not provided", + } + } + var kubientExt openrtb_ext.ExtImpKubient + if err := json.Unmarshal(bidderExt.Bidder, &kubientExt); err != nil { + return &errortypes.BadInput{ + Message: "ext.bidder.zoneid is not provided", + } + } + if kubientExt.ZoneID == "" { + return &errortypes.BadInput{ + Message: "zoneid is empty", + } + } + return nil +} + // MakeBids makes the bids func (adapter *KubientAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { var errs []error diff --git a/adapters/kubient/kubienttest/exemplary/banner.json b/adapters/kubient/kubienttest/exemplary/banner.json index a32c761a7d0..9af4f9f8cfa 100644 --- a/adapters/kubient/kubienttest/exemplary/banner.json +++ b/adapters/kubient/kubienttest/exemplary/banner.json @@ -17,7 +17,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "9042" + } } } ] @@ -44,7 +46,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "9042" + } } } ] diff --git a/adapters/kubient/kubienttest/exemplary/video.json b/adapters/kubient/kubienttest/exemplary/video.json index 59d32874cec..d9346c3fa46 100644 --- a/adapters/kubient/kubienttest/exemplary/video.json +++ b/adapters/kubient/kubienttest/exemplary/video.json @@ -11,7 +11,9 @@ "h": 576 }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "9010" + } } } ] @@ -32,7 +34,9 @@ "h": 576 }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "9010" + } } } ] diff --git a/adapters/kubient/kubienttest/supplemental/bad_response.json b/adapters/kubient/kubienttest/supplemental/bad_response.json index 166743cf497..076acf29058 100644 --- a/adapters/kubient/kubienttest/supplemental/bad_response.json +++ b/adapters/kubient/kubienttest/supplemental/bad_response.json @@ -13,7 +13,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "23" + } } } ] @@ -36,7 +38,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "23" + } } } ] diff --git a/adapters/kubient/kubienttest/supplemental/missing-zoneid.json b/adapters/kubient/kubienttest/supplemental/missing-zoneid.json new file mode 100644 index 00000000000..cfd616621e2 --- /dev/null +++ b/adapters/kubient/kubienttest/supplemental/missing-zoneid.json @@ -0,0 +1,31 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-missing-req-param-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + } + ] + }, + "ext": { + "bidder": {} + } + } + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "zoneid is empty", + "comparison": "literal" + } + ] +} diff --git a/adapters/kubient/kubienttest/supplemental/no-imps.json b/adapters/kubient/kubienttest/supplemental/no-imps.json new file mode 100644 index 00000000000..189adf9a932 --- /dev/null +++ b/adapters/kubient/kubienttest/supplemental/no-imps.json @@ -0,0 +1,12 @@ +{ + "mockBidRequest": { + "id": "test-no-imp-request-id", + "imp": [] + }, + "expectedMakeRequestsErrors": [ + { + "value": "No impression in the bid request", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/kubient/kubienttest/supplemental/status_204.json b/adapters/kubient/kubienttest/supplemental/status_204.json index 58bb2629a5e..6794d58be6c 100644 --- a/adapters/kubient/kubienttest/supplemental/status_204.json +++ b/adapters/kubient/kubienttest/supplemental/status_204.json @@ -14,6 +14,7 @@ }, "ext": { "bidder": { + "zoneid": "203" } } } @@ -39,6 +40,7 @@ }, "ext": { "bidder": { + "zoneid": "203" } } } diff --git a/adapters/kubient/kubienttest/supplemental/status_400.json b/adapters/kubient/kubienttest/supplemental/status_400.json index e895f793dc1..29438cc3b8b 100644 --- a/adapters/kubient/kubienttest/supplemental/status_400.json +++ b/adapters/kubient/kubienttest/supplemental/status_400.json @@ -13,7 +13,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "102" + } } } ] @@ -37,7 +39,9 @@ ] }, "ext": { - "bidder": {} + "bidder": { + "zoneid": "102" + } } } ] diff --git a/openrtb_ext/imp_kubient.go b/openrtb_ext/imp_kubient.go new file mode 100644 index 00000000000..fafd2a0eb8f --- /dev/null +++ b/openrtb_ext/imp_kubient.go @@ -0,0 +1,6 @@ +package openrtb_ext + +// ExtImpKubient defines the contract for bidrequest.imp[i].ext.kubient +type ExtImpKubient struct { + ZoneID string `json:"zoneid"` +} diff --git a/static/bidder-params/kubient.json b/static/bidder-params/kubient.json index a75dd734ff2..9b975289a7b 100644 --- a/static/bidder-params/kubient.json +++ b/static/bidder-params/kubient.json @@ -3,5 +3,11 @@ "title": "Kubient Adapter Params", "description": "A schema which validates params accepted by the Kubient adapter", "type": "object", - "properties": { } + "properties": { + "zoneid": { + "type": "string", + "description": "Zone ID identifies Kubient placement ID.", + "minLength": 1 + } + } }