Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
przemkaczmarek committed Dec 10, 2024
1 parent b16e499 commit 4745c28
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 52 deletions.
77 changes: 28 additions & 49 deletions adapters/intertech/intertech.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,71 +206,50 @@ func getCur(request *openrtb2.BidRequest) string {
return ""
}

func (a *adapter) MakeBids(req *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if responseData.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d", responseData.StatusCode),
}}
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

var bidResp openrtb2.BidResponse
if err := jsonutil.Unmarshal(responseData.Body, &bidResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Failed to decode bid response: %s", err.Error()),
}}
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}

seatBids := bidResp.SeatBid
if seatBids == nil {
return &adapters.BidderResponse{
Currency: bidResp.Cur,
Bids: make([]*adapters.TypedBid, 0),
}, nil
var response openrtb2.BidResponse
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

if len(seatBids) == 0 {
return nil, []error{&errortypes.BadServerResponse{
Message: "SeatBids is empty",
}}
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
if len(response.Cur) != 0 {
bidResponse.Currency = response.Cur
}

bidderResponse := adapters.NewBidderResponseWithBidsCapacity(len(seatBids))
bidderResponse.Currency = bidResp.Cur

var errs []error
for _, seatBid := range seatBids {
for _, bid := range seatBid.Bid {
bidType, err := getBidTypeFromImps(bid.ImpID, req.Imp)
for _, seatBid := range response.SeatBid {
for i := range seatBid.Bid {
bid := seatBid.Bid[i]
bidType, err := getBidType(bid)
if err != nil {
errs = append(errs, &errortypes.BadServerResponse{Message: err.Error()})
continue
return nil, []error{err}
}
typedBid := &adapters.TypedBid{
Bid: &bid,

b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
BidType: bidType,
}
bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
}
}

return bidderResponse, errs
}

func getBidTypeFromImps(bidImpID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
for _, imp := range imps {
if imp.ID == bidImpID {
return resolveImpType(imp)
bidResponse.Bids = append(bidResponse.Bids, b)
}
}
return "", fmt.Errorf("Invalid bid imp ID %s does not match any imp IDs from the original bid request", bidImpID)
return bidResponse, nil
}

func resolveImpType(imp openrtb2.Imp) (openrtb_ext.BidType, error) {
if imp.Native != nil {
return openrtb_ext.BidTypeNative, nil
}
if imp.Banner != nil {
func getBidType(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
}
return "", fmt.Errorf("Processing an invalid impression; cannot resolve impression type")

return "", fmt.Errorf("could not define media type for impression: %s", bid.ImpID)
}
8 changes: 5 additions & 3 deletions adapters/intertech/intertechtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"cid": "test_cid",
"crid": "test_crid",
"w": 300,
"h": 250
"h": 250,
"mtype": 1
}
]
}
Expand All @@ -101,11 +102,12 @@
"cid": "test_cid",
"crid": "test_crid",
"w": 300,
"h": 250
"h": 250,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
}

0 comments on commit 4745c28

Please sign in to comment.