-
Notifications
You must be signed in to change notification settings - Fork 832
New Adapter: ResetDigital #3766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
70de190
dd48470
32551fc
125124b
5c56e12
fe4ff39
664614f
0b44384
0775c72
20fa856
33f4603
e468217
b8ca566
2de7781
eb067f7
86206d7
3fc5455
3762676
989c565
39905ed
4482bc9
d426e8a
ac2fc01
52a6794
9626103
dea6cf7
5cfe0ae
ece8152
baa553c
ecc90bb
0d54a8d
660dba7
5f70f11
613317a
a083c03
bc7caaf
4569e97
0bc2aeb
d212d91
cff2442
44bee69
96fde76
6e08b5d
ec4005d
fd3ec0d
8bca6ad
278be3f
56a77a0
f0e2574
0e365ce
f2d3afc
d6e24d0
eceef87
e86d017
baa974f
73c3fe0
246010f
cff5817
5ab5517
d3df8f2
c1795b8
1665bc9
0f6f5b1
27863db
f0da5d7
6c745fb
56b03f1
21eecdd
dcd9dad
2584c6b
123cb13
4950da1
cc06d05
330d84f
17cf6c8
5b44280
ee3546c
2ecc9a8
0a4d9bc
b93dca3
ef65f7b
6bac6cd
62f74c1
4a0ec3f
11c824f
905485d
0623316
e82c838
a96efc8
8ed4059
415d551
f0a4ad4
fe2c572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please achieve code coverage of this error case by adding a supplemental JSON test (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
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))} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please achieve code coverage of this error case by adding a supplemental JSON test (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
// 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)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please achieve code coverage of this error case by adding a supplemental JSON test (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,5 +87,5 @@ | |
"comparison": "literal" | ||
} | ||
], | ||
"expectedBidResponses": [{}] | ||
"expectedBidResponses": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,5 +87,5 @@ | |
"comparison": "literal" | ||
} | ||
], | ||
"expectedBidResponses": [{}] | ||
"expectedBidResponses": [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I suggest removing all of the comments in this function to tighten this up. IMO your code is self explanatory now. You can leave it of course if you think it will benefit your developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.