Skip to content

Commit

Permalink
New Adapter: Missena - Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfbsf committed Sep 15, 2024
1 parent 4d210b9 commit 8c79b48
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 28 deletions.
43 changes: 23 additions & 20 deletions adapters/missena/missena.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a *adapter) makeParameter(missenaParams MissenaInternalParams, request *op
return &missenaRequest
}

func (a *adapter) makeRequest(missenaParams MissenaInternalParams, reqInfo *adapters.ExtraRequestInfo, existingRequests []*adapters.RequestData, request *openrtb2.BidRequest) (*adapters.RequestData, error) {
func (a *adapter) makeRequest(missenaParams MissenaInternalParams, reqInfo *adapters.ExtraRequestInfo, imp *openrtb2.Imp, request *openrtb2.BidRequest) (*adapters.RequestData, error) {

url := a.endpoint + "?t=" + missenaParams.ApiKey
parameter := a.makeParameter(missenaParams, request)
Expand Down Expand Up @@ -106,30 +106,34 @@ func (a *adapter) makeRequest(missenaParams MissenaInternalParams, reqInfo *adap
Uri: url,
Headers: headers,
Body: body,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
ImpIDs: []string{imp.ID},
}, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
// print the request

var httpRequests []*adapters.RequestData
var tempErrors []error
var errors []error
gdprApplies, consentString := readGDPR(request)

var missenaInternalParams MissenaInternalParams
missenaInternalParams := MissenaInternalParams{
GDPR: gdprApplies,
GDPRConsent: consentString,
}

for _, imp := range request.Imp {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
tempErrors = append(tempErrors, &errortypes.BadInput{
errors = append(errors, &errortypes.BadInput{
Message: "Error parsing bidderExt object",
})
continue
}

var missenaExt openrtb_ext.ExtImpMissena
if err := json.Unmarshal(bidderExt.Bidder, &missenaExt); err != nil {
tempErrors = append(tempErrors, &errortypes.BadInput{
errors = append(errors, &errortypes.BadInput{
Message: "Error parsing missenaExt parameters",
})
continue
Expand All @@ -138,25 +142,25 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
missenaInternalParams.ApiKey = missenaExt.ApiKey
missenaInternalParams.Placement = missenaExt.Placement
missenaInternalParams.TestMode = missenaExt.TestMode
}

var finalErrors []error
missenaInternalParams.GDPR = gdprApplies
missenaInternalParams.GDPRConsent = consentString
newHttpRequest, err := a.makeRequest(missenaInternalParams, requestInfo, &imp, request)
if err != nil {
errors = append(errors, err)
continue
}

newHttpRequest, err := a.makeRequest(missenaInternalParams, requestInfo, httpRequests, request)
httpRequests = append(httpRequests, newHttpRequest)

if len(tempErrors) > 0 {
return nil, tempErrors
break
}

if err != nil {
finalErrors = append(finalErrors, err)
} else if newHttpRequest != nil {
httpRequests = append(httpRequests, newHttpRequest)
if len(httpRequests) == 0 && len(errors) == 0 {
errors = append(errors, &errortypes.BadInput{
Message: "No valid impressions found",
})
}

return httpRequests, finalErrors
return httpRequests, errors
}

func readGDPR(request *openrtb2.BidRequest) (bool, string) {
Expand Down Expand Up @@ -221,6 +225,5 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R

bidResponse.Bids = append(bidResponse.Bids, b)

var errors []error
return bidResponse, errors
return bidResponse, nil
}
2 changes: 1 addition & 1 deletion adapters/missena/missena_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderMissena, config.Adapter{
Endpoint: "https://bid.missena.io"},
Endpoint: "http://example.com/"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
Expand Down
105 changes: 105 additions & 0 deletions adapters/missena/missenatest/exemplary/ipv6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"mockBidRequest": {
"id": "test-request-id",
"tmax": 500,
"at": 1,
"cur": [
"EUR"
],
"regs": {
"ext": {
"gdpr": 1
}
},
"user": {
"ext": {
"consent": "CO-X2XiO_eyUoAsAxBFRBECsA"
}
},
"device": {
"ipv6": "2001:0000:130F:0000:0000:09C0:876A:130B",
"ua": "test-user-agent"
},
"site": {
"page": "https://example.com/page",
"domain": "example.com"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"h": 50,
"w": 320
},
"ext": {
"bidder": {
"apiKey": "test-api-key",
"placement": "test-placement",
"test": "1"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"2001:0000:130F:0000:0000:09C0:876A:130B"
],
"Referer": [
"https://example.com/page"
]
},
"body": {
"request_id": "test-request-id",
"timeout": 2000,
"referer": "https://example.com/page",
"referer_canonical": "example.com",
"consent_string": "CO-X2XiO_eyUoAsAxBFRBECsA",
"consent_required": true,
"placement": "test-placement",
"test": "1"
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"ad": "<div>test ad</div>",
"cpm": 1.5,
"currency": "EUR",
"requestId": "test-request-id"
}
}
}
],
"expectedBidResponses": [
{
"currency": "EUR",
"bids": [
{
"bid": {
"id": "test-request-id",
"impid": "test-imp-id",
"price": 1.5,
"adm": "<div>test ad</div>",
"crid": "test-request-id"
},
"type": "banner"
}
]
}
]
}
115 changes: 115 additions & 0 deletions adapters/missena/missenatest/exemplary/multiple-imps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"mockBidRequest": {
"id": "test-request-id",
"tmax": 500,
"at": 1,
"cur": [
"EUR"
],
"regs": {
"ext": {
"gdpr": 1
}
},
"user": {
"ext": {
"consent": "CO-X2XiO_eyUoAsAxBFRBECsA"
}
},
"device": {
"ip": "123.123.123.123",
"ua": "test-user-agent"
},
"site": {
"page": "https://example.com/page",
"domain": "example.com"
},
"imp": [
{
"id": "test-imp-id-1",
"banner": {
"h": 50,
"w": 320
},
"ext": {
"bidder": {
"apiKey": "test-api-key",
"placement": "test-placement-1",
"test": "1"
}
}
},
{
"id": "test-imp-id-2",
"banner": {
"h": 50,
"w": 320
},
"ext": {
"bidder": "abc"
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
],
"Referer": [
"https://example.com/page"
]
},
"body": {
"request_id": "test-request-id",
"timeout": 2000,
"referer": "https://example.com/page",
"referer_canonical": "example.com",
"consent_string": "CO-X2XiO_eyUoAsAxBFRBECsA",
"consent_required": true,
"placement": "test-placement-1",
"test": "1"
},
"impIDs":["test-imp-id-1"]
},
"mockResponse": {
"status": 200,
"body": {
"ad": "<div>test ad</div>",
"cpm": 1.5,
"currency": "EUR",
"requestId": "test-request-id"
}
}
}
],
"expectedBidResponses": [
{
"currency": "EUR",
"bids": [
{
"bid": {
"id": "test-request-id",
"impid": "test-imp-id-1",
"price": 1.5,
"adm": "<div>test ad</div>",
"crid": "test-request-id"
},
"type": "banner"
}
]
}
]
}
2 changes: 1 addition & 1 deletion adapters/missena/missenatest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://bid.missena.io?t=test-api-key",
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
Expand Down
2 changes: 1 addition & 1 deletion adapters/missena/missenatest/supplemental/status-204.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://bid.missena.io?t=test-api-key",
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
Expand Down
2 changes: 1 addition & 1 deletion adapters/missena/missenatest/supplemental/status-400.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://bid.missena.io?t=test-api-key",
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://bid.missena.io?t=test-api-key",
"uri": "http://example.com/?t=test-api-key",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
Expand Down
7 changes: 6 additions & 1 deletion adapters/missena/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ func TestInvalidParams(t *testing.T) {
}

var validParams = []string{
`{"apiKey": ""}`,
`{"apiKey": "PA-123456"}`,
`{"apiKey": "PA-123456", "placement": "sticky"}`,
`{"apiKey": "PA-123456", "test": "native"}`,
}

var invalidParams = []string{
`{"apiKey": ""}`,
`{"apiKey": 42}`,
`{"placement": 111}`,
`{"placement": "sticky"}`,
`{"apiKey": "PA-123456", "placement": 111}`,
`{"test": "native"}`,
`{"apiKey": "PA-123456", "test": 111}`,
}
2 changes: 1 addition & 1 deletion static/bidder-info/missena.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
endpoint: https://bid.missena.io/
maintainer:
email: yboussafa@missena.com
email: prebid@missena.com
gvlVendorID: 687
modifyingVastXmlAllowed: true
capabilities:
Expand Down
Loading

0 comments on commit 8c79b48

Please sign in to comment.