Skip to content

Commit

Permalink
seedingAlliance: make suntContent alias, add finative alias and add s…
Browse files Browse the repository at this point in the history
…eatId bidder param in seedingAlliance (#3309)

co-authored by @sag-henmus
  • Loading branch information
sag-henmus authored Dec 7, 2023
1 parent 8128b24 commit 9644543
Show file tree
Hide file tree
Showing 28 changed files with 92 additions and 807 deletions.
4 changes: 4 additions & 0 deletions adapters/seedingAlliance/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ func TestInvalidParams(t *testing.T) {
var validParams = []string{
`{"adUnitId": "1234"}`,
`{"adUnitId": "AB12"}`,
`{"adUnitId": "1234", "seatId": "1234"}`,
`{"adUnitId": "AB12", "seatId": "AB12"}`,
}

var invalidParams = []string{
`{"adUnitId": 42}`,
`{"adUnitId": "1234", "seatId": 42}`,
`{"adUnitId": 1234, "seatId": "42"}`,
}
37 changes: 29 additions & 8 deletions adapters/seedingAlliance/seedingAlliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,38 @@ import (
"net/http"
"strconv"
"strings"
"text/template"

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

type adapter struct {
endpoint string
endpoint *template.Template
}

func Builder(_ 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)
}

bidder := &adapter{
endpoint: config.Endpoint,
endpoint: template,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, extraRequestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var seatId string
var err error

for i := range request.Imp {
if err := addTagID(&request.Imp[i]); err != nil {
if seatId, err = getExtInfo(&request.Imp[i]); err != nil {
return nil, []error{err}
}
}
Expand All @@ -41,9 +51,14 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, extraRequestInfo *a
return nil, []error{err}
}

url, err := macros.ResolveMacros(a.endpoint, macros.EndpointTemplateParams{AccountID: seatId})
if err != nil {
return nil, []error{err}
}

requestData := &adapters.RequestData{
Method: http.MethodPost,
Uri: a.endpoint,
Uri: url,
Body: requestJSON,
}

Expand Down Expand Up @@ -127,19 +142,25 @@ func curExists(allowedCurrencies []string, newCurrency string) bool {
return false
}

func addTagID(imp *openrtb2.Imp) error {
func getExtInfo(imp *openrtb2.Imp) (string, error) {
var ext adapters.ExtImpBidder
var extSA openrtb_ext.ImpExtSeedingAlliance

seatID := "pbs"

if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return fmt.Errorf("could not unmarshal adapters.ExtImpBidder: %w", err)
return "", fmt.Errorf("could not unmarshal adapters.ExtImpBidder: %w", err)
}

if err := json.Unmarshal(ext.Bidder, &extSA); err != nil {
return fmt.Errorf("could not unmarshal openrtb_ext.ImpExtSeedingAlliance: %w", err)
return "", fmt.Errorf("could not unmarshal openrtb_ext.ImpExtSeedingAlliance: %w", err)
}

imp.TagID = extSA.AdUnitID

return nil
if extSA.SeatID != "" {
seatID = extSA.SeatID
}

return seatID, nil
}
38 changes: 24 additions & 14 deletions adapters/seedingAlliance/seedingAlliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderSeedingAlliance, config.Adapter{
Endpoint: "https://mockup.seeding-alliance.de/",
Endpoint: "https://mockup.seeding-alliance.de/?ssp={{.AccountID}}",
}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand Down Expand Up @@ -134,20 +134,26 @@ func TestGetMediaTypeForBid(t *testing.T) {
}
}

func TestAddTagID(t *testing.T) {
func TestGetExtInfo(t *testing.T) {
type args struct {
adUnitId string
seatId string
}
tests := []struct {
name string
want string
data string
wantErr bool
name string
expectedAdUnitID string
expectedSeatID string
data args
wantErr bool
}{
{"regular case", "abc123", "abc123", false},
{"nil case", "", "", false},
{"unmarshal err case", "", "", true},
{"regular case", "abc123", "pbs", args{adUnitId: "abc123"}, false},
{"nil case", "", "pbs", args{adUnitId: ""}, false},
{"unmarshal err case", "", "pbs", args{adUnitId: ""}, true},
{"seatId case", "abc123", "seat1", args{adUnitId: "abc123", seatId: "seat1"}, false},
}

for _, test := range tests {
extSA, err := json.Marshal(openrtb_ext.ImpExtSeedingAlliance{AdUnitID: test.data})
extSA, err := json.Marshal(openrtb_ext.ImpExtSeedingAlliance{AdUnitID: test.data.adUnitId, SeatID: test.data.seatId})
if err != nil {
t.Fatalf("unexpected error %v", err)
}
Expand All @@ -162,16 +168,20 @@ func TestAddTagID(t *testing.T) {
}

ortbImp := openrtb2.Imp{Ext: extBidder}

if err := addTagID(&ortbImp); err != nil {
seatID, err := getExtInfo(&ortbImp)
if err != nil {
if test.wantErr {
continue
}
t.Fatalf("unexpected error %v", err)
}

if test.want != ortbImp.TagID {
t.Fatalf("want: %v, got: %v", test.want, ortbImp.TagID)
if test.expectedAdUnitID != ortbImp.TagID {
t.Fatalf("want: %v, got: %v", test.expectedAdUnitID, ortbImp.TagID)
}

if test.expectedSeatID != seatID {
t.Fatalf("want: %v, got: %v", test.expectedSeatID, seatID)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.seeding-alliance.de/",
"uri": "https://mockup.seeding-alliance.de/?ssp=pbs",
"body": {
"cur": [
"EUR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"ext": {
"bidder": {
"adUnitId": "example-tag-id"
"adUnitId": "example-tag-id",
"seatId": "123"
}
}
}
Expand All @@ -33,7 +34,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.suntcontent.com/",
"uri": "https://mockup.seeding-alliance.de/?ssp=123",
"body": {
"cur": [
"EUR"
Expand All @@ -57,7 +58,8 @@
"tagid": "example-tag-id",
"ext": {
"bidder": {
"adUnitId": "example-tag-id"
"adUnitId": "example-tag-id",
"seatId": "123"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.seeding-alliance.de/",
"uri": "https://mockup.seeding-alliance.de/?ssp=pbs",
"body": {
"cur": [
"EUR"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expectedMakeRequestsErrors": [
{
"value": "could not unmarshal openrtb_ext.ImpExtSeedingAlliance: json: cannot unmarshal number into Go struct field ImpExtSeedingAlliance.adUnitID of type string",
"value": "could not unmarshal openrtb_ext.ImpExtSeedingAlliance: json: cannot unmarshal number into Go struct field ImpExtSeedingAlliance.adUnitId of type string",
"comparison": "literal"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.seeding-alliance.de/",
"uri": "https://mockup.seeding-alliance.de/?ssp=pbs",
"body": {
"cur": [
"EUR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.seeding-alliance.de/",
"uri": "https://mockup.seeding-alliance.de/?ssp=pbs",
"body": {
"cur": [
"EUR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://mockup.seeding-alliance.de/",
"uri": "https://mockup.seeding-alliance.de/?ssp=pbs",
"body": {
"cur": [
"EUR"
Expand Down
43 changes: 0 additions & 43 deletions adapters/suntContent/params_test.go

This file was deleted.

Loading

0 comments on commit 9644543

Please sign in to comment.