This repository has been archived on 2022-03-09. You can view files and clone it, but cannot push or open issues or pull requests.
snoo2nebby/vendor/github.com/turnage/graw/reddit/lurker.go

32 lines
570 B
Go

package reddit
// Lurker defines browsing behavior.
type Lurker interface {
// Thread returns a Reddit post with a fully parsed comment tree.
Thread(permalink string) (*Post, error)
}
type lurker struct {
r reaper
}
func newLurker(r reaper) Lurker {
return &lurker{r: r}
}
func (s *lurker) Thread(permalink string) (*Post, error) {
harvest, err := s.r.reap(
permalink+".json",
map[string]string{"raw_json": "1"},
)
if err != nil {
return nil, err
}
if len(harvest.Posts) != 1 {
return nil, ThreadDoesNotExistErr
}
return harvest.Posts[0], nil
}