author | Mikael Berthe <mikael@lilotux.net> |
Wed, 05 Sep 2018 02:33:23 +0200 | |
changeset 231 | 741291bb4772 |
parent 207 | 301d5b94be3f |
child 238 | 1c0042e76902 |
permissions | -rw-r--r-- |
130 | 1 |
/* |
207 | 2 |
Copyright 2017-2018 Mikael Berthe |
130 | 3 |
|
4 |
Licensed under the MIT license. Please see the LICENSE file is this directory. |
|
5 |
*/ |
|
6 |
||
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
7 |
package madon |
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 |
|
156
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
17 |
// (I don't know if the limit options are used by the API server.) |
149
5f922977d7c7
Add support for limits and paging ({since,max}_id) API parameters
Mikael Berthe <mikael@lilotux.net>
parents:
138
diff
changeset
|
18 |
func (mc *Client) GetReports(lopt *LimitParams) ([]Report, error) { |
116 | 19 |
var reports []Report |
155 | 20 |
if err := mc.apiCall("reports", rest.Get, nil, lopt, nil, &reports); err != nil { |
120 | 21 |
return nil, err |
116 | 22 |
} |
23 |
return reports, nil |
|
24 |
} |
|
25 |
||
26 |
// ReportUser reports the user account |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
156
diff
changeset
|
27 |
func (mc *Client) ReportUser(accountID int64, statusIDs []int64, comment string) (*Report, error) { |
116 | 28 |
if accountID < 1 || comment == "" || len(statusIDs) < 1 { |
29 |
return nil, ErrInvalidParameter |
|
30 |
} |
|
31 |
||
120 | 32 |
params := make(apiCallParams) |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
156
diff
changeset
|
33 |
params["account_id"] = strconv.FormatInt(accountID, 10) |
120 | 34 |
params["comment"] = comment |
125
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
35 |
for i, id := range statusIDs { |
134
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
36 |
if id < 1 { |
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
37 |
return nil, ErrInvalidID |
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
38 |
} |
231
741291bb4772
Fix (hopefully) handling of arrays in API calls
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
39 |
qID := fmt.Sprintf("status_ids[%d]", i) |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
156
diff
changeset
|
40 |
params[qID] = strconv.FormatInt(id, 10) |
125
2bbb72b9ebf6
Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
41 |
} |
116 | 42 |
|
43 |
var report Report |
|
155 | 44 |
if err := mc.apiCall("reports", rest.Post, params, nil, nil, &report); err != nil { |
120 | 45 |
return nil, err |
116 | 46 |
} |
47 |
return &report, nil |
|
48 |
} |