Skip to content

Commit d00ff3f

Browse files
mirkoreanaklinkert
andauthored
Add Yieldlab Adapter (#1287)
Co-authored-by: Mirko Feddern <[email protected]> Signed-off-by: Alex Klinkert <[email protected]> Co-authored-by: Alexander Pinnecke <[email protected]> Co-authored-by: Alex Klinkert <[email protected]> Co-authored-by: Mirko Feddern <[email protected]>
1 parent 748e2d0 commit d00ff3f

File tree

22 files changed

+1147
-68
lines changed

22 files changed

+1147
-68
lines changed

adapters/adapterstest/test_json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func diffErrorLists(t *testing.T, description string, actual []error, expected [
208208
t.Helper()
209209

210210
if len(expected) != len(actual) {
211-
t.Fatalf("%s had wrong error count. Expected %d, got %d", description, len(expected), len(actual))
211+
t.Fatalf("%s had wrong error count. Expected %d, got %d (%v)", description, len(expected), len(actual), actual)
212212
}
213213
for i := 0; i < len(actual); i++ {
214214
if expected[i].Comparison == "literal" {

adapters/yieldlab/const.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package yieldlab
2+
3+
const adSlotIdSeparator = ","
4+
const adsizeSeparator = "x"
5+
const adSourceBanner = "<script src=\"%v\"></script>"
6+
const adSourceURL = "https://ad.yieldlab.net/d/%v/%v/%v?%v"
7+
const creativeID = "%v%v%v"

adapters/yieldlab/params_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package yieldlab
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/prebid/prebid-server/openrtb_ext"
8+
)
9+
10+
// This file actually intends to test static/bidder-params/yieldlab.json
11+
//
12+
// These also validate the format of the external API: request.imp[i].ext.yieldlab
13+
14+
// TestValidParams makes sure that the yieldlab schema accepts all imp.ext fields which we intend to support.
15+
func TestValidParams(t *testing.T) {
16+
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
17+
if err != nil {
18+
t.Fatalf("Failed to fetch the json-schemas. %v", err)
19+
}
20+
21+
for _, validParam := range validParams {
22+
if err := validator.Validate(openrtb_ext.BidderYieldlab, json.RawMessage(validParam)); err != nil {
23+
t.Errorf("Schema rejected yieldlab params: %s", validParam)
24+
}
25+
}
26+
}
27+
28+
// TestInvalidParams makes sure that the yieldlab schema rejects all the imp.ext fields we don't support.
29+
func TestInvalidParams(t *testing.T) {
30+
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
31+
if err != nil {
32+
t.Fatalf("Failed to fetch the json-schemas. %v", err)
33+
}
34+
35+
for _, invalidParam := range invalidParams {
36+
if err := validator.Validate(openrtb_ext.BidderYieldlab, json.RawMessage(invalidParam)); err == nil {
37+
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
38+
}
39+
}
40+
}
41+
42+
var validParams = []string{
43+
`{"adslotId": "123","supplyId":"23456","adSize":"100x100"}`,
44+
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","extId":"asdf"}`,
45+
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","extId":"asdf","targeting":{"a":"b"}}`,
46+
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","targeting":{"a":"b"}}`,
47+
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","targeting":{"a":"b"}}`,
48+
}
49+
50+
var invalidParams = []string{
51+
`{"supplyId":"23456","adSize":"100x100"}`,
52+
`{"adslotId": "123","adSize":"100x100","extId":"asdf"}`,
53+
`{"adslotId": "123","supplyId":"23456","extId":"asdf","targeting":{"a":"b"}}`,
54+
`{"adslotId": "123","supplyId":"23456"}`,
55+
`{"adSize":"100x100","supplyId":"23456"}`,
56+
`{"adslotId": "123","adSize":"100x100"}`,
57+
`{"supplyId":"23456"}`,
58+
`{"adslotId": "123"}`,
59+
`{}`,
60+
`[]`,
61+
`{"a":"b"}`,
62+
`null`,
63+
}

adapters/yieldlab/types.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package yieldlab
2+
3+
import (
4+
"strconv"
5+
"time"
6+
)
7+
8+
type bidResponse struct {
9+
ID uint64 `json:"id"`
10+
Price uint `json:"price"`
11+
Advertiser string `json:"advertiser"`
12+
Adsize string `json:"adsize"`
13+
Pid uint64 `json:"pid"`
14+
Did uint64 `json:"did"`
15+
Pvid string `json:"pvid"`
16+
}
17+
18+
type cacheBuster func() string
19+
20+
type weekGenerator func() string
21+
22+
var defaultCacheBuster cacheBuster = func() string {
23+
return strconv.FormatInt(time.Now().Unix(), 10)
24+
}
25+
26+
var defaultWeekGenerator weekGenerator = func() string {
27+
_, week := time.Now().ISOWeek()
28+
return strconv.Itoa(week)
29+
}

adapters/yieldlab/usersync.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package yieldlab
2+
3+
import (
4+
"text/template"
5+
6+
"github.com/prebid/prebid-server/adapters"
7+
"github.com/prebid/prebid-server/usersync"
8+
)
9+
10+
func NewYieldlabSyncer(temp *template.Template) usersync.Usersyncer {
11+
return adapters.NewSyncer("yieldlab", 70, temp, adapters.SyncTypeRedirect)
12+
}

adapters/yieldlab/usersync_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package yieldlab
2+
3+
import (
4+
"testing"
5+
"text/template"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/prebid/prebid-server/privacy"
10+
"github.com/prebid/prebid-server/privacy/gdpr"
11+
)
12+
13+
func TestYieldlabSyncer(t *testing.T) {
14+
temp := template.Must(template.New("sync-template").Parse("https://ad.yieldlab.net/mr?t=2&pid=9140838&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&redirectUri=http%3A%2F%2Flocalhost%2F%2Fsetuid%3Fbidder%3Dyieldlab%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%25%25YL_UID%25%25"))
15+
syncer := NewYieldlabSyncer(temp)
16+
syncInfo, err := syncer.GetUsersyncInfo(privacy.Policies{
17+
GDPR: gdpr.Policy{
18+
Signal: "0",
19+
},
20+
})
21+
assert.NoError(t, err)
22+
assert.Equal(t, "https://ad.yieldlab.net/mr?t=2&pid=9140838&gdpr=0&gdpr_consent=&redirectUri=http%3A%2F%2Flocalhost%2F%2Fsetuid%3Fbidder%3Dyieldlab%26gdpr%3D0%26gdpr_consent%3D%26uid%3D%25%25YL_UID%25%25", syncInfo.URL)
23+
assert.Equal(t, "redirect", syncInfo.Type)
24+
assert.EqualValues(t, 70, syncer.GDPRVendorID())
25+
assert.False(t, syncInfo.SupportCORS)
26+
}

0 commit comments

Comments
 (0)