2020-07-11 13:49:07 -04:00
|
|
|
package reddit
|
2020-05-03 17:31:35 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-11 14:11:41 -04:00
|
|
|
"net/http"
|
2020-05-03 17:31:35 -04:00
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrivateMessageService handles communication with the private message
|
|
|
|
// related methods of the Reddit API
|
|
|
|
type PrivateMessageService interface {
|
|
|
|
BlockUser(ctx context.Context, messageID string) (*Response, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrivateMessageServiceOp implements the PrivateMessageService interface
|
|
|
|
type PrivateMessageServiceOp struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PrivateMessageService = &PrivateMessageServiceOp{}
|
|
|
|
|
|
|
|
// BlockUser blocks a user based on the ID of the private message
|
|
|
|
func (s *PrivateMessageServiceOp) BlockUser(ctx context.Context, messageID string) (*Response, error) {
|
|
|
|
path := "api/block"
|
|
|
|
|
|
|
|
form := url.Values{}
|
|
|
|
form.Set("id", messageID)
|
|
|
|
|
2020-07-11 14:11:41 -04:00
|
|
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
2020-05-03 17:31:35 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.client.Do(ctx, req, nil)
|
|
|
|
}
|