Skip to content

Commit

Permalink
Changes according to the comments on my pull request 4223
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-lundin committed Mar 4, 2025
1 parent c9e7a43 commit 9011125
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 32 deletions.
34 changes: 15 additions & 19 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
adUnit.AdType = "NATIVE"
nativeRequest := json.RawMessage{}

if err := json.Unmarshal([]byte(imp.Native.Request), &nativeRequest); err != nil {
if err := jsonutil.Unmarshal([]byte(imp.Native.Request), &nativeRequest); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error unmarshalling Native: %s", err.Error()),
}}
Expand Down Expand Up @@ -206,40 +206,36 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest)

ad := adunit.Ads[0]
html := adunit.Html
var bidType openrtb2.MarkupType = 1
var mType openrtb2.MarkupType = openrtb2.MarkupBanner

currency = ad.Bid.Currency
native, _, _, _ := jsonparser.Get(adunit.NativeJson, "ortb")

if native != nil {
html = string(native)
bidType = 4
mType = openrtb2.MarkupNative
}

adBid, err := generateAdResponse(ad, imp, html, bidType, request)
adBid, err := generateAdResponse(ad, imp, html, mType, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: "Error at ad generation",
}}
return nil, err
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: adBid,
BidType: convertMarkupTypeToBidType(bidType),
BidType: convertMarkupTypeToBidType(mType),
})

for _, deal := range adunit.Deals {
bidType = 1
dealBid, err := generateAdResponse(deal, imp, deal.Html, bidType, request)
mType = 1
dealBid, err := generateAdResponse(deal, imp, deal.Html, mType, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: "Error at ad generation",
}}
return nil, err
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: dealBid,
BidType: convertMarkupTypeToBidType(bidType),
BidType: convertMarkupTypeToBidType(mType),
})
}
}
Expand Down Expand Up @@ -279,28 +275,28 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, mType openrtb2.Mar

creativeWidth, widthErr := strconv.ParseInt(ad.CreativeWidth, 10, 64)
if widthErr != nil {
return nil, []error{&errortypes.BadInput{
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Value of width: %s is not a string", ad.CreativeWidth),
}}
}

creativeHeight, heightErr := strconv.ParseInt(ad.CreativeHeight, 10, 64)
if heightErr != nil {
return nil, []error{&errortypes.BadInput{
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Value of height: %s is not a string", ad.CreativeHeight),
}}
}

var bidderExt adapters.ExtImpBidder
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, []error{&errortypes.BadInput{
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Error unmarshalling ExtImpBidder: %s", err.Error()),
}}
}

var adnuntiusExt openrtb_ext.ImpExtAdnunitus
if err := jsonutil.Unmarshal(bidderExt.Bidder, &adnuntiusExt); err != nil {
return nil, []error{&errortypes.BadInput{
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Error unmarshalling ExtImpValues: %s", err.Error()),
}}
}
Expand All @@ -317,7 +313,7 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, mType openrtb2.Mar

extJson, err := generateReturnExt(ad, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Error extracting Ext: %s", err.Error()),
}}
}
Expand Down
33 changes: 21 additions & 12 deletions adapters/adnuntius/adnuntius_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@ func setHeaders(ortbRequest openrtb2.BidRequest) http.Header {

func makeEndpointUrl(ortbRequest openrtb2.BidRequest, a *adapter, noCookies bool) (string, []error) {
uri, err := url.Parse(a.endpoint)
endpointUrl := a.endpoint
if err != nil {
return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
}

gdpr, consent, err := getGDPR(&ortbRequest)
if err != nil {
return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
return "", []error{fmt.Errorf("failed to parse GDPR information: %v", err)}
}

if gdpr != "" {
extraInfoURI, err := url.Parse(a.extraInfo)
if err != nil {
return "", []error{fmt.Errorf("invalid extraInfo URL: %v", err)}
}
uri = extraInfoURI
}

if !noCookies {
var deviceExt extDeviceAdnuntius
if ortbRequest.Device != nil && ortbRequest.Device.Ext != nil {
if err := jsonutil.Unmarshal(ortbRequest.Device.Ext, &deviceExt); err != nil {
return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
return "", []error{fmt.Errorf("failed to parse device ext: %v", err)}
}
}

Expand All @@ -58,7 +65,6 @@ func makeEndpointUrl(ortbRequest openrtb2.BidRequest, a *adapter, noCookies bool

q := uri.Query()
if gdpr != "" {
endpointUrl = a.extraInfo
q.Set("gdpr", gdpr)
}

Expand All @@ -70,11 +76,14 @@ func makeEndpointUrl(ortbRequest openrtb2.BidRequest, a *adapter, noCookies bool
q.Set("noCookies", "true")
}

q.Set("tzo", fmt.Sprint(tzo))
q.Set("tzo", strconv.Itoa(tzo))
q.Set("format", "prebidServer")

url := endpointUrl + "?" + q.Encode()
return url, nil
// Set the query params to the URI
uri.RawQuery = q.Encode()

// Return the correctly formatted URL
return uri.String(), nil
}

func getImpSizes(imp openrtb2.Imp, bidType string) [][]int64 {
Expand Down Expand Up @@ -158,7 +167,7 @@ func generateReturnExt(ad Ad, request *openrtb2.BidRequest) (json.RawMessage, er
},
}

returnExt, err := json.Marshal(ext)
returnExt, err := jsonutil.Marshal(ext)
if err != nil {
return nil, fmt.Errorf("Failed to parse Ext information in Adnuntius: %v", err)
}
Expand Down Expand Up @@ -189,13 +198,13 @@ func generateAdUnit(imp openrtb2.Imp, adnuntiusExt openrtb_ext.ImpExtAdnunitus,
*/
func convertMarkupTypeToBidType(markupType openrtb2.MarkupType) openrtb_ext.BidType {
switch markupType {
case 1:
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner
case 2:
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo
case 3:
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio
case 4:
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative
}
return openrtb_ext.BidTypeBanner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"expectedMakeRequestsErrors": [
{
"value": "failed to parse URL: [failed to parse Adnuntius endpoint: failed to parse ExtRegs in Adnuntius GDPR check: expect { or n, but found \"]",
"value": "failed to parse URL: [failed to parse GDPR information: failed to parse ExtRegs in Adnuntius GDPR check: expect { or n, but found \"]",
"comparison": "literal"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"ext":""
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"auId": "123"
}
}
}
]
},
"expectedMakeRequestsErrors": [
{
"value": "failed to parse URL: [failed to parse GDPR information: failed to parse ExtUser in Adnuntius GDPR check: expect { or n, but found \"]",
"comparison": "literal"
}
]

}

0 comments on commit 9011125

Please sign in to comment.