2 Copyright 2017 Mikael Berthe |
2 Copyright 2017 Mikael Berthe |
3 |
3 |
4 Licensed under the MIT license. Please see the LICENSE file is this directory. |
4 Licensed under the MIT license. Please see the LICENSE file is this directory. |
5 */ |
5 */ |
6 |
6 |
7 package gondole |
7 package madon |
8 |
8 |
9 import ( |
9 import ( |
10 "fmt" |
10 "fmt" |
11 "strconv" |
11 "strconv" |
12 |
12 |
13 "github.com/sendgrid/rest" |
13 "github.com/sendgrid/rest" |
14 ) |
14 ) |
15 |
15 |
16 // GetReports returns the current user's reports |
16 // GetReports returns the current user's reports |
17 func (g *Client) GetReports() ([]Report, error) { |
17 func (mc *Client) GetReports() ([]Report, error) { |
18 var reports []Report |
18 var reports []Report |
19 if err := g.apiCall("reports", rest.Get, nil, &reports); err != nil { |
19 if err := mc.apiCall("reports", rest.Get, nil, &reports); err != nil { |
20 return nil, err |
20 return nil, err |
21 } |
21 } |
22 return reports, nil |
22 return reports, nil |
23 } |
23 } |
24 |
24 |
25 // ReportUser reports the user account |
25 // ReportUser reports the user account |
26 func (g *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) { |
26 func (mc *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) { |
27 if accountID < 1 || comment == "" || len(statusIDs) < 1 { |
27 if accountID < 1 || comment == "" || len(statusIDs) < 1 { |
28 return nil, ErrInvalidParameter |
28 return nil, ErrInvalidParameter |
29 } |
29 } |
30 |
30 |
31 params := make(apiCallParams) |
31 params := make(apiCallParams) |
38 qID := fmt.Sprintf("status_ids[%d]", i+1) |
38 qID := fmt.Sprintf("status_ids[%d]", i+1) |
39 params[qID] = strconv.Itoa(id) |
39 params[qID] = strconv.Itoa(id) |
40 } |
40 } |
41 |
41 |
42 var report Report |
42 var report Report |
43 if err := g.apiCall("reports", rest.Post, params, &report); err != nil { |
43 if err := mc.apiCall("reports", rest.Post, params, &report); err != nil { |
44 return nil, err |
44 return nil, err |
45 } |
45 } |
46 return &report, nil |
46 return &report, nil |
47 } |
47 } |