Skip to content

Commit

Permalink
now uses params from imp for deciding endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyHPettersen committed Dec 12, 2024
1 parent e6b4eeb commit aba06b9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
44 changes: 33 additions & 11 deletions adapters/kobler/kobler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"mockBidRequest": {
"id": "test-request-id",
"test": 1,
"device": {
"devicetype": 2
},
Expand All @@ -23,6 +22,11 @@
"h": 100
}
]
},
"ext": {
"bidder": {
"test": true
}
}
}
]
Expand All @@ -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
},
Expand All @@ -55,6 +58,11 @@
"h": 100
}
]
},
"ext": {
"bidder": {
"test": true
}
}
}
],
Expand Down
5 changes: 5 additions & 0 deletions openrtb_ext/imp_kobler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openrtb_ext

type ExtImpKobler struct {
Test *bool `json:"test"`
}
7 changes: 6 additions & 1 deletion static/bidder-params/kobler.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}

0 comments on commit aba06b9

Please sign in to comment.