-
Notifications
You must be signed in to change notification settings - Fork 0
/
Survey.go
70 lines (56 loc) · 1.88 KB
/
Survey.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
package mailchimp
import (
"fmt"
errortools "github.com/leapforce-libraries/go_errortools"
go_http "github.com/leapforce-libraries/go_http"
"github.com/leapforce-libraries/go_mailchimp/types"
"net/http"
"net/url"
)
type Survey struct {
Id string `json:"id"`
ListId string `json:"list_id"`
WebId string `json:"web_id"`
Title string `json:"title"`
Status string `json:"status"`
HostedUrl string `json:"hosted_url"`
IsPipedToInbox bool `json:"is_piped_to_inbox"`
QuestionCount int `json:"question_count"`
ResponseCount int `json:"response_count"`
Questions []string `json:"questions"`
CreatedAt types.DateTimeString `json:"created_at"`
UpdatedAt *types.DateTimeString `json:"updated_at"`
PublishedAt *types.DateTimeString `json:"published_at"`
}
type ListSurveysConfig struct {
ListId string
}
type ListSurveysResponse struct {
Surveys []Survey `json:"surveys"`
TotalItems int `json:"total_items"`
}
func (service *Service) ListSurveys(cfg *ListSurveysConfig) (*[]Survey, *errortools.Error) {
if cfg == nil {
return nil, errortools.ErrorMessage("ListSurveysConfig must not be nil")
}
var surveys []Survey
var values = url.Values{}
for {
var response ListSurveysResponse
requestConfig := go_http.RequestConfig{
Method: http.MethodGet,
Url: service.url(fmt.Sprintf("lists/%s/surveys?%s", cfg.ListId, values.Encode())),
ResponseModel: &response,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, e
}
surveys = append(surveys, response.Surveys...)
if len(surveys) >= response.TotalItems {
break
}
values.Set("offset", fmt.Sprintf("%v", len(surveys)))
}
return &surveys, nil
}