Skip to content

Commit

Permalink
Merge branch 'master' into bidderRequestPayload_RequestWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 committed Sep 24, 2023
2 parents 80daab8 + 55302c6 commit 64ca130
Show file tree
Hide file tree
Showing 90 changed files with 4,871 additions and 701 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,25 @@ jobs:
outputs:
hasWritePermission: ${{ steps.check.outputs.require-result }}

build-master:
name: Build master
needs: check-permission
if: contains(needs.check-permission.outputs.hasWritePermission, 'true')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0
repository: ${{ github.repository }}
ref: master
- name: Build and validate
run: |
./validate.sh
publish-tag:
name: Publish tag
needs: check-permission
needs: build-master
if: contains(needs.check-permission.outputs.hasWritePermission, 'true')
permissions:
contents: write
Expand Down
24 changes: 20 additions & 4 deletions adapters/infoawarebidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// media types defined in the static/bidder-info/{bidder}.yaml file.
//
// It adjusts incoming requests in the following ways:
// 1. If App or Site traffic is not supported by the info file, then requests from
// 1. If App, Site or DOOH traffic is not supported by the info file, then requests from
// those sources will be rejected before the delegate is called.
// 2. If a given MediaType is not supported for the platform, then it will be set
// to nil before the request is forwarded to the delegate.
Expand All @@ -24,7 +24,7 @@ type InfoAwareBidder struct {
info parsedBidderInfo
}

// BuildInfoAwareBidder wraps a bidder to enforce site, app, and media type support.
// BuildInfoAwareBidder wraps a bidder to enforce inventory {site, app, dooh} and media type support.
func BuildInfoAwareBidder(bidder Bidder, info config.BidderInfo) Bidder {
return &InfoAwareBidder{
Bidder: bidder,
Expand All @@ -47,6 +47,12 @@ func (i *InfoAwareBidder) MakeRequests(request *openrtb2.BidRequest, reqInfo *Ex
}
allowedMediaTypes = i.info.app
}
if request.DOOH != nil {
if !i.info.dooh.enabled {
return nil, []error{&errortypes.Warning{Message: "this bidder does not support dooh requests"}}
}
allowedMediaTypes = i.info.dooh
}

// Filtering imps is quite expensive (array filter with large, non-pointer elements)... but should be rare,
// because it only happens if the publisher makes a really bad request.
Expand Down Expand Up @@ -136,6 +142,7 @@ func filterImps(imps []openrtb2.Imp, numToFilter int) ([]openrtb2.Imp, []error)
type parsedBidderInfo struct {
app parsedSupports
site parsedSupports
dooh parsedSupports
}

type parsedSupports struct {
Expand All @@ -148,13 +155,22 @@ type parsedSupports struct {

func parseBidderInfo(info config.BidderInfo) parsedBidderInfo {
var parsedInfo parsedBidderInfo
if info.Capabilities != nil && info.Capabilities.App != nil {

if info.Capabilities == nil {
return parsedInfo
}

if info.Capabilities.App != nil {
parsedInfo.app.enabled = true
parsedInfo.app.banner, parsedInfo.app.video, parsedInfo.app.audio, parsedInfo.app.native = parseAllowedTypes(info.Capabilities.App.MediaTypes)
}
if info.Capabilities != nil && info.Capabilities.Site != nil {
if info.Capabilities.Site != nil {
parsedInfo.site.enabled = true
parsedInfo.site.banner, parsedInfo.site.video, parsedInfo.site.audio, parsedInfo.site.native = parseAllowedTypes(info.Capabilities.Site.MediaTypes)
}
if info.Capabilities.DOOH != nil {
parsedInfo.dooh.enabled = true
parsedInfo.dooh.banner, parsedInfo.dooh.video, parsedInfo.dooh.audio, parsedInfo.dooh.native = parseAllowedTypes(info.Capabilities.DOOH.MediaTypes)
}
return parsedInfo
}
30 changes: 27 additions & 3 deletions adapters/infoawarebidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAppNotSupported(t *testing.T) {
Expand Down Expand Up @@ -56,6 +57,26 @@ func TestSiteNotSupported(t *testing.T) {
assert.Len(t, bids, 0)
}

func TestDOOHNotSupported(t *testing.T) {
bidder := &mockBidder{}
info := config.BidderInfo{
Capabilities: &config.CapabilitiesInfo{
Site: &config.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner},
},
},
}
constrained := adapters.BuildInfoAwareBidder(bidder, info)
bids, errs := constrained.MakeRequests(&openrtb2.BidRequest{
Imp: []openrtb2.Imp{{ID: "imp-1", Banner: &openrtb2.Banner{}}},
DOOH: &openrtb2.DOOH{},
}, &adapters.ExtraRequestInfo{})
require.Len(t, errs, 1)
assert.EqualError(t, errs[0], "this bidder does not support dooh requests")
assert.IsType(t, &errortypes.Warning{}, errs[0])
assert.Len(t, bids, 0)
}

func TestImpFiltering(t *testing.T) {
bidder := &mockBidder{}
info := config.BidderInfo{
Expand All @@ -66,6 +87,9 @@ func TestImpFiltering(t *testing.T) {
App: &config.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner},
},
DOOH: &config.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeNative},
},
},
}

Expand Down Expand Up @@ -153,10 +177,10 @@ func TestImpFiltering(t *testing.T) {
description: "All imps with correct media type, MakeRequest() call expected",
inBidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{ID: "imp-1", Video: &openrtb2.Video{}},
{ID: "imp-2", Video: &openrtb2.Video{}},
{ID: "imp-1", Native: &openrtb2.Native{}},
{ID: "imp-2", Native: &openrtb2.Native{}},
},
Site: &openrtb2.Site{},
DOOH: &openrtb2.DOOH{},
},
expectedErrors: nil,
expectedImpLen: 2,
Expand Down
99 changes: 99 additions & 0 deletions adapters/mabidder/mabidder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package mabidder

