Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobilefuse adapter: Added support for multiple imps and multiple imp types #2950

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions adapters/mobilefuse/mobilefuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,16 @@ func (adapter *MobileFuseAdapter) makeRequest(bidRequest *openrtb2.BidRequest) (
var errs []error

mobileFuseExtension, errs := getFirstMobileFuseExtension(bidRequest)

if errs != nil {
return nil, errs
}

endpoint, err := adapter.getEndpoint(mobileFuseExtension)

if err != nil {
return nil, append(errs, err)
}

validImps, err := getValidImps(bidRequest, mobileFuseExtension)

if err != nil {
errs = append(errs, err)
return nil, errs
Expand All @@ -121,7 +118,6 @@ func (adapter *MobileFuseAdapter) makeRequest(bidRequest *openrtb2.BidRequest) (
mobileFuseBidRequest := *bidRequest
mobileFuseBidRequest.Imp = validImps
body, err := json.Marshal(mobileFuseBidRequest)

if err != nil {
return nil, append(errs, err)
}
Expand Down Expand Up @@ -165,13 +161,23 @@ func getFirstMobileFuseExtension(request *openrtb2.BidRequest) (*openrtb_ext.Ext
return &mobileFuseImpExtension, errs
}

func getMobileFuseExtensionForImp(imp *openrtb2.Imp, mobileFuseImpExtension *openrtb_ext.ExtImpMobileFuse) error {
var bidder_imp_extension adapters.ExtImpBidder

err := json.Unmarshal(imp.Ext, &bidder_imp_extension)
if err != nil {
return err
}

return json.Unmarshal(bidder_imp_extension.Bidder, &mobileFuseImpExtension)
}

func (adapter *MobileFuseAdapter) getEndpoint(ext *openrtb_ext.ExtImpMobileFuse) (string, error) {
publisher_id := strconv.Itoa(ext.PublisherId)

url, errs := macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{PublisherID: publisher_id})

if errs != nil {
return "", errs
url, err := macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{PublisherID: publisher_id})
if err != nil {
return "", err
}

if ext.TagidSrc == "ext" {
Expand All @@ -186,10 +192,15 @@ func getValidImps(bidRequest *openrtb2.BidRequest, ext *openrtb_ext.ExtImpMobile

for _, imp := range bidRequest.Imp {
if imp.Banner != nil || imp.Video != nil || imp.Native != nil {
err := getMobileFuseExtensionForImp(&imp, ext)
if err != nil {
return nil, err
}

imp.TagID = strconv.Itoa(ext.PlacementId)

var extSkadn ExtSkadn
err := json.Unmarshal(imp.Ext, &extSkadn)
err = json.Unmarshal(imp.Ext, &extSkadn)
if err != nil {
return nil, err
}
Expand All @@ -204,8 +215,6 @@ func getValidImps(bidRequest *openrtb2.BidRequest, ext *openrtb_ext.ExtImpMobile
}

validImps = append(validImps, imp)

break
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 320,
"h": 50
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 320,
"h": 480
},
"ext": {
"bidder": {
"placement_id": 123456,
"pub_id": 1234
}
}
},
{
"id": "2",
"banner": {
"format": [
{
"w": 300,
"h": 50
}
]
},
"native": {
"ver": "1.2",
"request": "{\"native\":{\"assets\":[{\"id\":0,\"required\":1,\"img\":{\"url\":\"...\"}},{\"id\":1,\"required\":1,\"title\":{\"text\":\"custom title\"}}]}}"
},
"ext": {
"bidder": {
"placement_id": 234567,
"pub_id": 1234
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://mfx.mobilefuse.com/openrtb?pub_id=1234",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 320,
"h": 50
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 320,
"h": 480
},
"tagid": "123456"
},
{
"id": "2",
"banner": {
"format": [
{
"w": 300,
"h": 50
}
]
},
"native": {
"ver": "1.2",
"request": "{\"native\":{\"assets\":[{\"id\":0,\"required\":1,\"img\":{\"url\":\"...\"}},{\"id\":1,\"required\":1,\"title\":{\"text\":\"custom title\"}}]}}"
},
"tagid": "234567"
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "mobilefuse",
"bid": [
{
"id": "test-bid-id",
"impid": "1",
"price": 1.50,
"adm": "some-test-ad",
"crid": "test-crid",
"h": 50,
"w": 320,
"ext": {
"mf": {
"media_type": "banner"
}
}
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "1",
"price": 1.50,
"adm": "some-test-ad",
"crid": "test-crid",
"w": 320,
"h": 50
},
"type": "banner"
}
]
}
]
}
12 changes: 12 additions & 0 deletions adapters/mobilefuse/mobilefusetest/exemplary/multi-imps.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
]
},
"tagid": "123456"
},
{
"id": "2",
"banner": {
"format": [
{
"w": 300,
"h": 50
}
]
},
"tagid": "234567"
}
]
}
Expand Down
Loading