From 229c0ae8c58e60695995d987ef87aceca640aec7 Mon Sep 17 00:00:00 2001 From: Marsel Taipov Date: Tue, 23 Jun 2020 16:40:15 +0300 Subject: [PATCH 1/2] Add ext.bidder.zoneid for Kubient adapater --- adapters/kubient/kubient.go | 18 +++++++++++ .../kubient/kubienttest/exemplary/banner.json | 8 +++-- .../kubient/kubienttest/exemplary/video.json | 8 +++-- .../supplemental/bad_response.json | 8 +++-- .../supplemental/missing-zoneid.json | 31 +++++++++++++++++++ .../kubienttest/supplemental/status_204.json | 2 ++ .../kubienttest/supplemental/status_400.json | 8 +++-- openrtb_ext/imp_kubient.go | 6 ++++ static/bidder-params/kubient.json | 9 +++++- 9 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 adapters/kubient/kubienttest/supplemental/missing-zoneid.json create mode 100644 openrtb_ext/imp_kubient.go diff --git a/adapters/kubient/kubient.go b/adapters/kubient/kubient.go index cb1fe93ff82..2978c314fc2 100644 --- a/adapters/kubient/kubient.go +++ b/adapters/kubient/kubient.go @@ -28,6 +28,24 @@ func (adapter *KubientAdapter) MakeRequests( requestsToBidder []*adapters.RequestData, errs []error, ) { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(openRTBRequest.Imp[0].Ext, &bidderExt); err != nil { + return nil, []error{&errortypes.BadInput{ + Message: "ext.bidder not provided", + }} + } + var kubientExt openrtb_ext.ExtImpKubient + if err := json.Unmarshal(bidderExt.Bidder, &kubientExt); err != nil { + return nil, []error{&errortypes.BadInput{ + Message: "ext.bidder.zoneid is not provided", + }} + } + if kubientExt.ZoneID == "" { + return nil, []error{&errortypes.BadInput{ + Message: "zoneid is empty", + }} + } + openRTBRequestJSON, err := json.Marshal(openRTBRequest) if err != nil { errs = append(errs, err) 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/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..8ff4a152f21 100644 --- a/static/bidder-params/kubient.json +++ b/static/bidder-params/kubient.json @@ -3,5 +3,12 @@ "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 + } + }, + "required": ["zoneid"] } From 4ca4a7192252b8864048c5965a141a4249b85d2f Mon Sep 17 00:00:00 2001 From: Marsel Taipov Date: Tue, 23 Jun 2020 19:30:12 +0300 Subject: [PATCH 2/2] Check the number of Imps. zoneid is optional. --- adapters/kubient/kubient.go | 57 ++++++++++++------- .../kubienttest/supplemental/no-imps.json | 12 ++++ static/bidder-params/kubient.json | 3 +- 3 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 adapters/kubient/kubienttest/supplemental/no-imps.json diff --git a/adapters/kubient/kubient.go b/adapters/kubient/kubient.go index 2978c314fc2..acfaa44b6af 100644 --- a/adapters/kubient/kubient.go +++ b/adapters/kubient/kubient.go @@ -24,28 +24,24 @@ type KubientAdapter struct { func (adapter *KubientAdapter) MakeRequests( openRTBRequest *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo, -) ( - requestsToBidder []*adapters.RequestData, - errs []error, -) { - var bidderExt adapters.ExtImpBidder - if err := json.Unmarshal(openRTBRequest.Imp[0].Ext, &bidderExt); err != nil { +) ([]*adapters.RequestData, []error) { + if len(openRTBRequest.Imp) == 0 { return nil, []error{&errortypes.BadInput{ - Message: "ext.bidder not provided", + Message: "No impression in the bid request", }} } - var kubientExt openrtb_ext.ExtImpKubient - if err := json.Unmarshal(bidderExt.Bidder, &kubientExt); err != nil { - return nil, []error{&errortypes.BadInput{ - Message: "ext.bidder.zoneid is not provided", - }} + 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 kubientExt.ZoneID == "" { - return nil, []error{&errortypes.BadInput{ - Message: "zoneid is empty", - }} + if hasErrors { + return nil, errs } - openRTBRequestJSON, err := json.Marshal(openRTBRequest) if err != nil { errs = append(errs, err) @@ -54,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/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/static/bidder-params/kubient.json b/static/bidder-params/kubient.json index 8ff4a152f21..9b975289a7b 100644 --- a/static/bidder-params/kubient.json +++ b/static/bidder-params/kubient.json @@ -9,6 +9,5 @@ "description": "Zone ID identifies Kubient placement ID.", "minLength": 1 } - }, - "required": ["zoneid"] + } }