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 Initialization Framework #1532

Merged
merged 58 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4446969
Added Builder Framework + AppNexus Conversion
SyntaxNode Sep 9, 2020
d800c51
Converted 33Across + Adform
SyntaxNode Sep 10, 2020
6de2932
Converted Adgeneration, Adhese, + Adkernel
SyntaxNode Sep 10, 2020
7404c7e
Converted Adkernel, Adman, Adnixer, + AdOcean
SyntaxNode Sep 10, 2020
912ab70
Converted Adoppler, Adpone, Adprime, + Adtarget
SyntaxNode Sep 10, 2020
4abec5c
Converted Adtelligent + Advangelists
SyntaxNode Sep 10, 2020
7f19f1b
Converted AJA, Applogy, + Facebook
SyntaxNode Sep 10, 2020
36a44b4
Adapter Map Update
SyntaxNode Sep 11, 2020
38d0649
Converted Avocet, Beachfront, + Beintoo
SyntaxNode Sep 14, 2020
abe64ba
Converted Brightroll + Retro Update
SyntaxNode Sep 14, 2020
c8d95af
Update Adapter Map Count
SyntaxNode Sep 14, 2020
17d5b64
Converted Consumable, Cpmstar, Datablocks, + DMX
SyntaxNode Sep 14, 2020
7b7aadb
Converted EMXDigital, EngageBDR, EPlanning, Gamma
SyntaxNode Sep 14, 2020
a722110
Refactor Adapter Creation
SyntaxNode Sep 14, 2020
db72af2
Converted Gamoshi, Grid, + GumGum
SyntaxNode Sep 15, 2020
2bf69c9
Converted ImproveDigital, Kidoz, + Kubient
SyntaxNode Sep 15, 2020
399eb1a
Converted LockerDome, LogicAd, + LunaMedia
SyntaxNode Sep 15, 2020
87eb69e
Converted Marmedia + Mgid
SyntaxNode Sep 15, 2020
316e99f
Converted Rubicon
SyntaxNode Sep 15, 2020
f257777
Converted Sharethrough, Smaato, SmartAd + SmartRTB
SyntaxNode Sep 15, 2020
2930126
Converted MobileFuse, Nano, + NinthDecimal
SyntaxNode Sep 15, 2020
73f0133
Converted OpenX, Orbidder, Sharethrough + Pubmatic
SyntaxNode Sep 15, 2020
3ea0256
Converted Pubnative, Rythmone + RTBHouse
SyntaxNode Sep 15, 2020
0b586ad
Converted Somo + Sonobi
SyntaxNode Sep 15, 2020
a2c1ff2
Converted Sovrn + Synacor
SyntaxNode Sep 15, 2020
ee623d9
Converted Tappx + Telaria
SyntaxNode Sep 15, 2020
9c0511f
Converted Triplelift
SyntaxNode Sep 15, 2020
06fe65e
Converted Ucfunnel, Unruly, + ValueImpression
SyntaxNode Sep 15, 2020
ebff93c
Converted VerizonMedia, Visx, + Vrtcal
SyntaxNode Sep 15, 2020
a062330
Adapter Typos + Error Message Unification
SyntaxNode Sep 16, 2020
f696ea6
Converted Remaining Adapters
SyntaxNode Sep 16, 2020
67ee1d8
Merge branch 'master' into alias_adapter_creation
SyntaxNode Sep 28, 2020
cce48fa
Missing Files From Last Merge
SyntaxNode Sep 28, 2020
309056a
Exchange Err Rollup
SyntaxNode Sep 28, 2020
a60a5fa
Compiling + First Tests
SyntaxNode Sep 28, 2020
2d63341
Back To Building
SyntaxNode Oct 8, 2020
1bf72e5
Missed Non-Staged Files
SyntaxNode Oct 8, 2020
7080140
Builder Tests
SyntaxNode Oct 10, 2020
906735e
Fixed Tests
SyntaxNode Oct 10, 2020
e30f25d
Merge branch 'master' into alias_adapter_creation
SyntaxNode Oct 10, 2020
29c5bd3
Converted Krushmedia + SmartyAds
SyntaxNode Oct 10, 2020
f68b5aa
Misc + Error Handling Update
SyntaxNode Oct 10, 2020
87de5c7
More Resilient Tests
SyntaxNode Oct 10, 2020
68a2bf3
Merge branch 'master' into alias_adapter_creation
SyntaxNode Oct 12, 2020
c67d066
Merge branch 'master' into alias_adapter_creation
SyntaxNode Oct 13, 2020
9b9b783
Consistent Legacy Adapter Names
SyntaxNode Oct 13, 2020
c29d7c6
Code Review Feedback
SyntaxNode Oct 14, 2020
813d4e5
Merge branch 'master' into alias_adapter_creation
SyntaxNode Oct 16, 2020
eec5a53
Resolve Merge Conflict
SyntaxNode Oct 16, 2020
9351102
Merge branch 'master' into alias_adapter_creation
SyntaxNode Oct 19, 2020
9b9ad6b
Fix Typo
SyntaxNode Oct 19, 2020
ffd3bf8
Removed IndexExchange Rename Notice
SyntaxNode Oct 20, 2020
76f0e7f
Merge branch 'master' into alias_adapter_creation
SyntaxNode Nov 19, 2020
ce2d36a
Mix Merge Error
SyntaxNode Nov 19, 2020
f201323
Remove MisconfiguredBidder
SyntaxNode Nov 19, 2020
f66884b
Add Meta Ext Structure
SyntaxNode Nov 19, 2020
30abf47
Fix 33Across Merge Error
SyntaxNode Nov 19, 2020
e354bd2
Fix Conversant Test Typo
SyntaxNode Nov 20, 2020
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
10 changes: 6 additions & 4 deletions adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)
Expand Down Expand Up @@ -219,9 +220,10 @@ func getBidType(ext bidExt) openrtb_ext.BidType {
return openrtb_ext.BidTypeBanner
}

