vendor/github.com/McKael/madon/v3/report.go
changeset 270 df7e9dff1b66
parent 268 4dd196a4ee7c
equal deleted inserted replaced
269:c50e88700432 270:df7e9dff1b66
     6 
     6 
     7 package madon
     7 package madon
     8 
     8 
     9 import (
     9 import (
    10 	"fmt"
    10 	"fmt"
    11 	"strconv"
       
    12 
    11 
    13 	"github.com/sendgrid/rest"
    12 	"github.com/sendgrid/rest"
    14 )
    13 )
    15 
    14 
    16 // GetReports returns the current user's reports
    15 // GetReports returns the current user's reports
    22 	}
    21 	}
    23 	return reports, nil
    22 	return reports, nil
    24 }
    23 }
    25 
    24 
    26 // ReportUser reports the user account
    25 // ReportUser reports the user account
    27 func (mc *Client) ReportUser(accountID int64, statusIDs []int64, comment string) (*Report, error) {
    26 func (mc *Client) ReportUser(accountID ActivityID, statusIDs []ActivityID, comment string) (*Report, error) {
    28 	if accountID < 1 || comment == "" || len(statusIDs) < 1 {
    27 	if accountID == "" || comment == "" || len(statusIDs) < 1 {
    29 		return nil, ErrInvalidParameter
    28 		return nil, ErrInvalidParameter
    30 	}
    29 	}
    31 
    30 
    32 	params := make(apiCallParams)
    31 	params := make(apiCallParams)
    33 	params["account_id"] = strconv.FormatInt(accountID, 10)
    32 	params["account_id"] = accountID
    34 	params["comment"] = comment
    33 	params["comment"] = comment
    35 	for i, id := range statusIDs {
    34 	for i, id := range statusIDs {
    36 		if id < 1 {
    35 		if id == "" {
    37 			return nil, ErrInvalidID
    36 			return nil, ErrInvalidID
    38 		}
    37 		}
    39 		qID := fmt.Sprintf("[%d]status_ids", i)
    38 		qID := fmt.Sprintf("[%d]status_ids", i)
    40 		params[qID] = strconv.FormatInt(id, 10)
    39 		params[qID] = id
    41 	}
    40 	}
    42 
    41 
    43 	var report Report
    42 	var report Report
    44 	if err := mc.apiCall("v1/reports", rest.Post, params, nil, nil, &report); err != nil {
    43 	if err := mc.apiCall("v1/reports", rest.Post, params, nil, nil, &report); err != nil {
    45 		return nil, err
    44 		return nil, err