author | Mikael Berthe <mikael@lilotux.net> |
Sat, 15 Apr 2017 21:08:34 +0200 | |
changeset 125 | 2bbb72b9ebf6 |
parent 120 | 579912e9d0ef |
child 130 | c450bb73f59a |
permissions | -rw-r--r-- |
8 | 1 |
package gondole |
116 | 2 |
|
3 |
import ( |
|
125
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
4 |
"fmt" |
116 | 5 |
"strconv" |
6 |
||
7 |
"github.com/sendgrid/rest" |
|
8 |
) |
|
9 |
||
10 |
// GetReports returns the current user's reports |
|
11 |
func (g *Client) GetReports() ([]Report, error) { |
|
12 |
var reports []Report |
|
120 | 13 |
if err := g.apiCall("reports", rest.Get, nil, &reports); err != nil { |
14 |
return nil, err |
|
116 | 15 |
} |
16 |
return reports, nil |
|
17 |
} |
|
18 |
||
19 |
// ReportUser reports the user account |
|
20 |
func (g *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) { |
|
21 |
if accountID < 1 || comment == "" || len(statusIDs) < 1 { |
|
22 |
return nil, ErrInvalidParameter |
|
23 |
} |
|
24 |
||
120 | 25 |
params := make(apiCallParams) |
26 |
params["account_id"] = strconv.Itoa(accountID) |
|
27 |
params["comment"] = comment |
|
125
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
28 |
for i, id := range statusIDs { |
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
29 |
qID := fmt.Sprintf("status_ids[%d]", i+1) |
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
30 |
params[qID] = strconv.Itoa(id) |
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
31 |
} |
116 | 32 |
|
33 |
var report Report |
|
120 | 34 |
if err := g.apiCall("reports", rest.Post, params, &report); err != nil { |
35 |
return nil, err |
|
116 | 36 |
} |
37 |
return &report, nil |
|
38 |
} |