Skip to content

Commit

Permalink
Merge pull request #5 from bruno-siira/pr-review-comments-12-16-24
Browse files Browse the repository at this point in the history
Pr review comments 12 16 24
  • Loading branch information
dirk-rd authored Jan 10, 2025
2 parents 0623316 + a96efc8 commit 8ed4059
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
62 changes: 38 additions & 24 deletions adapters/resetdigital/resetdigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,51 +207,65 @@ func processDataFromRequest(requestData *openrtb2.BidRequest, imp openrtb2.Imp,
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
// Return early if the response contains no content
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

// Check for errors in the response status code
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}

// Parse the response body into a single bid response
var response resetDigitalBidResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
// Ensure there is exactly one bid in the response
if len(response.Bids) != 1 {
return nil, []error{fmt.Errorf("expected exactly one bid in the response, but got %d", len(response.Bids))}
}

// Extract the single bid
resetDigitalBid := &response.Bids[0]

var errs []error
requestImps := make(map[string]openrtb2.Imp)
for _, imp := range request.Imp {
requestImps[imp.ID] = imp
// Map the incoming impression to its ID for media type determination
requestImp, found := findRequestImpByID(request.Imp, resetDigitalBid.ImpID)
if !found {
return nil, []error{fmt.Errorf("no matching impression found for ImpID %s", resetDigitalBid.ImpID)}
}

for i := range response.Bids {
resetDigitalBid := &response.Bids[i]
// Convert the bid into an OpenRTB bid
bid, err := getBidFromResponse(resetDigitalBid)
if err != nil {
return nil, []error{err}
}

bid, err := getBidFromResponse(resetDigitalBid)
if bid == nil {
errs = append(errs, err)
continue
}
// Determine the bid type based on the impression
bidType := GetMediaTypeForImp(requestImp)

bidType := GetMediaTypeForImp(requestImps[bid.ImpID])
// Construct the bidder response
bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)
bidResponse.Currency = "USD" // Default currency
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: bid,
BidType: bidType,
Seat: openrtb_ext.BidderName(resetDigitalBid.Seat),
})

b := &adapters.TypedBid{
Bid: bid,
BidType: bidType,
Seat: openrtb_ext.BidderName(resetDigitalBid.Seat),
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
return bidResponse, nil
}

if len(request.Cur) == 0 {
bidResponse.Currency = "USD"
// findRequestImpByID searches for an impression by its ID in the list of impressions
func findRequestImpByID(imps []openrtb2.Imp, impID string) (openrtb2.Imp, bool) {
for _, imp := range imps {
if imp.ID == impID {
return imp, true
}
}

return bidResponse, errs
return openrtb2.Imp{}, false
}

func getBidFromResponse(bidResponse *resetDigitalBid) (*openrtb2.Bid, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@
"comparison": "literal"
}
],
"expectedBidResponses": [{}]
"expectedBidResponses": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@
"comparison": "literal"
}
],
"expectedBidResponses": [{}]
"expectedBidResponses": []
}

0 comments on commit 8ed4059

Please sign in to comment.