import (
"encoding/json"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
)

type serverResponse struct {
Responses []bidResponse
PrivateIdStatus string `json:"-"`
}

type bidResponse struct {
RequestID string `json:"requestId"`
Currency string `json:"currency"`
Width int32 `json:"width"`
Height int32 `json:"height"`
PlacementId string `json:"creativeId"`
Deal string `json:"dealId,omitempty"`
NetRevenue bool `json:"netRevenue"`
TimeToLiveSeconds int32 `json:"ttl"`
AdTag string `json:"ad"`
MediaType string `json:"mediaType"`
Meta meta `json:"meta"`
CPM float32 `json:"cpm"`
}

type meta struct {
AdDomain []string `json:"advertiserDomains"`
}

type adapter struct {
endpoint string
}

// Builder builds a new instance of the Mabidder adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

requestData := &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: requestJSON,
}

return []*adapters.RequestData{requestData}, nil
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}

var response serverResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
for _, maBidResp := range response.Responses {
b := &adapters.TypedBid{
Bid: &openrtb2.Bid{
ID: maBidResp.RequestID,
ImpID: maBidResp.RequestID,
Price: float64(maBidResp.CPM),
AdM: maBidResp.AdTag,
W: int64(maBidResp.Width),
H: int64(maBidResp.Height),
CrID: maBidResp.PlacementId,
DealID: maBidResp.Deal,
ADomain: maBidResp.Meta.AdDomain,
},
BidType: openrtb_ext.BidType(maBidResp.MediaType),
}
bidResponse.Bids = append(bidResponse.Bids, b)
if maBidResp.Currency != "" {
bidResponse.Currency = maBidResp.Currency
}
}
return bidResponse, nil
}
21 changes: 21 additions & 0 deletions adapters/mabidder/mabidder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mabidder

import (
"testing"

"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderMabidder, config.Adapter{
Endpoint: "https://prebid.ecdrsvc.com/pbs"},
config.Server{ExternalUrl: "https://prebid.ecdrsvc.com/pbs", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "mabiddertest", bidder)
}
110 changes: 110 additions & 0 deletions adapters/mabidder/mabiddertest/exemplary/simple-app-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "ppidtest"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prebid.ecdrsvc.com/pbs",
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "ppidtest"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"Responses": [
{
"requestId": "1",
"currency": "CAD",
"width": 300,
"height": 250,
"creativeId": "6002677",
"dealId": "testdeal",
"netRevenue": false,
"ttl": 5,
"ad": "<script type='text/javascript' src='https://adsvr.ecdrsvc.com/js?6002677'></script>",
"meta": {
"advertiserDomains": [
"https://www.loblaws.ca/"
]
},
"cpm": 3.5764000415802
}
]
}
}
}
],
"expectedBidResponses": [
{
"id": "test-request-id",
"bids": [
{
"bid": {
"id": "1",
"impid": "1",
"price":3.5764000415802,
"adm": "<script type='text/javascript' src='https://adsvr.ecdrsvc.com/js?6002677'></script>",
"adomain": [
"https://www.loblaws.ca/"
],
"crid": "6002677",
"dealid": "testdeal",
"w": 300,
"h": 250
}
}
],
"cur": "USD"
}
]
}
Loading

0 comments on commit 64ca130

Please sign in to comment.