diff --git a/adapters/verizonmedia/verizonmedia.go b/adapters/verizonmedia/verizonmedia.go index 64a48d6dbeb..106867033e0 100644 --- a/adapters/verizonmedia/verizonmedia.go +++ b/adapters/verizonmedia/verizonmedia.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" + "net/http" + "github.com/mxmCherry/openrtb" "github.com/prebid/prebid-server/adapters" "github.com/prebid/prebid-server/errortypes" "github.com/prebid/prebid-server/openrtb_ext" - "net/http" ) type VerizonMediaAdapter struct { @@ -25,8 +26,8 @@ func (a *VerizonMediaAdapter) SkipNoCookies() bool { } func (a *VerizonMediaAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { - errors := make([]error, 0, 1) + if len(request.Imp) == 0 { err := &errortypes.BadInput{ Message: "No impression in the bid request", @@ -35,68 +36,79 @@ func (a *VerizonMediaAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo return nil, errors } - var bidderExt adapters.ExtImpBidder - err := json.Unmarshal(request.Imp[0].Ext, &bidderExt) - if err != nil { - err = &errortypes.BadInput{ - Message: "ext.bidder not provided", + reqs := make([]*adapters.RequestData, 0, len(request.Imp)) + headers := http.Header{} + + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Set("User-Agent", request.Device.UA) + headers.Add("x-openrtb-version", "2.5") + + for idx, imp := range request.Imp { + var bidderExt adapters.ExtImpBidder + err := json.Unmarshal(imp.Ext, &bidderExt) + if err != nil { + err = &errortypes.BadInput{ + Message: fmt.Sprintf("imp #%d: ext.bidder not provided", idx), + } + errors = append(errors, err) + continue } - errors = append(errors, err) - return nil, errors - } - var verizonMediaExt openrtb_ext.ExtImpVerizonMedia - err = json.Unmarshal(bidderExt.Bidder, &verizonMediaExt) - if err != nil { - err = &errortypes.BadInput{ - Message: err.Error(), + + var verizonMediaExt openrtb_ext.ExtImpVerizonMedia + err = json.Unmarshal(bidderExt.Bidder, &verizonMediaExt) + if err != nil { + err = &errortypes.BadInput{ + Message: fmt.Sprintf("imp #%d: %s", idx, err.Error()), + } + errors = append(errors, err) + continue } - errors = append(errors, err) - return nil, errors - } - if verizonMediaExt.Dcn == "" { - err = &errortypes.BadInput{ - Message: "Missing param dcn", + if verizonMediaExt.Dcn == "" { + err = &errortypes.BadInput{ + Message: fmt.Sprintf("imp #%d: missing param dcn", idx), + } + errors = append(errors, err) + continue } - errors = append(errors, err) - return nil, errors - } - if verizonMediaExt.Pos == "" { - err = &errortypes.BadInput{ - Message: "Missing param pos", + if verizonMediaExt.Pos == "" { + err = &errortypes.BadInput{ + Message: fmt.Sprintf("imp #%d: missing param pos", idx), + } + errors = append(errors, err) + continue } - errors = append(errors, err) - return nil, errors - } - siteCopy := *request.Site - request.Site = &siteCopy - if err := changeRequestForBidService(request, &verizonMediaExt); err != nil { - errors = append(errors, err) - return nil, errors - } + // Split up multi-impression requests into multiple requests so that + // each split request is only associated to a single impression + reqCopy := *request + reqCopy.Imp = []openrtb.Imp{imp} - reqJSON, err := json.Marshal(request) - if err != nil { - errors = append(errors, err) - return nil, errors - } + siteCopy := *request.Site + reqCopy.Site = &siteCopy - thisURI := a.URI + if err := changeRequestForBidService(&reqCopy, &verizonMediaExt); err != nil { + errors = append(errors, err) + return nil, errors + } - headers := http.Header{} - headers.Add("Content-Type", "application/json;charset=utf-8") - headers.Add("Accept", "application/json") - headers.Set("User-Agent", request.Device.UA) - headers.Add("x-openrtb-version", "2.5") + reqJSON, err := json.Marshal(&reqCopy) + if err != nil { + errors = append(errors, err) + continue + } - return []*adapters.RequestData{{ - Method: "POST", - Uri: thisURI, - Body: reqJSON, - Headers: headers, - }}, errors + reqs = append(reqs, &adapters.RequestData{ + Method: "POST", + Uri: a.URI, + Body: reqJSON, + Headers: headers, + }) + } + + return reqs, errors } func (a *VerizonMediaAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { @@ -173,6 +185,10 @@ func changeRequestForBidService(request *openrtb.BidRequest, extension *openrtb_ request.Site.ID = extension.Dcn } + /* Always override the tag ID and site ID of the request */ + request.Imp[0].TagID = extension.Pos + request.Site.ID = extension.Dcn + if request.Imp[0].Banner == nil { return nil }