forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncer.go
72 lines (60 loc) · 1.54 KB
/
syncer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package adapters
import (
"strings"
"text/template"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"
)
func GDPRAwareSyncerIDs(syncers map[openrtb_ext.BidderName]usersync.Usersyncer) map[openrtb_ext.BidderName]uint16 {
gdprAwareSyncers := make(map[openrtb_ext.BidderName]uint16, len(syncers))
for bidderName, syncer := range syncers {
if syncer.GDPRVendorID() != 0 {
gdprAwareSyncers[bidderName] = syncer.GDPRVendorID()
}
}
return gdprAwareSyncers
}
type Syncer struct {
familyName string
gdprVendorID uint16
urlTemplate *template.Template
syncType SyncType
}
func NewSyncer(familyName string, vendorID uint16, urlTemplate *template.Template, syncType SyncType) *Syncer {
return &Syncer{
familyName: familyName,
gdprVendorID: vendorID,
urlTemplate: urlTemplate,
syncType: syncType,
}
}
type SyncType string
const (
SyncTypeRedirect SyncType = "redirect"
SyncTypeIframe SyncType = "iframe"
)
func (s *Syncer) GetUsersyncInfo(gdpr string, consent string) (*usersync.UsersyncInfo, error) {
sb := strings.Builder{}
err := s.urlTemplate.Execute(&sb, TemplateValues{
GDPR: gdpr,
GDPRConsent: consent,
})
if err != nil {
return nil, err
}
return &usersync.UsersyncInfo{
URL: sb.String(),
Type: string(s.syncType),
SupportCORS: false,
}, err
}
type TemplateValues struct {
GDPR string
GDPRConsent string
}
func (s *Syncer) FamilyName() string {
return s.familyName
}
func (s *Syncer) GDPRVendorID() uint16 {
return s.gdprVendorID
}