From d128a7c4f7cb03c1016617d859b73b3fe137a52b Mon Sep 17 00:00:00 2001 From: Vartan Benohanian Date: Tue, 29 Sep 2020 14:19:32 -0400 Subject: [PATCH] Remove "before" field from Response Listing responses only ever contain a non-empty "before" field when the "count" parameter is provided, which is only useful for the HTML website, not really needed for API clients Signed-off-by: Vartan Benohanian --- reddit/message.go | 9 +-------- reddit/post.go | 2 -- reddit/reddit.go | 4 ---- reddit/subreddit.go | 23 ++++------------------- reddit/things.go | 21 +-------------------- reddit/wiki.go | 7 +------ 6 files changed, 7 insertions(+), 59 deletions(-) diff --git a/reddit/message.go b/reddit/message.go index 5ee4227..c4fc86c 100644 --- a/reddit/message.go +++ b/reddit/message.go @@ -42,25 +42,19 @@ type inboxThing struct { type inboxListing struct { inboxThings - after string - before string + after string } func (l *inboxListing) After() string { return l.after } -func (l *inboxListing) Before() string { - return l.before -} - // UnmarshalJSON implements the json.Unmarshaler interface. func (l *inboxListing) UnmarshalJSON(b []byte) error { root := new(struct { Data struct { Things inboxThings `json:"children"` After string `json:"after"` - Before string `json:"before"` } `json:"data"` }) @@ -71,7 +65,6 @@ func (l *inboxListing) UnmarshalJSON(b []byte) error { l.inboxThings = root.Data.Things l.after = root.Data.After - l.before = root.Data.Before return nil } diff --git a/reddit/post.go b/reddit/post.go index f76c8d7..ef55224 100644 --- a/reddit/post.go +++ b/reddit/post.go @@ -109,8 +109,6 @@ func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDupli duplicates := listing2.Posts() resp.After = listing2.After() - resp.Before = listing2.Before() - return post, duplicates, resp, nil } diff --git a/reddit/reddit.go b/reddit/reddit.go index 939f0f6..7c2d086 100644 --- a/reddit/reddit.go +++ b/reddit/reddit.go @@ -293,9 +293,6 @@ type Response struct { // Pagination anchor indicating there are more results after this id. After string - // Pagination anchor indicating there are more results before this id. - // todo: not sure yet if responses ever contain this - Before string // Rate limit information. Rate Rate @@ -310,7 +307,6 @@ func newResponse(r *http.Response) *Response { func (r *Response) populateAnchors(a anchor) { r.After = a.After() - r.Before = a.Before() } // parseRate parses the rate related headers. diff --git a/reddit/subreddit.go b/reddit/subreddit.go index d6bd451..dc94838 100644 --- a/reddit/subreddit.go +++ b/reddit/subreddit.go @@ -680,9 +680,8 @@ func (s *SubredditService) Banned(ctx context.Context, subreddit string, opts *L root := new(struct { Data struct { - Bans []*Ban `json:"children"` - After string `json:"after"` - Before string `json:"before"` + Bans []*Ban `json:"children"` + After string `json:"after"` } `json:"data"` }) resp, err := s.client.Do(ctx, req, root) @@ -691,8 +690,6 @@ func (s *SubredditService) Banned(ctx context.Context, subreddit string, opts *L } resp.After = root.Data.After - resp.Before = root.Data.Before - return root.Data.Bans, resp, nil } @@ -714,7 +711,6 @@ func (s *SubredditService) Muted(ctx context.Context, subreddit string, opts *Li Data struct { Relationships []*Relationship `json:"children"` After string `json:"after"` - Before string `json:"before"` } `json:"data"` }) resp, err := s.client.Do(ctx, req, root) @@ -723,8 +719,6 @@ func (s *SubredditService) Muted(ctx context.Context, subreddit string, opts *Li } resp.After = root.Data.After - resp.Before = root.Data.Before - return root.Data.Relationships, resp, nil } @@ -744,9 +738,8 @@ func (s *SubredditService) WikiBanned(ctx context.Context, subreddit string, opt root := new(struct { Data struct { - Bans []*Ban `json:"children"` - After string `json:"after"` - Before string `json:"before"` + Bans []*Ban `json:"children"` + After string `json:"after"` } `json:"data"` }) resp, err := s.client.Do(ctx, req, root) @@ -755,8 +748,6 @@ func (s *SubredditService) WikiBanned(ctx context.Context, subreddit string, opt } resp.After = root.Data.After - resp.Before = root.Data.Before - return root.Data.Bans, resp, nil } @@ -778,7 +769,6 @@ func (s *SubredditService) Contributors(ctx context.Context, subreddit string, o Data struct { Relationships []*Relationship `json:"children"` After string `json:"after"` - Before string `json:"before"` } `json:"data"` }) resp, err := s.client.Do(ctx, req, root) @@ -787,8 +777,6 @@ func (s *SubredditService) Contributors(ctx context.Context, subreddit string, o } resp.After = root.Data.After - resp.Before = root.Data.Before - return root.Data.Relationships, resp, nil } @@ -810,7 +798,6 @@ func (s *SubredditService) WikiContributors(ctx context.Context, subreddit strin Data struct { Relationships []*Relationship `json:"children"` After string `json:"after"` - Before string `json:"before"` } `json:"data"` }) resp, err := s.client.Do(ctx, req, root) @@ -819,8 +806,6 @@ func (s *SubredditService) WikiContributors(ctx context.Context, subreddit strin } resp.After = root.Data.After - resp.Before = root.Data.Before - return root.Data.Relationships, resp, nil } diff --git a/reddit/things.go b/reddit/things.go index dccf557..0a2f020 100644 --- a/reddit/things.go +++ b/reddit/things.go @@ -31,7 +31,6 @@ const ( type anchor interface { After() string - Before() string } // thing is an entity on Reddit. @@ -53,17 +52,6 @@ func (t *thing) After() string { return a.After() } -func (t *thing) Before() string { - if t == nil { - return "" - } - a, ok := t.Data.(anchor) - if !ok { - return "" - } - return a.Before() -} - // UnmarshalJSON implements the json.Unmarshaler interface. func (t *thing) UnmarshalJSON(b []byte) error { root := new(struct { @@ -239,27 +227,21 @@ func (t *thing) StyleSheet() (v *SubredditStyleSheet, ok bool) { } // listing is a list of things coming from the Reddit API. -// It also contains the after/before anchors useful for subsequent requests. +// It also contains the after anchor useful to get the next results via subsequent requests. type listing struct { things things after string - before string } func (l *listing) After() string { return l.after } -func (l *listing) Before() string { - return l.before -} - // UnmarshalJSON implements the json.Unmarshaler interface. func (l *listing) UnmarshalJSON(b []byte) error { root := new(struct { Things things `json:"children"` After string `json:"after"` - Before string `json:"before"` }) err := json.Unmarshal(b, root) @@ -269,7 +251,6 @@ func (l *listing) UnmarshalJSON(b []byte) error { l.things = root.Things l.after = root.After - l.before = root.Before return nil } diff --git a/reddit/wiki.go b/reddit/wiki.go index 98a55ae..ef7acda 100644 --- a/reddit/wiki.go +++ b/reddit/wiki.go @@ -127,7 +127,6 @@ type wikiPageRevisionListing struct { Data struct { Revisions []*WikiPageRevision `json:"children"` After string `json:"after"` - Before string `json:"before"` } `json:"data"` } @@ -135,10 +134,6 @@ func (l *wikiPageRevisionListing) After() string { return l.Data.After } -func (l *wikiPageRevisionListing) Before() string { - return l.Data.Before -} - // WikiPageRevision is a revision of a wiki page. type WikiPageRevision struct { ID string `json:"id,omitempty"` @@ -329,7 +324,7 @@ func (s *WikiService) revisions(ctx context.Context, subreddit, page string, opt } if opts != nil { - idPrefix := "WikiRevision_" + const idPrefix = "WikiRevision_" if opts.After != "" && !strings.HasPrefix(opts.After, idPrefix) { opts.After = idPrefix + opts.After }