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
|
@ -43,24 +43,18 @@ type inboxThing struct {
|
||||||
type inboxListing struct {
|
type inboxListing struct {
|
||||||
inboxThings
|
inboxThings
|
||||||
after string
|
after string
|
||||||
before string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *inboxListing) After() string {
|
func (l *inboxListing) After() string {
|
||||||
return l.after
|
return l.after
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *inboxListing) Before() string {
|
|
||||||
return l.before
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
func (l *inboxListing) UnmarshalJSON(b []byte) error {
|
func (l *inboxListing) UnmarshalJSON(b []byte) error {
|
||||||
root := new(struct {
|
root := new(struct {
|
||||||
Data struct {
|
Data struct {
|
||||||
Things inboxThings `json:"children"`
|
Things inboxThings `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -71,7 +65,6 @@ func (l *inboxListing) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
l.inboxThings = root.Data.Things
|
l.inboxThings = root.Data.Things
|
||||||
l.after = root.Data.After
|
l.after = root.Data.After
|
||||||
l.before = root.Data.Before
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,6 @@ func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDupli
|
||||||
duplicates := listing2.Posts()
|
duplicates := listing2.Posts()
|
||||||
|
|
||||||
resp.After = listing2.After()
|
resp.After = listing2.After()
|
||||||
resp.Before = listing2.Before()
|
|
||||||
|
|
||||||
return post, duplicates, resp, nil
|
return post, duplicates, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,9 +293,6 @@ type Response struct {
|
||||||
|
|
||||||
// Pagination anchor indicating there are more results after this id.
|
// Pagination anchor indicating there are more results after this id.
|
||||||
After string
|
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 limit information.
|
||||||
Rate Rate
|
Rate Rate
|
||||||
|
@ -310,7 +307,6 @@ func newResponse(r *http.Response) *Response {
|
||||||
|
|
||||||
func (r *Response) populateAnchors(a anchor) {
|
func (r *Response) populateAnchors(a anchor) {
|
||||||
r.After = a.After()
|
r.After = a.After()
|
||||||
r.Before = a.Before()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseRate parses the rate related headers.
|
// parseRate parses the rate related headers.
|
||||||
|
|
|
@ -682,7 +682,6 @@ func (s *SubredditService) Banned(ctx context.Context, subreddit string, opts *L
|
||||||
Data struct {
|
Data struct {
|
||||||
Bans []*Ban `json:"children"`
|
Bans []*Ban `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
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.After = root.Data.After
|
||||||
resp.Before = root.Data.Before
|
|
||||||
|
|
||||||
return root.Data.Bans, resp, nil
|
return root.Data.Bans, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,7 +711,6 @@ func (s *SubredditService) Muted(ctx context.Context, subreddit string, opts *Li
|
||||||
Data struct {
|
Data struct {
|
||||||
Relationships []*Relationship `json:"children"`
|
Relationships []*Relationship `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
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.After = root.Data.After
|
||||||
resp.Before = root.Data.Before
|
|
||||||
|
|
||||||
return root.Data.Relationships, resp, nil
|
return root.Data.Relationships, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,7 +740,6 @@ func (s *SubredditService) WikiBanned(ctx context.Context, subreddit string, opt
|
||||||
Data struct {
|
Data struct {
|
||||||
Bans []*Ban `json:"children"`
|
Bans []*Ban `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
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.After = root.Data.After
|
||||||
resp.Before = root.Data.Before
|
|
||||||
|
|
||||||
return root.Data.Bans, resp, nil
|
return root.Data.Bans, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,7 +769,6 @@ func (s *SubredditService) Contributors(ctx context.Context, subreddit string, o
|
||||||
Data struct {
|
Data struct {
|
||||||
Relationships []*Relationship `json:"children"`
|
Relationships []*Relationship `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
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.After = root.Data.After
|
||||||
resp.Before = root.Data.Before
|
|
||||||
|
|
||||||
return root.Data.Relationships, resp, nil
|
return root.Data.Relationships, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +798,6 @@ func (s *SubredditService) WikiContributors(ctx context.Context, subreddit strin
|
||||||
Data struct {
|
Data struct {
|
||||||
Relationships []*Relationship `json:"children"`
|
Relationships []*Relationship `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
})
|
})
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
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.After = root.Data.After
|
||||||
resp.Before = root.Data.Before
|
|
||||||
|
|
||||||
return root.Data.Relationships, resp, nil
|
return root.Data.Relationships, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ const (
|
||||||
|
|
||||||
type anchor interface {
|
type anchor interface {
|
||||||
After() string
|
After() string
|
||||||
Before() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// thing is an entity on Reddit.
|
// thing is an entity on Reddit.
|
||||||
|
@ -53,17 +52,6 @@ func (t *thing) After() string {
|
||||||
return a.After()
|
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.
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
func (t *thing) UnmarshalJSON(b []byte) error {
|
func (t *thing) UnmarshalJSON(b []byte) error {
|
||||||
root := new(struct {
|
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.
|
// 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 {
|
type listing struct {
|
||||||
things things
|
things things
|
||||||
after string
|
after string
|
||||||
before string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listing) After() string {
|
func (l *listing) After() string {
|
||||||
return l.after
|
return l.after
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listing) Before() string {
|
|
||||||
return l.before
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
func (l *listing) UnmarshalJSON(b []byte) error {
|
func (l *listing) UnmarshalJSON(b []byte) error {
|
||||||
root := new(struct {
|
root := new(struct {
|
||||||
Things things `json:"children"`
|
Things things `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
})
|
})
|
||||||
|
|
||||||
err := json.Unmarshal(b, root)
|
err := json.Unmarshal(b, root)
|
||||||
|
@ -269,7 +251,6 @@ func (l *listing) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
l.things = root.Things
|
l.things = root.Things
|
||||||
l.after = root.After
|
l.after = root.After
|
||||||
l.before = root.Before
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,6 @@ type wikiPageRevisionListing struct {
|
||||||
Data struct {
|
Data struct {
|
||||||
Revisions []*WikiPageRevision `json:"children"`
|
Revisions []*WikiPageRevision `json:"children"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Before string `json:"before"`
|
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,10 +134,6 @@ func (l *wikiPageRevisionListing) After() string {
|
||||||
return l.Data.After
|
return l.Data.After
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *wikiPageRevisionListing) Before() string {
|
|
||||||
return l.Data.Before
|
|
||||||
}
|
|
||||||
|
|
||||||
// WikiPageRevision is a revision of a wiki page.
|
// WikiPageRevision is a revision of a wiki page.
|
||||||
type WikiPageRevision struct {
|
type WikiPageRevision struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
|
@ -329,7 +324,7 @@ func (s *WikiService) revisions(ctx context.Context, subreddit, page string, opt
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts != nil {
|
if opts != nil {
|
||||||
idPrefix := "WikiRevision_"
|
const idPrefix = "WikiRevision_"
|
||||||
if opts.After != "" && !strings.HasPrefix(opts.After, idPrefix) {
|
if opts.After != "" && !strings.HasPrefix(opts.After, idPrefix) {
|
||||||
opts.After = idPrefix + opts.After
|
opts.After = idPrefix + opts.After
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue