Skip to content

Smaato: Split multiple media types #1930

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

Merged
merged 2 commits into from
Jul 29, 2021
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newly created splitImpressionsByMediaType(...) function and the return nil statements in lines 459 and 465 make this line unreachable. It doesn't affect anything and I don't have a problem with it so, if you like to fix it in this PR, ok, but I will approve your PR either way. Your code looks pretty solid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, we will address this with next PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @el-chuck . Thank you for addressing our feedback

}

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