// New33AcrossBidder configures bidder endpoint
func New33AcrossBidder(endpoint string) *TtxAdapter {
return &TtxAdapter{
endpoint: endpoint,
// Builder builds a new instance of the 33Across adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
bidder := &TtxAdapter{
endpoint: config.Endpoint,
}
return bidder, nil
}
11 changes: 10 additions & 1 deletion adapters/33across/33across_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ 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) {
adapterstest.RunJSONBidderTest(t, "33acrosstest", New33AcrossBidder("http://ssc.33across.com"))
bidder, buildErr := Builder(openrtb_ext.Bidder33Across, config.Adapter{
Endpoint: "http://ssc.33across.com"})

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

adapterstest.RunJSONBidderTest(t, "33acrosstest", bidder)
}
16 changes: 10 additions & 6 deletions adapters/acuityads/acuityads.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http"
"text/template"

"github.com/golang/glog"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
Expand All @@ -18,13 +18,17 @@ type AcuityAdsAdapter struct {
endpoint template.Template
}

func NewAcuityAdsBidder(endpointTemplate string) *AcuityAdsAdapter {
template, err := template.New("endpointTemplate").Parse(endpointTemplate)
// Builder builds a new instance of the AcuityAds adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
template, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
glog.Fatal("Unable to parse endpoint url template")
return nil
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}

bidder := &AcuityAdsAdapter{
endpoint: *template,
}
return &AcuityAdsAdapter{endpoint: *template}
return bidder, nil
}

func getHeaders(request *openrtb.BidRequest) http.Header {
Expand Down
19 changes: 18 additions & 1 deletion adapters/acuityads/acuityads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ import (
"testing"

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

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "acuityadstest", NewAcuityAdsBidder("http://{{.Host}}.example.com/bid?token={{.AccountID}}"))
bidder, buildErr := Builder(openrtb_ext.BidderAcuityAds, config.Adapter{
Endpoint: "http://{{.Host}}.example.com/bid?token={{.AccountID}}"})

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

adapterstest.RunJSONBidderTest(t, "acuityadstest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAcuityAds, config.Adapter{
Endpoint: "{{Malformed}}"})

