Skip to content
Closed
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
92 changes: 88 additions & 4 deletions adapters/rtbhouse/rtbhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ const (
BidderCurrency string = "USD"
)

// publisherExtPrebid defines the structure for publisher.ext.prebid used by RTBHouse adapter
type publisherExtPrebid struct {
PublisherId string `json:"publisherId,omitempty"`
}

// publisherExt defines the structure for publisher.ext used by RTBHouse adapter
type publisherExt struct {
Prebid *publisherExtPrebid `json:"prebid,omitempty"`
}

// RTBHouseAdapter implements the Bidder interface.
type RTBHouseAdapter struct {
endpoint string
Expand All @@ -45,14 +55,23 @@ func (adapter *RTBHouseAdapter) MakeRequests(

reqCopy := *openRTBRequest
reqCopy.Imp = []openrtb2.Imp{}

var publisherId string

for _, imp := range openRTBRequest.Imp {
rtbhouseExt, err := getImpressionExt(imp)
if err != nil {
return nil, []error{err}
}

// Extract publisherId from the first impression that has one
if publisherId == "" && rtbhouseExt.PublisherId != "" {
publisherId = rtbhouseExt.PublisherId
}

var bidFloorCur = imp.BidFloorCur
var bidFloor = imp.BidFloor
if bidFloorCur == "" && bidFloor == 0 {
rtbhouseExt, err := getImpressionExt(imp)
if err != nil {
return nil, []error{err}
}
if rtbhouseExt.BidFloor > 0 {
bidFloor = rtbhouseExt.BidFloor
bidFloorCur = BidderCurrency
Expand Down Expand Up @@ -90,11 +109,22 @@ func (adapter *RTBHouseAdapter) MakeRequests(
}
imp.Ext = newImpExt

// Remove PMP from impression
imp.PMP = nil

// Set the CUR of bid to BIDDER_CURRENCY after converting all floors
reqCopy.Cur = []string{BidderCurrency}
reqCopy.Imp = append(reqCopy.Imp, imp)
}

// Set publisher ID in site.publisher.ext.prebid.publisherId or app.publisher.ext.prebid.publisherId if we found one
if publisherId != "" {
if err := setPublisherID(&reqCopy, publisherId); err != nil {
errs = append(errs, err)
return nil, errs
}
}

openRTBRequestJSON, err := json.Marshal(reqCopy)
if err != nil {
errs = append(errs, err)
Expand All @@ -115,6 +145,60 @@ func (adapter *RTBHouseAdapter) MakeRequests(
return requestsToBidder, errs
}

// setPublisherID sets the publisherId in site.publisher.ext.prebid.publisherId or app.publisher.ext.prebid.publisherId
func setPublisherID(request *openrtb2.BidRequest, publisherId string) error {
var publisher *openrtb2.Publisher
if request.Site != nil {
// Create a copy of the site to avoid modifying the original request
siteCopy := *request.Site
request.Site = &siteCopy
publisher = request.Site.Publisher
} else if request.App != nil {
// Create a copy of the app to avoid modifying the original request
appCopy := *request.App
request.App = &appCopy
publisher = request.App.Publisher
} else {
// If neither site nor app exists, create a site object
request.Site = &openrtb2.Site{}
}

if publisher != nil {
// Create a copy of the publisher to avoid modifying the original request
publisherCopy := *publisher
publisher = &publisherCopy
} else {
publisher = &openrtb2.Publisher{}
}

// Set publisherId in publisher.ext.prebid.publisherId using local struct
var pubExt publisherExt
if publisher.Ext != nil {
if err := jsonutil.Unmarshal(publisher.Ext, &pubExt); err != nil {
return err
}
}
if pubExt.Prebid == nil {
pubExt.Prebid = &publisherExtPrebid{}
}
pubExt.Prebid.PublisherId = publisherId

publisherExtJSON, err := jsonutil.Marshal(pubExt)
if err != nil {
return err
}
publisher.Ext = publisherExtJSON

// Assign the updated publisher back to the appropriate object
if request.Site != nil {
request.Site.Publisher = publisher
} else if request.App != nil {
request.App.Publisher = publisher
}

return nil
}

func clearAuctionEnvironment(imp *openrtb2.Imp) (json.RawMessage, error) {
var objmap map[string]interface{}
err := json.Unmarshal(imp.Ext, &objmap)
Expand Down
118 changes: 118 additions & 0 deletions adapters/rtbhouse/rtbhousetest/exemplary/ae-igs-removal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"ae": 1,
"igs": {
"biddable": 1
},
"bidder": {
"publisherId": "12345"
},
"someOtherField": "should-remain"
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": [
"USD"
],
"imp": [
{
"banner": {
"format": [
{
"h": 250,
"w": 300
}
]
},
"ext": {
"bidder": {
"publisherId": "12345"
},
"someOtherField": "should-remain"
},
"id": "test-imp-id"
}
],
"site": {
"publisher": {
"ext": {
"prebid": {
"publisherId": "12345"
}
}
}
}
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-response-id",
"cur": "USD",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
118 changes: 118 additions & 0 deletions adapters/rtbhouse/rtbhousetest/exemplary/app-with-publisher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.example.app",
"name": "Test App"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"publisherId": "app-publisher-123"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": [
"USD"
],
"app": {
"bundle": "com.example.app",
"name": "Test App",
"publisher": {
"ext": {
"prebid": {
"publisherId": "app-publisher-123"
}
}
}
},
"imp": [
{
"banner": {
"format": [
{
"h": 250,
"w": 300
}
]
},
"ext": {
"bidder": {
"publisherId": "app-publisher-123"
}
},
"id": "test-imp-id"
}
]
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-response-id",
"cur": "USD",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
"id": "test-imp-id"
}
],
"site": {
"publisher": {
"ext": {
"prebid": {
"publisherId": "12345"
}
}
}
},
"ext": {
"prebid": {
"currency": {
Expand Down
Loading
Loading