forked from justwatch/facebook-marketing-api-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interest.go
54 lines (44 loc) · 1.47 KB
/
interest.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
package v14
import (
"context"
"strings"
"github.com/lavkumarv/facebook-marketing-api-golang-sdk/fb"
)
// InterestService works with ads interests.
type InterestService struct {
c *fb.Client
}
// Search returns a list of InterestTargetings.
func (is *InterestService) Search(ctx context.Context, query string, limit int) ([]InterestTargeting, error) {
query = strings.TrimSpace(query)
if query == "" {
return []InterestTargeting{}, nil
}
res := []InterestTargeting{}
err := is.c.GetList(ctx, fb.NewRoute(Version, "/search").Type("adinterest").Q(query).Limit(limit).Fields("id", "name", "audience_size_upper_bound", "path", "description", "topic").String(), &res)
if err != nil {
return nil, err
}
return res, nil
}
// TargetingSearch searches for a targeting.
func (is *InterestService) TargetingSearch(ctx context.Context, act string, query string) ([]InterestTargeting, error) {
query = strings.TrimSpace(query)
if query == "" {
return []InterestTargeting{}, nil
}
res := []InterestTargeting{}
err := is.c.GetList(ctx, fb.NewRoute(Version, "/act_%s/targetingsearch", act).Q(query).String(), &res)
if err != nil {
return nil, err
}
return res, nil
}
// InterestTargeting represents an ad interest to be used in an adset targeting.
type InterestTargeting struct {
ID string `json:"id"`
Name string `json:"name"`
AudienceSize uint64 `json:"audience_size_upper_bound"`
Type string `json:"type"`
Path []string `json:"path"`
}