Skip to content

Commit 4897506

Browse files
prebid-spgondsuryaprakash
and
gondsuryaprakash
authored
New Adapter: Silverpush (prebid#2957)
Co-authored-by: gondsuryaprakash <“[email protected]”>
1 parent 86a118c commit 4897506

35 files changed

+5516
-1
lines changed

adapters/silverpush/devicetype.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package silverpush
2+
3+
import (
4+
"regexp"
5+
"strings"
6+
7+
"github.com/prebid/openrtb/v19/openrtb2"
8+
)
9+
10+
var isValidMobile = regexp.MustCompile(`(ios|ipod|ipad|iphone|android)`)
11+
var isCtv = regexp.MustCompile(`(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)`)
12+
var isIos = regexp.MustCompile(`(iPhone|iPod|iPad)`)
13+
14+
func isMobile(ua string) bool {
15+
return isValidMobile.MatchString(strings.ToLower(ua))
16+
}
17+
18+
func isCTV(ua string) bool {
19+
return isCtv.MatchString(strings.ToLower(ua))
20+
}
21+
22+
// isValidEids checks for valid eids.
23+
func isValidEids(eids []openrtb2.EID) bool {
24+
for i := 0; i < len(eids); i++ {
25+
if len(eids[i].UIDs) > 0 && eids[i].UIDs[0].ID != "" {
26+
return true
27+
}
28+
}
29+
return false
30+
}
31+
32+
func getOS(ua string) string {
33+
if strings.Contains(ua, "Windows") {
34+
return "Windows"
35+
} else if isIos.MatchString(ua) {
36+
return "iOS"
37+
} else if strings.Contains(ua, "Mac OS X") {
38+
return "macOS"
39+
} else if strings.Contains(ua, "Android") {
40+
return "Android"
41+
} else if strings.Contains(ua, "Linux") {
42+
return "Linux"
43+
} else {
44+
return "Unknown"
45+
}
46+
}

adapters/silverpush/params_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package silverpush
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/prebid/prebid-server/openrtb_ext"
8+
)
9+
10+
// This file intends to test static/bidder-params/silverpush.json
11+
12+
// These also validate the format of the external API: request.imp[i].bidRequestExt.silverpush
13+
14+
// TestValidParams makes sure that the Smaato schema accepts all imp.bidRequestExt fields which Smaato supports.
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.BidderSilverPush, json.RawMessage(validParam)); err != nil {
23+
t.Errorf("Schema rejected silverpush params: %s \n Error: %s", validParam, err)
24+
}
25+
}
26+
}
27+
28+
// TestInvalidParams makes sure that the Smaato schema rejects all the imp.bidRequestExt fields which are not 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.BidderSilverPush, json.RawMessage(invalidParam)); err == nil {
37+
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
38+
}
39+
}
40+
}
41+
42+
var validParams = []string{
43+
`{"publisherId":"test-id-1234-silverpush","bidfloor": 0.05}`,
44+
`{"publisherId":"test123","bidfloor": 0.05}`,
45+
`{"publisherId":"testSIlverpush","bidfloor": 0.05}`,
46+
}
47+
48+
var invalidParams = []string{
49+
``,
50+
`null`,
51+
`true`,
52+
`5`,
53+
`4.2`,
54+
`[]`,
55+
`{}`,
56+
`{"bidfloor": "1123581321"}`,
57+
`{"publisherId":false}`,
58+
`{"bidfloor":false}`,
59+
`{"publisherId":0,"bidfloor": 1123581321}`,
60+
`{"publisherId":false,"bidfloor": true}`,
61+
`{"instl": 0}`,
62+
`{"secure": 0}`,
63+
`{"bidfloor": "1123581321"}`,
64+
`{"publisherId":{}}`,
65+
}

0 commit comments

Comments
 (0)