a0b06ed651
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package reddit
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// ModerationService handles communication with the moderation
|
|
// related methods of the Reddit API.
|
|
//
|
|
// Reddit API docs: https://www.reddit.com/dev/api/#section_moderation
|
|
type ModerationService service
|
|
|
|
// ModAction is an action executed by a moderator of a subreddit, such
|
|
// as inviting another user to be a mod, or setting permissions.
|
|
type ModAction struct {
|
|
ID string `json:"id,omitempty"`
|
|
Action string `json:"action,omitempty"`
|
|
Created *Timestamp `json:"created_utc,omitempty"`
|
|
|
|
Moderator string `json:"mod,omitempty"`
|
|
// Not the full ID, just the ID36.
|
|
ModeratorID string `json:"mod_id36,omitempty"`
|
|
|
|
// The author of whatever the action was produced on, e.g. a user, post, comment, etc.
|
|
TargetAuthor string `json:"target_author,omitempty"`
|
|
// This is the full ID of whatever the target was.
|
|
TargetID string `json:"target_fullname,omitempty"`
|
|
TargetTitle string `json:"target_title,omitempty"`
|
|
TargetPermalink string `json:"target_permalink,omitempty"`
|
|
TargetBody string `json:"target_body,omitempty"`
|
|
|
|
Subreddit string `json:"subreddit,omitempty"`
|
|
// Not the full ID, just the ID36.
|
|
SubredditID string `json:"sr_id36,omitempty"`
|
|
}
|
|
|
|
// GetActions gets a list of moderator actions on a subreddit.
|
|
func (s *ModerationService) GetActions(ctx context.Context, subreddit string, opts ...SearchOptionSetter) (*ModActions, *Response, error) {
|
|
form := newSearchOptions(opts...)
|
|
|
|
path := fmt.Sprintf("r/%s/about/log", subreddit)
|
|
path = addQuery(path, form)
|
|
|
|
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
root := new(rootListing)
|
|
resp, err := s.client.Do(ctx, req, root)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return root.getModeratorActions(), resp, nil
|
|
}
|
|
|
|
/*
|
|
type rootTrophyListing struct {
|
|
Kind string `json:"kind,omitempty"`
|
|
Data struct {
|
|
Trophies []rootTrophy `json:"trophies"`
|
|
} `json:"data"`
|
|
}
|
|
*/
|