Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
prebid#615 Beachfront URLs from config (prebid#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdesput authored Apr 15, 2020
1 parent d1cda80 commit 2e43b84
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 45 deletions.
80 changes: 51 additions & 29 deletions adapters/beachfront/beachfront.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,40 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
"net/http"
"reflect"
"strconv"
"strings"

"github.com/golang/glog"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

const Seat = "beachfront"
const BidCapacity = 5

const bannerEndpoint = "https://display.bfmio.com/prebid_display"
const videoEndpoint = "https://reachms.bfmio.com/bid.json?exchange_id"
const defaultVideoEndpoint = "https://reachms.bfmio.com/bid.json?exchange_id"

const nurlVideoEndpointSuffix = "&prebidserver"

const beachfrontAdapterName = "BF_PREBID_S2S"
const beachfrontAdapterVersion = "0.8.0"
const beachfrontAdapterVersion = "0.9.0"

const minBidFloor = 0.01

const DefaultVideoWidth = 300
const DefaultVideoHeight = 250

type BeachfrontAdapter struct {
bannerEndpoint string
extraInfo ExtraInfo
}

type ExtraInfo struct {
VideoEndpoint string `json:"video_endpoint,omitempty"`
}

type beachfrontRequests struct {
Expand Down Expand Up @@ -138,7 +145,7 @@ func (a *BeachfrontAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *a
if err == nil {
reqs[0] = &adapters.RequestData{
Method: "POST",
Uri: bannerEndpoint,
Uri: a.bannerEndpoint,
Body: bytes,
Headers: headers,
}
Expand All @@ -159,7 +166,7 @@ func (a *BeachfrontAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *a
if err == nil {
reqs[j+nurlBump] = &adapters.RequestData{
Method: "POST",
Uri: videoEndpoint + "=" + beachfrontRequests.ADMVideo[j].AppId,
Uri: a.extraInfo.VideoEndpoint + "=" + beachfrontRequests.ADMVideo[j].AppId,
Body: bytes,
Headers: headers,
}
Expand All @@ -178,7 +185,7 @@ func (a *BeachfrontAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *a
bytes = append([]byte(`{"isPrebid":true,`), bytes[1:]...)
reqs[j+admBump] = &adapters.RequestData{
Method: "POST",
Uri: videoEndpoint + "=" + beachfrontRequests.NurlVideo[j].AppId + nurlVideoEndpointSuffix,
Uri: a.extraInfo.VideoEndpoint + "=" + beachfrontRequests.NurlVideo[j].AppId + nurlVideoEndpointSuffix,
Body: bytes,
Headers: headers,
}
Expand Down Expand Up @@ -518,20 +525,29 @@ func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bids[i],
BidType: getBidType(externalRequest),
BidType: a.getBidType(externalRequest),
BidVideo: &impVideo,
})
} else {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bids[i],
BidType: getBidType(externalRequest),
BidType: a.getBidType(externalRequest),
})
}
}

return bidResponse, errs
}

func (a *BeachfrontAdapter) getBidType(externalRequest *adapters.RequestData) openrtb_ext.BidType {
t := strings.Split(externalRequest.Uri, "=")[0]
if t == a.extraInfo.VideoEndpoint {
return openrtb_ext.BidTypeVideo
}

return openrtb_ext.BidTypeBanner
}

