Add store_visits method, about/edited in moderation service
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
4a2284755f
commit
304b02f47d
5 changed files with 95 additions and 4 deletions
10
account.go
10
account.go
|
@ -189,10 +189,12 @@ type Settings struct {
|
|||
ShowCustomSubredditThemes *bool `json:"show_stylesheets,omitempty"`
|
||||
|
||||
// Show trending subreddits on the home feed.
|
||||
ShowTrendingSubreddits *bool `json:"show_trending,omitempty"`
|
||||
ShowTwitter *bool `json:"show_twitter,omitempty"`
|
||||
StoreVisits *bool `json:"store_visits,omitempty"`
|
||||
ThemeSelector *string `json:"theme_selector,omitempty"`
|
||||
ShowTrendingSubreddits *bool `json:"show_trending,omitempty"`
|
||||
ShowTwitter *bool `json:"show_twitter,omitempty"`
|
||||
|
||||
// Store whether or not you want to track posts you've visited.
|
||||
StoreVisits *bool `json:"store_visits,omitempty"`
|
||||
ThemeSelector *string `json:"theme_selector,omitempty"`
|
||||
|
||||
// Allow Reddit to use data provided by third-parties to show you more relevant advertisements on Reddit.i
|
||||
AllowThirdPartyDataAdPersonalization *bool `json:"third_party_data_personalized_ads,omitempty"`
|
||||
|
|
|
@ -177,3 +177,26 @@ func (s *ModerationService) LeaveContributor(ctx context.Context, subredditID st
|
|||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// Edited gets posts and comments that have been edited recently.
|
||||
func (s *ModerationService) Edited(ctx context.Context, subreddit string, opts *ListOptions) (*Posts, *Comments, *Response, error) {
|
||||
path := fmt.Sprintf("r/%s/about/edited", subreddit)
|
||||
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
root := new(rootListing)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return root.getPosts(), root.getComments(), resp, nil
|
||||
}
|
||||
|
|
|
@ -211,3 +211,30 @@ func TestModerationService_LeaveContributor(t *testing.T) {
|
|||
_, err := client.Moderation.LeaveContributor(ctx, "t5_test")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestModerationService_Edited(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
// contains posts and comments
|
||||
blob, err := readFileContents("testdata/user/overview.json")
|
||||
require.NoError(t, err)
|
||||
|
||||
mux.HandleFunc("/r/testsubreddit/about/edited", func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, http.MethodGet, r.Method)
|
||||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
posts, comments, _, err := client.Moderation.Edited(ctx, "testsubreddit", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, posts.Posts, 1)
|
||||
require.Equal(t, expectedPost, posts.Posts[0])
|
||||
require.Equal(t, "t1_f0zsa37", posts.After)
|
||||
require.Equal(t, "", posts.Before)
|
||||
|
||||
require.Len(t, comments.Comments, 1)
|
||||
require.Equal(t, expectedComment, comments.Comments[0])
|
||||
require.Equal(t, "t1_f0zsa37", comments.After)
|
||||
require.Equal(t, "", comments.Before)
|
||||
}
|
||||
|
|
20
post.go
20
post.go
|
@ -530,3 +530,23 @@ func (s *PostService) Random(ctx context.Context) (*PostAndComments, *Response,
|
|||
func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*PostAndComments, *Response, error) {
|
||||
return s.random(ctx)
|
||||
}
|
||||
|
||||
// MarkVisited marks the post(s) as visited.
|
||||
// This method requires a subscription to Reddit premium.
|
||||
func (s *PostService) MarkVisited(ctx context.Context, ids ...string) (*Response, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, errors.New("must provide at least 1 id")
|
||||
}
|
||||
|
||||
path := "api/store_visits"
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("links", strings.Join(ids, ","))
|
||||
|
||||
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
|
19
post_test.go
19
post_test.go
|
@ -1034,3 +1034,22 @@ func TestPostService_RemoveVote(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
}
|
||||
|
||||
func TestPostService_MarkVisited(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/store_visits", func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("links", "t3_test1,t3_test2,t3_test3")
|
||||
|
||||
err := r.ParseForm()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, form, r.PostForm)
|
||||
})
|
||||
|
||||
_, err := client.Post.MarkVisited(ctx, "t3_test1", "t3_test2", "t3_test3")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue