Skip to content

Commit

Permalink
Add ext.bidder.zoneid for Kubient adapater (#1367)
Browse files Browse the repository at this point in the history
* Add ext.bidder.zoneid for Kubient adapater

* Check the number of Imps. zoneid is optional.
  • Loading branch information
Marsel authored Jun 25, 2020
1 parent e376a8b commit 1667636
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 17 deletions.
49 changes: 41 additions & 8 deletions adapters/kubient/kubient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions adapters/kubient/kubienttest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "9042"
}
}
}
]
Expand All @@ -44,7 +46,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "9042"
}
}
}
]
Expand Down
8 changes: 6 additions & 2 deletions adapters/kubient/kubienttest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"h": 576
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "9010"
}
}
}
]
Expand All @@ -32,7 +34,9 @@
"h": 576
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "9010"
}
}
}
]
Expand Down
8 changes: 6 additions & 2 deletions adapters/kubient/kubienttest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "23"
}
}
}
]
Expand All @@ -36,7 +38,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "23"
}
}
}
]
Expand Down
31 changes: 31 additions & 0 deletions adapters/kubient/kubienttest/supplemental/missing-zoneid.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
12 changes: 12 additions & 0 deletions adapters/kubient/kubienttest/supplemental/no-imps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mockBidRequest": {
"id": "test-no-imp-request-id",
"imp": []
},
"expectedMakeRequestsErrors": [
{
"value": "No impression in the bid request",
"comparison": "literal"
}
]
}
2 changes: 2 additions & 0 deletions adapters/kubient/kubienttest/supplemental/status_204.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"zoneid": "203"
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"zoneid": "203"
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions adapters/kubient/kubienttest/supplemental/status_400.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "102"
}
}
}
]
Expand All @@ -37,7 +39,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"zoneid": "102"
}
}
}
]
Expand Down
6 changes: 6 additions & 0 deletions openrtb_ext/imp_kubient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package openrtb_ext

// ExtImpKubient defines the contract for bidrequest.imp[i].ext.kubient
type ExtImpKubient struct {
ZoneID string `json:"zoneid"`
}
8 changes: 7 additions & 1 deletion static/bidder-params/kubient.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 1667636

Please sign in to comment.