コード例 #1
0
ファイル: operator.go プロジェクト: KevinRhyne/graw
// 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)
}
コード例 #2
0
ファイル: operator.go プロジェクト: KevinRhyne/graw
// 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)
}
コード例 #3
0
ファイル: operator.go プロジェクト: KevinRhyne/graw
// 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)
}