func postprocess(response *adapters.ResponseData, xtrnal openrtb.BidRequest, uri string, id string) ([]openrtb.Bid, []error) {
var beachfrontResp []beachfrontResponseSlot
var errs = make([]error, 0)
Expand Down Expand Up @@ -629,23 +645,23 @@ func getBeachfrontExtension(imp openrtb.Imp) (openrtb_ext.ExtImpBeachfront, erro
}

func getDomain(page string) string {
protoUrl := strings.Split(page, "//")
protoURL := strings.Split(page, "//")
var domainPage string

if len(protoUrl) > 1 {
domainPage = protoUrl[1]
if len(protoURL) > 1 {
domainPage = protoURL[1]
} else {
domainPage = protoUrl[0]
domainPage = protoURL[0]
}

return strings.Split(domainPage, "/")[0]

}

func isSecure(page string) int8 {
protoUrl := strings.Split(page, "://")
protoURL := strings.Split(page, "://")

if len(protoUrl) > 1 && protoUrl[0] == "https" {
if len(protoURL) > 1 && protoURL[0] == "https" {
return 1
}

Expand All @@ -663,19 +679,25 @@ func getIP(ip string) string {
return ip
}

func getBidType(externalRequest *adapters.RequestData) openrtb_ext.BidType {
t := strings.Split(externalRequest.Uri, "=")[0]
if t == videoEndpoint {
return openrtb_ext.BidTypeVideo
}

return openrtb_ext.BidTypeBanner
}

func removeVideoElement(slice []beachfrontVideoRequest, s int) []beachfrontVideoRequest {
return append(slice[:s], slice[s+1:]...)
}

func NewBeachfrontBidder() *BeachfrontAdapter {
return &BeachfrontAdapter{}
func NewBeachfrontBidder(bannerEndpoint string, extraAdapterInfo string) adapters.Bidder {
var extraInfo ExtraInfo

if len(extraAdapterInfo) == 0 {
extraAdapterInfo = "{\"video_endpoint\":\"" + defaultVideoEndpoint + "\"}"
}

if err := json.Unmarshal([]byte(extraAdapterInfo), &extraInfo); err != nil {
glog.Fatal("Invalid Beachfront extra adapter info: " + err.Error())
return nil
}

if extraInfo.VideoEndpoint == "" {
extraInfo.VideoEndpoint = defaultVideoEndpoint
}

return &BeachfrontAdapter{bannerEndpoint: bannerEndpoint, extraInfo: extraInfo}
}
2 changes: 1 addition & 1 deletion adapters/beachfront/beachfront_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "beachfronttest", new(BeachfrontAdapter))
adapterstest.RunJSONBidderTest(t, "beachfronttest", NewBeachfrontBidder("https://display.bfmio.com/prebid_display", "{\"video_endpoint\":\"https://reachms.bfmio.com/bid.json?exchange_id\"}"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dnt": 0,
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.8.0",
"adapterVersion": "0.9.0",
"user": {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"buyeruid": "some-buyer"
},
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.8.0",
"adapterVersion": "0.9.0",
"ip": "192.168.255.255",
"requestId": "61b87329-8790-47b7-90dd-c53ae7ce1723"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dnt": 0,
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.8.0",
"adapterVersion": "0.9.0",
"user": {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dnt": 0,
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.8.0",
"adapterVersion": "0.9.0",
"user": {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

},
"adapterName":"BF_PREBID_S2S",
"adapterVersion":"0.8.0",
"adapterVersion":"0.9.0",
"ip":"192.168.255.255",
"requestId":"763e3312-19d5-4b07-a61d-890147e863a1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"dnt": 1,
"ua": "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.8.0",
"adapterVersion": "0.9.0",
"user": {
"buyeruid": "some-buyer",
"id": "some-user"
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs
v.SetDefault("adapters.appnexus.platform_id", "5")
v.SetDefault("adapters.beachfront.endpoint", "https://display.bfmio.com/prebid_display")
v.SetDefault("adapters.beachfront.extra_info", "{\"video_endpoint\":\"https://reachms.bfmio.com/bid.json?exchange_id\"}")
v.SetDefault("adapters.brightroll.endpoint", "http://east-bid.ybp.yahoo.com/bid/appnexuspbs")
v.SetDefault("adapters.consumable.endpoint", "https://e.serverbid.com/api/v2")
v.SetDefault("adapters.conversant.endpoint", "http://api.hb.ad.cpe.dotomi.com/s2s/header/24")
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func TestFullConfig(t *testing.T) {
cmpStrings(t, "adapters.audiencenetwork.usersync_url", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderFacebook))].UserSyncURL, "http://facebook.com/ortb/prebid-s2s")
cmpStrings(t, "adapters.audiencenetwork.platform_id", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderFacebook))].PlatformID, "abcdefgh1234")
cmpStrings(t, "adapters.audiencenetwork.app_secret", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderFacebook))].AppSecret, "987abc")
cmpStrings(t, "adapters.beachfront.endpoint", cfg.Adapters[string(openrtb_ext.BidderBeachfront)].Endpoint, "https://display.bfmio.com/prebid_display")
cmpStrings(t, "adapters.beachfront.extra_info", cfg.Adapters[string(openrtb_ext.BidderBeachfront)].ExtraAdapterInfo, "{\"video_endpoint\":\"https://reachms.bfmio.com/bid.json?exchange_id\"}")
cmpStrings(t, "adapters.ix.endpoint", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderIx))].Endpoint, "http://ixtest.com/api")
cmpStrings(t, "adapters.rubicon.endpoint", cfg.Adapters[string(openrtb_ext.BidderRubicon)].Endpoint, "http://rubitest.com/api")
cmpStrings(t, "adapters.rubicon.usersync_url", cfg.Adapters[string(openrtb_ext.BidderRubicon)].UserSyncURL, "http://pixel.rubiconproject.com/sync.php?p=prebid")
Expand Down
17 changes: 8 additions & 9 deletions exchange/adapter_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ func newAdapterMap(client *http.Client, cfg *config.Configuration, infos adapter
openrtb_ext.BidderAdvangelists: advangelists.NewAdvangelistsBidder(cfg.Adapters[string(openrtb_ext.BidderAdvangelists)].Endpoint),
openrtb_ext.BidderApplogy: applogy.NewApplogyBidder(cfg.Adapters[string(openrtb_ext.BidderApplogy)].Endpoint),
openrtb_ext.BidderAppnexus: appnexus.NewAppNexusBidder(client, cfg.Adapters[string(openrtb_ext.BidderAppnexus)].Endpoint, cfg.Adapters[string(openrtb_ext.BidderAppnexus)].PlatformID),
// TODO #615: Update the config setup so that the Beachfront URLs can be configured, and use those in TestRaceIntegration in exchange_test.go
openrtb_ext.BidderBeachfront: beachfront.NewBeachfrontBidder(),
openrtb_ext.BidderBrightroll: brightroll.NewBrightrollBidder(cfg.Adapters[string(openrtb_ext.BidderBrightroll)].Endpoint),
openrtb_ext.BidderConsumable: consumable.NewConsumableBidder(cfg.Adapters[string(openrtb_ext.BidderConsumable)].Endpoint),
openrtb_ext.BidderCpmstar: cpmstar.NewCpmstarBidder(cfg.Adapters[string(openrtb_ext.BidderCpmstar)].Endpoint),
openrtb_ext.BidderDatablocks: datablocks.NewDatablocksBidder(cfg.Adapters[string(openrtb_ext.BidderDatablocks)].Endpoint),
openrtb_ext.BidderEmxDigital: emx_digital.NewEmxDigitalBidder(cfg.Adapters[string(openrtb_ext.BidderEmxDigital)].Endpoint),
openrtb_ext.BidderEngageBDR: engagebdr.NewEngageBDRBidder(client, cfg.Adapters[string(openrtb_ext.BidderEngageBDR)].Endpoint),
openrtb_ext.BidderEPlanning: eplanning.NewEPlanningBidder(client, cfg.Adapters[string(openrtb_ext.BidderEPlanning)].Endpoint),
openrtb_ext.BidderBeachfront: beachfront.NewBeachfrontBidder(cfg.Adapters[string(openrtb_ext.BidderBeachfront)].Endpoint, cfg.Adapters[string(openrtb_ext.BidderBeachfront)].ExtraAdapterInfo),
openrtb_ext.BidderBrightroll: brightroll.NewBrightrollBidder(cfg.Adapters[string(openrtb_ext.BidderBrightroll)].Endpoint),
openrtb_ext.BidderConsumable: consumable.NewConsumableBidder(cfg.Adapters[string(openrtb_ext.BidderConsumable)].Endpoint),
openrtb_ext.BidderCpmstar: cpmstar.NewCpmstarBidder(cfg.Adapters[string(openrtb_ext.BidderCpmstar)].Endpoint),
openrtb_ext.BidderDatablocks: datablocks.NewDatablocksBidder(cfg.Adapters[string(openrtb_ext.BidderDatablocks)].Endpoint),
openrtb_ext.BidderEmxDigital: emx_digital.NewEmxDigitalBidder(cfg.Adapters[string(openrtb_ext.BidderEmxDigital)].Endpoint),
openrtb_ext.BidderEngageBDR: engagebdr.NewEngageBDRBidder(client, cfg.Adapters[string(openrtb_ext.BidderEngageBDR)].Endpoint),
openrtb_ext.BidderEPlanning: eplanning.NewEPlanningBidder(client, cfg.Adapters[string(openrtb_ext.BidderEPlanning)].Endpoint),
openrtb_ext.BidderFacebook: audienceNetwork.NewFacebookBidder(
client,
cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderFacebook))].PlatformID,
Expand Down
5 changes: 5 additions & 0 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ func TestRaceIntegration(t *testing.T) {
Endpoint: server.URL,
PlatformID: "abc",
}
cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderBeachfront))] = config.Adapter{
Endpoint: server.URL,
ExtraAdapterInfo: "{\"video_endpoint\":\"" + server.URL + "\"}",
}

categoriesFetcher, error := newCategoryFetcher("./test/category-mapping")
if error != nil {
t.Errorf("Failed to create a category Fetcher: %v", error)
Expand Down

0 comments on commit 2e43b84

Please sign in to comment.