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

New Adapter: Roundhouseads #3977

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c18b548
Upload full Prebid stack with roadhouseads bidder integration
Sep 22, 2024
8e2a865
Added Procfile for Elastic Beanstalk deployment
Sep 23, 2024
48283ed
Updated Procfile for Elastic Beanstalk deployment
Sep 23, 2024
c2e486e
Updated Procfile for Elastic Beanstalk deployment
Sep 23, 2024
fa0ca08
Updated configuration for Prebid Server deployment
Sep 23, 2024
e651e5a
Added pbs.yaml with GDPR configuration
Sep 24, 2024
9afd76b
Added pbs.yaml with GDPR configuration
Sep 24, 2024
63ac7ec
Added roundhouseads bidder adapter and updated configs
Sep 24, 2024
c1d5cbf
Updated pbs.yaml with port 8000 and configuration changes
Sep 24, 2024
4daa91b
Initial commit or some description
Sep 24, 2024
56eb91d
update to 8080 in yaml
Sep 27, 2024
61bcc3e
update main.go
Sep 27, 2024
ee97e74
Updated Nginx and Prebid Server to use port 8000
Sep 29, 2024
59f3680
update
Sep 29, 2024
fcf44c8
update
Sep 29, 2024
5c8da13
update
Sep 29, 2024
eaec6fa
update
Sep 29, 2024
a64ccaf
update
Sep 29, 2024
93b990c
update
Sep 29, 2024
a8cfb79
update
Sep 29, 2024
8d93f80
Updated roundhouseads.yaml with new bidder endpoint
Sep 29, 2024
f7775e4
update
Sep 29, 2024
b9f3bd6
Update to bidder endpoint and setup
Sep 29, 2024
615eb64
Updated roundhouseads.yaml with correct bidder endpoint and other upd…
Sep 29, 2024
3716a26
update
Sep 29, 2024
15a1ec1
Updated pbs.yaml and roundhouseads.yaml with new bidder configuration
Sep 29, 2024
05f5f24
Updated pbs.yaml and roundhouseads.yaml with new bidder endpoint and …
Sep 29, 2024
48f51f3
Updated pbs.yaml and roundhouseads.yaml with new bidder endpoint and …
Sep 29, 2024
f4a4299
update
Sep 29, 2024
5c1be24
update
Sep 30, 2024
e583b10
Updated
Sep 30, 2024
3fde7a3
Updated
Sep 30, 2024
3abe68b
Updated
Sep 30, 2024
15458d6
Updated
Sep 30, 2024
83686cc
Updated
Oct 2, 2024
3130692
Updated
Oct 2, 2024
6d665ac
update
Oct 5, 2024
be82def
Updated
Oct 13, 2024
429de15
Delete .elasticbeanstalk/config.yml
juliansalinas121 Oct 14, 2024
be68f9f
Delete Procfile
juliansalinas121 Oct 14, 2024
626d158
Delete pbs.yaml
juliansalinas121 Oct 14, 2024
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
5 changes: 5 additions & 0 deletions .elasticbeanstalk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global:
application_name: roundhouseads-prebid
default_region: us-east-1
profile: eb-cli # Ensure that this is correctly configured
workspace_type: Application
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: go run main.go
53 changes: 53 additions & 0 deletions adapters/roundhouseads/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package roundhouseads

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v2/openrtb_ext"
)

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, validParam := range validParams {
if err := validator.Validate(openrtb_ext.BidderRoundhouseads, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected Roundhouseads params: %s", validParam)
}
}
}

// TestInvalidParams makes sure that the Roundhouseads schema rejects all the imp.ext fields we don't support.
func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderRoundhouseads, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}

var validParams = []string{
`{"publisherId": "123456"}`,
`{"publisherId": "pub-123456"}`,
`{"publisherId": "publisherIDAllString"}`,
}

var invalidParams = []string{
``,
`null`,
`true`,
`5`,
`4.2`,
`[]`,
`{}`,
`{"publisherId": 123456}`,
`{"publisherId": 0}`,
}
196 changes: 196 additions & 0 deletions adapters/roundhouseads/roundhouseads.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package roundhouseads

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"regexp"
"text/template"

