Skip to content

Commit

Permalink
Reverting back to cleaner commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-lundin committed Aug 27, 2024
1 parent 84a8162 commit e813f2d
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 0 deletions.
46 changes: 46 additions & 0 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type siteExt struct {
Data interface{} `json:"data"`
}

type adnAdvertiser struct {
LegalName string `json:"legalName,omitempty"`
Name string `json:"name,omitempty"`
}

type Ad struct {
Bid struct {
Amount float64
Expand All @@ -56,6 +61,7 @@ type Ad struct {
LineItemId string
Html string
DestinationUrls map[string]string
Advertiser adnAdvertiser
}

type AdUnit struct {
Expand Down Expand Up @@ -369,6 +375,38 @@ func getGDPR(request *openrtb2.BidRequest) (string, string, error) {
return gdpr, consent, nil
}

func generateReturnExt(ad Ad, request *openrtb2.BidRequest) (json.RawMessage, error) {
// We always force the publisher to render
var adRender int8 = 0

var requestRegsExt *openrtb_ext.ExtRegs
if request.Regs != nil && request.Regs.Ext != nil {
if err := json.Unmarshal(request.Regs.Ext, &requestRegsExt); err != nil {

return nil, fmt.Errorf("Failed to parse Ext information in Adnuntius: %v", err)
}
}

if requestRegsExt != nil && requestRegsExt.DSA != nil && requestRegsExt.DSA.PubRender != &adRender {
ext := &openrtb_ext.ExtBid{
DSA: &openrtb_ext.ExtBidDSA{
AdRender: &adRender,
Paid: ad.Advertiser.LegalName,
Behalf: ad.Advertiser.LegalName,
},
}
returnExt, err := json.Marshal(ext)
if err != nil {
return nil, fmt.Errorf("Failed to parse Ext information in Adnuntius: %v", err)
}

return returnExt, nil
} else {
return nil, nil
}

}

func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) {

creativeWidth, widthErr := strconv.ParseInt(ad.CreativeWidth, 10, 64)
Expand Down Expand Up @@ -410,6 +448,13 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.
}
}

extJson, err := generateReturnExt(ad, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error extracting Ext: %s", err.Error()),
}}
}

adDomain := []string{}
for _, url := range ad.DestinationUrls {
domainArray := strings.Split(url, "/")
Expand All @@ -429,6 +474,7 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.
Price: price * 1000,
AdM: html,
ADomain: adDomain,
Ext: extJson,
}
return &bid, nil

Expand Down
46 changes: 46 additions & 0 deletions adapters/adnuntius/adnuntiustest/supplemental/check-dsa-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"id": "1kjh3429kjh295jkl"
},
"site": {
"ext":{
"data" : {
"key": ["value"]
}
}
},
"regs": {
"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 Adnuntius endpoint: failed to parse ExtRegs in Adnuntius GDPR check: json: cannot unmarshal string into Go value of type openrtb_ext.ExtRegs]",
"comparison": "literal"
}
]
}
135 changes: 135 additions & 0 deletions adapters/adnuntius/adnuntiustest/supplemental/check-dsa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"id": "1kjh3429kjh295jkl"
},
"site": {
"ext":{
"data" : {
"key": ["value"]
}
}
},
"regs": {
"ext": {
"dsa": {
"dsarequired": 3,
"pubrender": 1,
"datatopub": 1
}
}
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"auId": "123"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://whatever.url?format=prebid&tzo=0",
"body": {
"adUnits": [
{
"auId": "123",
"targetId": "123-test-imp-id",
"dimensions": [[300,250],[300,600]]
}
],
"kv": {
"key": ["value"]
},
"metaData": {
"usi": "1kjh3429kjh295jkl"
},
"context": "unknown"
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"adUnits": [
{
"auId": "0000000000000123",
"targetId": "123-test-imp-id",
"html": "<ADCODE>",
"responseId": "adn-rsp-900646517",
"ads": [
{
"destinationUrls": {
"url": "http://www.google.com"
},
"bid": {
"amount": 20.0,
"currency": "NOK"
},
"adId": "adn-id-1559784094",
"creativeWidth": "980",
"creativeHeight": "240",
"creativeId": "jn9hpzvlsf8cpdmm",
"lineItemId": "q7y9qm5b0xt9htrv",
"advertiser": {
"legalName": "LegalName",
"name": "Name"
}
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "adn-id-1559784094",
"impid": "test-imp-id",
"price": 20000,
"adm": "<ADCODE>",
"adid": "adn-id-1559784094",
"adomain": [
"google.com"
],
"cid": "q7y9qm5b0xt9htrv",
"crid": "jn9hpzvlsf8cpdmm",
"w": 980,
"h": 240,
"ext": {
"dsa": {
"paid": "LegalName",
"behalf": "LegalName",
"adrender": 0
}
}
},
"type": "banner"

}
],
"currency": "NOK"
}
]
}

0 comments on commit e813f2d

Please sign in to comment.