report.go
author Mikael Berthe <mikael@lilotux.net>
Sun, 16 Apr 2017 02:12:38 +0200
changeset 127 96a7f2432d27
parent 125 2bbb72b9ebf6
child 130 c450bb73f59a
permissions -rw-r--r--
GetTimelines: Allow '#' as hashtag prefix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
6d89be3dd966 Placeholders.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     1
package gondole
116
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     2
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     3
import (
125
2bbb72b9ebf6 Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     4
	"fmt"
116
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     5
	"strconv"
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     6
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     7
	"github.com/sendgrid/rest"
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     8
)
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
     9
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    10
// GetReports returns the current user's reports
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    11
func (g *Client) GetReports() ([]Report, error) {
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    12
	var reports []Report
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    13
	if err := g.apiCall("reports", rest.Get, nil, &reports); err != nil {
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    14
		return nil, err
116
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    15
	}
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    16
	return reports, nil
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    17
}
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    18
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    19
// ReportUser reports the user account
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    20
func (g *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) {
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    21
	if accountID < 1 || comment == "" || len(statusIDs) < 1 {
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    22
		return nil, ErrInvalidParameter
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    23
	}
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    24
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    25
	params := make(apiCallParams)
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    26
	params["account_id"] = strconv.Itoa(accountID)
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    27
	params["comment"] = comment
125
2bbb72b9ebf6 Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    28
	for i, id := range statusIDs {
2bbb72b9ebf6 Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    29
		qID := fmt.Sprintf("status_ids[%d]", i+1)
2bbb72b9ebf6 Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    30
		params[qID] = strconv.Itoa(id)
2bbb72b9ebf6 Rework the API wrappers to handle arrays of parameters
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    31
	}
116
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    32
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    33
	var report Report
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    34
	if err := g.apiCall("reports", rest.Post, params, &report); err != nil {
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 116
diff changeset
    35
		return nil, err
116
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    36
	}
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    37
	return &report, nil
d237ffdd75c0 Add reports API calls
Mikael Berthe <mikael@lilotux.net>
parents: 19
diff changeset
    38
}