vendor/github.com/McKael/madon/v2/report.go
changeset 265 05c40b36d3b2
parent 264 8f478162d991
child 266 80973a656b81
equal deleted inserted replaced
264:8f478162d991 265:05c40b36d3b2
     1 /*
       
     2 Copyright 2017-2018 Mikael Berthe
       
     3 
       
     4 Licensed under the MIT license.  Please see the LICENSE file is this directory.
       
     5 */
       
     6 
       
     7 package madon
       
     8 
       
     9 import (
       
    10 	"fmt"
       
    11 	"strconv"
       
    12 
       
    13 	"github.com/sendgrid/rest"
       
    14 )
       
    15 
       
    16 // GetReports returns the current user's reports
       
    17 // (I don't know if the limit options are used by the API server.)
       
    18 func (mc *Client) GetReports(lopt *LimitParams) ([]Report, error) {
       
    19 	var reports []Report
       
    20 	if err := mc.apiCall("v1/reports", rest.Get, nil, lopt, nil, &reports); err != nil {
       
    21 		return nil, err
       
    22 	}
       
    23 	return reports, nil
       
    24 }
       
    25 
       
    26 // ReportUser reports the user account
       
    27 func (mc *Client) ReportUser(accountID int64, statusIDs []int64, comment string) (*Report, error) {
       
    28 	if accountID < 1 || comment == "" || len(statusIDs) < 1 {
       
    29 		return nil, ErrInvalidParameter
       
    30 	}
       
    31 
       
    32 	params := make(apiCallParams)
       
    33 	params["account_id"] = strconv.FormatInt(accountID, 10)
       
    34 	params["comment"] = comment
       
    35 	for i, id := range statusIDs {
       
    36 		if id < 1 {
       
    37 			return nil, ErrInvalidID
       
    38 		}
       
    39 		qID := fmt.Sprintf("[%d]status_ids", i)
       
    40 		params[qID] = strconv.FormatInt(id, 10)
       
    41 	}
       
    42 
       
    43 	var report Report
       
    44 	if err := mc.apiCall("v1/reports", rest.Post, params, nil, nil, &report); err != nil {
       
    45 		return nil, err
       
    46 	}
       
    47 	return &report, nil
       
    48 }