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 <vartanbeno@gmail.com>
This commit is contained in:
parent
15ee94fbbe
commit
d128a7c4f7
6 changed files with 7 additions and 59 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue