Ejemplo n.º 1
0
// Thread returns a post with its comments.
func (o *Operator) Thread(url string) (*redditproto.Link, error) {
	req, err := request.New(
		"GET",
		fmt.Sprintf("%s.json", url),
		nil,
	)
	if err != nil {
		return nil, err
	}

	response, err := o.cli.Do(req)
	if err != nil {
		return nil, err
	}

	return parser.ParseThread(response)
}
Ejemplo n.º 2
0
// Threads returns specific threads, requested by their fullname (t[1-6]_[id]).
// This does not return their comments.
func (o *Operator) Threads(fullnames ...string) ([]*redditproto.Link, error) {
	ids := strings.Join(fullnames, ",")
	req, err := request.New(
		"GET",
		fmt.Sprintf("https://oauth.reddit.com/by_id/%s", ids),
		nil,
	)
	if err != nil {
		return nil, err
	}

	response, err := o.cli.Do(req)
	if err != nil {
		return nil, err
	}

	return parser.ParseLinkListing(response)
}
Ejemplo n.º 3
0
// Scrape returns posts from a subreddit, in the specified sort order, with the
// specified reference points for direction, up to lim. lims above 100 are
// ineffective because Reddit will return only 100 posts per query. Comments are
// not included in this query.
func (o *Operator) Scrape(sub, sort, after, before string, lim uint) ([]*redditproto.Link, error) {
	req, err := request.New(
		"GET",
		fmt.Sprintf("https://oauth.reddit.com/r/%s/%s.json", sub, sort),
		&url.Values{
			"limit":  []string{strconv.Itoa(int(lim))},
			"after":  []string{after},
			"before": []string{before},
		},
	)
	if err != nil {
		return nil, err
	}

	response, err := o.cli.Do(req)
	if err != nil {
		return nil, err
	}

	return parser.ParseLinkListing(response)
}