assert.Error(t, buildErr)
}
25 changes: 19 additions & 6 deletions adapters/adform/adform.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -13,6 +14,7 @@ import (
"strings"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbs"
Expand All @@ -22,6 +24,8 @@ import (
"golang.org/x/net/context/ctxhttp"
)

const version = "0.1.3"

type AdformAdapter struct {
http *adapters.HTTPAdapter
URL *url.URL
Expand Down Expand Up @@ -95,8 +99,18 @@ func isPriceTypeValid(priceType string) (string, bool) {

// ADAPTER Interface

func NewAdformAdapter(config *adapters.HTTPAdapterConfig, endpointURL string) *AdformAdapter {
return NewAdformBidder(adapters.NewHTTPAdapter(config).Client, endpointURL)
// Builder builds a new instance of the Adform adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
uri, err := url.Parse(config.Endpoint)
if err != nil {
return nil, errors.New("unable to parse endpoint")
}

bidder := &AdformAdapter{
URL: uri,
version: version,
}
return bidder, nil
}

// used for cookies and such
Expand Down Expand Up @@ -386,18 +400,17 @@ func parseAdformBids(response []byte) ([]*adformBid, error) {

// BIDDER Interface

func NewAdformBidder(client *http.Client, endpointURL string) *AdformAdapter {
a := &adapters.HTTPAdapter{Client: client}
func NewAdformLegacyAdapter(httpConfig *adapters.HTTPAdapterConfig, endpointURL string) *AdformAdapter {
var uriObj *url.URL
uriObj, err := url.Parse(endpointURL)
if err != nil {
panic(fmt.Sprintf("Incorrect Adform request url %s, check the configuration, please.", endpointURL))
}

return &AdformAdapter{
http: a,
http: adapters.NewHTTPAdapter(httpConfig),
URL: uriObj,
version: "0.1.3",
version: version,
}
}

Expand Down
27 changes: 23 additions & 4 deletions adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ import (
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "adformtest", NewAdformBidder(nil, "http://adx.adform.net/adx"))
bidder, buildErr := Builder(openrtb_ext.BidderAdform, config.Adapter{
Endpoint: "http://adx.adform.net/adx"})

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

adapterstest.RunJSONBidderTest(t, "adformtest", bidder)
}

func TestEndpointMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAdform, config.Adapter{
Endpoint: ` https://malformed`})

assert.Error(t, buildErr)
}

type aTagInfo struct {
Expand Down Expand Up @@ -193,7 +207,7 @@ func initTestData(server *httptest.Server, t *testing.T) (*AdformAdapter, contex

// prepare adapter
conf := *adapters.DefaultHTTPAdapterConfig
adapter := NewAdformAdapter(&conf, server.URL)
adapter := NewAdformLegacyAdapter(&conf, server.URL)

prebidRequest := preparePrebidRequest(server.URL, t)
ctx := context.TODO()
Expand Down Expand Up @@ -285,7 +299,12 @@ func preparePrebidRequestBody(requestData aBidInfo, t *testing.T) *bytes.Buffer
// OpenRTB auction tests

func TestOpenRTBRequest(t *testing.T) {
bidder := NewAdformBidder(nil, "http://adx.adform.net")
bidder, buildErr := Builder(openrtb_ext.BidderAdform, config.Adapter{
Endpoint: "http://adx.adform.net"})

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

testData := createTestData(true)
request := createOpenRtbRequest(&testData)
Expand Down Expand Up @@ -483,7 +502,7 @@ func TestOpenRTBSurpriseResponse(t *testing.T) {
// Properties tests

func TestAdformProperties(t *testing.T) {
adapter := NewAdformAdapter(adapters.DefaultHTTPAdapterConfig, "adx.adform.net/adx")
adapter := NewAdformLegacyAdapter(adapters.DefaultHTTPAdapterConfig, "adx.adform.net/adx")

if adapter.SkipNoCookies() != false {
t.Fatalf("should have been false")
Expand Down
9 changes: 6 additions & 3 deletions adapters/adgeneration/adgeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)
Expand Down Expand Up @@ -258,10 +259,12 @@ func removeWrapper(ad string) string {
return str
}

func NewAdgenerationAdapter(endpoint string) *AdgenerationAdapter {
return &AdgenerationAdapter{
endpoint,
// Builder builds a new instance of the Adgeneration adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
bidder := &AdgenerationAdapter{
config.Endpoint,
"1.0.2",
"JPY",
}
return bidder, nil
}
61 changes: 47 additions & 14 deletions adapters/adgeneration/adgeneration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,32 @@ import (
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "adgenerationtest", NewAdgenerationAdapter("https://d.socdm.com/adsv/v1"))
bidder, buildErr := Builder(openrtb_ext.BidderAdgeneration, config.Adapter{
Endpoint: "https://d.socdm.com/adsv/v1"})

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

adapterstest.RunJSONBidderTest(t, "adgenerationtest", bidder)
}

func TestGetRequestUri(t *testing.T) {
bidder := NewAdgenerationAdapter("https://d.socdm.com/adsv/v1")
func TestgetRequestUri(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAdgeneration, config.Adapter{
Endpoint: "https://d.socdm.com/adsv/v1"})

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

bidderAdgeneration, _ := bidder.(*AdgenerationAdapter)

// Test items
failedRequest := &openrtb.BidRequest{
ID: "test-failed-bid-request",
Expand All @@ -42,7 +59,7 @@ func TestGetRequestUri(t *testing.T) {

numRequests := len(failedRequest.Imp)
for index := 0; index < numRequests; index++ {
httpRequests, err := bidder.getRequestUri(failedRequest, index)
httpRequests, err := bidderAdgeneration.getRequestUri(failedRequest, index)
if err == nil {
t.Errorf("getRequestUri: %v did not throw an error", failedRequest.Imp[index])
}
Expand All @@ -57,15 +74,15 @@ func TestGetRequestUri(t *testing.T) {
if err != nil {
t.Errorf("unmarshalExtImpAdgeneration: %v did throw an error: %v", successRequest.Imp[index], err)
}
rawQuery := bidder.getRawQuery(adgExt.Id, successRequest, &successRequest.Imp[index])
rawQuery := bidderAdgeneration.getRawQuery(adgExt.Id, successRequest, &successRequest.Imp[index])
expectQueries := map[string]string{
"posall": "SSPLOC",
"id": adgExt.Id,
"sdktype": "0",
"hb": "true",
"currency": bidder.getCurrency(successRequest),
"currency": bidderAdgeneration.getCurrency(successRequest),
"sdkname": "prebidserver",
"adapterver": bidder.version,
"adapterver": bidderAdgeneration.version,
"sizes": getSizes(&successRequest.Imp[index]),
"tp": successRequest.Site.Page,
"transactionid": successRequest.Source.TID,
Expand All @@ -78,11 +95,11 @@ func TestGetRequestUri(t *testing.T) {
}

// RequestUri Test.
actualUri, err := bidder.getRequestUri(successRequest, index)
actualUri, err := bidderAdgeneration.getRequestUri(successRequest, index)
if err != nil {
t.Errorf("getRequestUri: %v did throw an error: %v", successRequest.Imp[index], err)
}
expectedUri := "https://d.socdm.com/adsv/v1?adapterver=" + bidder.version + "&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=https%3A%2F%2Fsupership.com&transactionid=SourceTID"
expectedUri := "https://d.socdm.com/adsv/v1?adapterver=" + bidderAdgeneration.version + "&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=https%3A%2F%2Fsupership.com&transactionid=SourceTID"
if actualUri != expectedUri {
t.Errorf("getRequestUri: does not match expected %s, actual %s", expectedUri, actualUri)
}
Expand Down Expand Up @@ -115,20 +132,28 @@ func TestGetSizes(t *testing.T) {
}

func TestGetCurrency(t *testing.T) {
bidder := NewAdgenerationAdapter("https://d.socdm.com/adsv/v1")
bidder, buildErr := Builder(openrtb_ext.BidderAdgeneration, config.Adapter{
Endpoint: "https://d.socdm.com/adsv/v1"})

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

bidderAdgeneration, _ := bidder.(*AdgenerationAdapter)

// Test items
var request *openrtb.BidRequest
var currency string
innerDefaultCur := []string{"USD", "JPY"}
usdCur := []string{"USD", "EUR"}

request = &openrtb.BidRequest{Cur: innerDefaultCur}
currency = bidder.getCurrency(request)
currency = bidderAdgeneration.getCurrency(request)
if currency != "JPY" {
t.Errorf("%v does not match currency.", innerDefaultCur)
}
request = &openrtb.BidRequest{Cur: usdCur}
currency = bidder.getCurrency(request)
currency = bidderAdgeneration.getCurrency(request)
if currency != "USD" {
t.Errorf("%v does not match currency.", usdCur)
}
Expand Down Expand Up @@ -178,7 +203,15 @@ func TestCreateAd(t *testing.T) {
}

func TestMakeBids(t *testing.T) {
bidder := NewAdgenerationAdapter("https://d.socdm.com/adsv/v1")
bidder, buildErr := Builder(openrtb_ext.BidderAdgeneration, config.Adapter{
Endpoint: "https://d.socdm.com/adsv/v1"})

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

bidderAdgeneration, _ := bidder.(*AdgenerationAdapter)

internalRequest := &openrtb.BidRequest{
ID: "test-success-bid-request",
Imp: []openrtb.Imp{
Expand All @@ -198,7 +231,7 @@ func TestMakeBids(t *testing.T) {
if len(errs) > 0 {
t.Errorf("MakeBids return errors. errors: %v", errs)
}
checkBidResponse(t, defaultCurBidderResponse, bidder.defaultCurrency)
checkBidResponse(t, defaultCurBidderResponse, bidderAdgeneration.defaultCurrency)

// Specified Currency InternalRequest
usdCur := "USD"
Expand Down
Loading