-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadvertiser_profiles.go
155 lines (134 loc) · 3.83 KB
/
advertiser_profiles.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package tonicpow
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
// permitFields will remove fields that cannot be used
func (a *AdvertiserProfile) permitFields() {
a.PublicGUID = ""
a.UserID = 0
}
// GetAdvertiserProfile will get an existing advertiser profile
// This will return an Error if the profile is not found (404)
//
// For more information: https://docs.tonicpow.com/#b3a62d35-7778-4314-9321-01f5266c3b51
func (c *Client) GetAdvertiserProfile(profileID uint64) (profile *AdvertiserProfile,
response *StandardResponse, err error) {
// Must have an ID
if profileID == 0 {
err = fmt.Errorf("missing field: %s", fieldID)
return
}
// Fire the Request
if response, err = c.Request(
http.MethodGet,
fmt.Sprintf("/%s/details/%d", modelAdvertiser, profileID),
nil, http.StatusOK,
); err != nil {
return
}
// Convert model response
err = json.Unmarshal(response.Body, &profile)
return
}
// UpdateAdvertiserProfile will update an existing profile
//
// For more information: https://docs.tonicpow.com/#0cebd1ff-b1ce-4111-aff6-9d586f632a84
func (c *Client) UpdateAdvertiserProfile(profile *AdvertiserProfile) (*StandardResponse, error) {
// Basic requirements
if profile.ID == 0 {
return nil, fmt.Errorf("missing required attribute: %s", fieldID)
}
// Permit fields
profile.permitFields()
// Fire the Request
response, err := c.Request(
http.MethodPut,
"/"+modelAdvertiser,
profile, http.StatusOK,
)
if err != nil {
return response, err
}
// Convert model response
return response, json.Unmarshal(response.Body, &profile)
}
// ListCampaignsByAdvertiserProfile will return a list of campaigns
//
// For more information: https://docs.tonicpow.com/#98017e9a-37dd-4810-9483-b6c400572e0c
func (c *Client) ListCampaignsByAdvertiserProfile(profileID uint64, page, resultsPerPage int,
sortBy, sortOrder string) (campaigns *CampaignResults, response *StandardResponse, err error) {
// Basic requirements
if profileID == 0 {
err = fmt.Errorf("missing required attribute: %s", fieldAdvertiserProfileID)
return
}
// Do we know this field?
if len(sortBy) > 0 {
if !isInList(strings.ToLower(sortBy), campaignSortFields) {
err = fmt.Errorf("sort by %s is not valid", sortBy)
return
}
} else {
sortBy = SortByFieldCreatedAt
sortOrder = SortOrderDesc
}
// Fire the Request
if response, err = c.Request(
http.MethodGet,
fmt.Sprintf("/%s/%s/%d?%s=%d&%s=%d&%s=%s&%s=%s", modelAdvertiser, modelCampaign, profileID,
fieldCurrentPage, page,
fieldResultsPerPage, resultsPerPage,
fieldSortBy, sortBy,
fieldSortOrder, sortOrder,
),
nil, http.StatusOK,
); err != nil {
return
}
// Convert model response
err = json.Unmarshal(response.Body, &campaigns)
return
}
// ListAppsByAdvertiserProfile will return a list of apps
//
// For more information: https://docs.tonicpow.com/#9c9fa8dc-3017-402e-8059-136b0eb85c2e
func (c *Client) ListAppsByAdvertiserProfile(profileID uint64, page, resultsPerPage int,
sortBy, sortOrder string) (apps *AppResults, response *StandardResponse, err error) {
// Basic requirements
if profileID == 0 {
err = fmt.Errorf("missing required attribute: %s", fieldAdvertiserProfileID)
return
}
// Do we know this field?
if len(sortBy) > 0 {
if !isInList(strings.ToLower(sortBy), appSortFields) {
err = fmt.Errorf("sort by %s is not valid", sortBy)
return
}
} else {
sortBy = SortByFieldCreatedAt
sortOrder = SortOrderDesc
}
// Fire the Request
if response, err = c.Request(
http.MethodGet,
fmt.Sprintf(
"/%s/%s/?%s=%d&%s=%d&%s=%d&%s=%s&%s=%s",
modelAdvertiser, modelApp,
fieldID, profileID,
fieldCurrentPage, page,
fieldResultsPerPage, resultsPerPage,
fieldSortBy, sortBy,
fieldSortOrder, sortOrder,
),
nil, http.StatusOK,
); err != nil {
return
}
// Convert model response
err = json.Unmarshal(response.Body, &apps)
return
}