"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"

"github.com/prebid/openrtb/v20/openrtb2"
)

const PREBID_INTEGRATION_TYPE = "1"

type adapter struct {
bidderEndpoint string
}

type ExtImpBidderRoundhouseads struct {
adapters.ExtImpBidder
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
pubID, err := getPublisherId(request.Imp)

if err != nil {
return nil, []error{err}
}

modifiedImps := make([]openrtb2.Imp, 0, len(request.Imp))

for _, imp := range request.Imp {

if imp.Banner != nil {
if len(imp.Banner.Format) > 0 {
firstFormat := imp.Banner.Format[0]
bannerCopy := *imp.Banner
bannerCopy.H = &firstFormat.H
bannerCopy.W = &firstFormat.W
imp.Banner = &bannerCopy

}
}

modifiedImps = append(modifiedImps, imp)
}

request.Imp = modifiedImps

if request.Site != nil {
siteCopy := *request.Site
if siteCopy.Publisher != nil {
publisherCopy := *siteCopy.Publisher
if pubID != "" {
publisherCopy.ID = pubID
}
siteCopy.Publisher = &publisherCopy
} else {
siteCopy.Publisher = &openrtb2.Publisher{ID: pubID}
}
request.Site = &siteCopy
} else if request.App != nil {
appCopy := *request.App
if appCopy.Publisher != nil {
publisherCopy := *appCopy.Publisher
if pubID != "" {
publisherCopy.ID = pubID
}
appCopy.Publisher = &publisherCopy
} else {
appCopy.Publisher = &openrtb2.Publisher{ID: pubID}
}
request.App = &appCopy
}

errs := make([]error, 0, len(request.Imp))
reqJSON, err := json.Marshal(request)
if err != nil {
errs = append(errs, err)
return nil, errs
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
headers.Add("x-integration-type", PREBID_INTEGRATION_TYPE)
return []*adapters.RequestData{{
Method: "POST",
Uri: a.bidderEndpoint,
Body: reqJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}}, errs
}

func getPublisherId(impressions []openrtb2.Imp) (string, error) {
for _, imp := range impressions {

var bidderExt ExtImpBidderRoundhouseads
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return "", err
}

var roundhouseadsExt openrtb_ext.ExtImpRoundhouseads
if err := json.Unmarshal(bidderExt.Bidder, &roundhouseadsExt); err != nil {
return "", err
}

if roundhouseadsExt.PublisherId != "" {
return roundhouseadsExt.PublisherId, nil
}
}
return "", nil
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(response) {
return adapters.NewBidderResponse(), nil
}

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

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

bidderResponse := adapters.NewBidderResponse()
bidderResponse.Currency = bidResponse.Cur

for _, seatBid := range bidResponse.SeatBid {
for _, bid := range seatBid.Bid {
bid := bid

bidType, err := getBidType(bid.MType)

if err != nil {
return nil, []error{err}
}

b := &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
}
bidderResponse.Bids = append(bidderResponse.Bids, b)
}
}

return bidderResponse, nil
}

func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) {
switch markupType {
juliansalinas121 marked this conversation as resolved.
Show resolved Hide resolved
juliansalinas121 marked this conversation as resolved.
Show resolved Hide resolved
juliansalinas121 marked this conversation as resolved.
Show resolved Hide resolved
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
default:
return "", fmt.Errorf("unsupported mtype: %d", markupType)
}
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
template, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}

if len(config.ExtraAdapterInfo) > 0 {
isValidEndpoint, err := regexp.Match("([a-z]+)$", []byte(config.ExtraAdapterInfo))
if !isValidEndpoint || err != nil {
return nil, errors.New("ExtraAdapterInfo must be a simple string provided by Roundhouseads")
}
}

urlParams := macros.EndpointTemplateParams{SupplyId: config.ExtraAdapterInfo}
bidderEndpoint, err := macros.ResolveMacros(template, urlParams)

if err != nil {
return nil, fmt.Errorf("unable to resolve endpoint macros: %v", err)
}

return &adapter{
bidderEndpoint: bidderEndpoint,
}, nil
}
Loading
Loading