-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tag.go
63 lines (48 loc) · 1.18 KB
/
Tag.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
package mailchimp
import (
"fmt"
errortools "github.com/leapforce-libraries/go_errortools"
go_http "github.com/leapforce-libraries/go_http"
"net/http"
"net/url"
)
type Tag struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type SearchTagsConfig struct {
ListId string
Name *string
}
type SearchTagsResponse struct {
Tags []Tag `json:"tags"`
TotalItems int `json:"total_items"`
}
func (service *Service) SearchTags(cfg *SearchTagsConfig) (*[]Tag, *errortools.Error) {
if cfg == nil {
return nil, errortools.ErrorMessage("SearchTagsConfig must not be nil")
}
var tags []Tag
var values = url.Values{}
if cfg.Name != nil {
values.Set("name", *cfg.Name)
}
for {
var response SearchTagsResponse
requestConfig := go_http.RequestConfig{
Method: http.MethodGet,
Url: service.url(fmt.Sprintf("lists/%s/tag-search?%s", cfg.ListId, values.Encode())),
ResponseModel: &response,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, e
}
tags = append(tags, response.Tags...)
if len(tags) >= response.TotalItems {
break
}
values.Set("offset", fmt.Sprintf("%v", len(tags)))
}
return &tags, nil
}