report.go
author Mikael Berthe <mikael@lilotux.net>
Sat, 15 Apr 2017 21:08:34 +0200
changeset 124 5ee3f23205af
parent 120 579912e9d0ef
child 125 2bbb72b9ebf6
permissions -rw-r--r--
Update gondole-cli tests

package gondole

import (
	"strconv"

	"github.com/sendgrid/rest"
)

// GetReports returns the current user's reports
func (g *Client) GetReports() ([]Report, error) {
	var reports []Report
	if err := g.apiCall("reports", rest.Get, nil, &reports); err != nil {
		return nil, err
	}
	return reports, nil
}

// ReportUser reports the user account
// NOTE: Currently only the first statusID is sent.
func (g *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) {
	if accountID < 1 || comment == "" || len(statusIDs) < 1 {
		return nil, ErrInvalidParameter
	}

	params := make(apiCallParams)
	params["account_id"] = strconv.Itoa(accountID)
	// XXX Sending only the first one since I'm not sure arrays work
	params["status_ids"] = strconv.Itoa(statusIDs[0])
	params["comment"] = comment

	var report Report
	if err := g.apiCall("reports", rest.Post, params, &report); err != nil {
		return nil, err
	}
	return &report, nil
}