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