Skip to content

Commit

Permalink
Smaato: Split multiple media types (prebid#1930)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernhard Pickenbrock <[email protected]>
  • Loading branch information
el-chuck and el-chuck authored Jul 29, 2021
1 parent 4a78264 commit 2e9b897
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 33 deletions.
49 changes: 39 additions & 10 deletions adapters/smaato/smaato.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/prebid/prebid-server/util/timeutil"
)

const clientVersion = "prebid_server_0.3"
const clientVersion = "prebid_server_0.4"

type adMarkupType string

Expand Down Expand Up @@ -160,24 +160,53 @@ func (adapter *adapter) makeIndividualRequests(request *openrtb2.BidRequest) ([]
errors := make([]error, 0, len(imps))

for _, imp := range imps {
request.Imp = []openrtb2.Imp{imp}
if err := prepareIndividualRequest(request); err != nil {
errors = append(errors, err)
continue
}

requestData, err := adapter.makeRequest(request)
impsByMediaType, err := splitImpressionsByMediaType(&imp)
if err != nil {
errors = append(errors, err)
continue
}

requests = append(requests, requestData)
for _, impByMediaType := range impsByMediaType {
request.Imp = []openrtb2.Imp{impByMediaType}
if err := prepareIndividualRequest(request); err != nil {
errors = append(errors, err)
continue
}

requestData, err := adapter.makeRequest(request)
if err != nil {
errors = append(errors, err)
continue
}

requests = append(requests, requestData)
}
}

return requests, errors
}

func splitImpressionsByMediaType(imp *openrtb2.Imp) ([]openrtb2.Imp, error) {
if imp.Banner == nil && imp.Video == nil {
return nil, &errortypes.BadInput{Message: "Invalid MediaType. Smaato only supports Banner and Video."}
}

imps := make([]openrtb2.Imp, 0, 2)

if imp.Banner != nil {
impCopy := *imp
impCopy.Video = nil
imps = append(imps, impCopy)
}

if imp.Video != nil {
imp.Banner = nil
imps = append(imps, *imp)
}

return imps, nil
}

func (adapter *adapter) makePodRequests(request *openrtb2.BidRequest) ([]*adapters.RequestData, []error) {
pods, orderedKeys, errors := groupImpressionsByPod(request.Imp)
requests := make([]*adapters.RequestData, 0, len(pods))
Expand Down Expand Up @@ -436,7 +465,7 @@ func setImpForAdspace(imp *openrtb2.Imp) error {
return nil
}

return &errortypes.BadInput{Message: "Invalid MediaType. Smaato only supports Banner and Video."}
return nil
}

func setImpForAdBreak(imps []openrtb2.Imp) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}
]
},
"bidfloor": 0.00123,
"ext": {
"bidder": {
"publisherId": "1100042525",
Expand Down Expand Up @@ -65,6 +66,7 @@
"rewarded": 0
}
},
"bidfloor": 0.00456,
"ext": {
"bidder": {
"publisherId": "1100042526",
Expand Down Expand Up @@ -114,6 +116,7 @@
{
"id": "1C86242D-9535-47D6-9576-7B1FE87F282C",
"tagid": "130563103",
"bidfloor": 0.00123,
"banner": {
"h": 50,
"w": 320,
Expand Down Expand Up @@ -159,7 +162,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_0.3"
"client": "prebid_server_0.4"
}
}
},
Expand Down Expand Up @@ -208,6 +211,7 @@
{
"id": "postbid_iframe",
"tagid": "130563104",
"bidfloor": 0.00456,
"video": {
"w": 1024,
"h": 768,
Expand Down Expand Up @@ -264,7 +268,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_0.3"
"client": "prebid_server_0.4"
}
}
},
Expand Down
Loading

0 comments on commit 2e9b897

Please sign in to comment.