Beispiel #1
0
// Returns questions based on search parameters params
func Collect(appInfo AppDetails, params stackongo.Params, transport http.RoundTripper) (*stackongo.Questions, error) {
	// Add standard parameters
	params = addParams(appInfo, params)

	// Search for questions
	questions, err := searchAdvanced(params, transport)
	if err != nil {
		return nil, err
	}
	if questions.Error_id != 0 {
		return nil, fmt.Errorf("%v: %v", questions.Error_name, questions.Error_message)
	}

	// If there are more pages of search results, repeat search with next page
	for questions.Has_more && questions.Quota_remaining > 0 {
		params.Page(questions.Page + 1)
		nextPage, err := searchAdvanced(params, transport)
		if err != nil {
			return nil, err
		}
		if nextPage.Error_id != 0 {
			return nil, fmt.Errorf("%v: %v", nextPage.Error_name, nextPage.Error_message)
		}
		nextPage.Items = append(questions.Items, nextPage.Items...)
		questions = nextPage
	}
	return questions, nil
}
func Collect(session *stackongo.Session, appInfo AppDetails, params stackongo.Params) (*stackongo.Questions, error) {
	params.Add("key", appInfo.Key)
	params.Add("filter", appInfo.Filters)
	params.Add("site", "stackoverflow")

	return session.AllQuestions(params)
}
Beispiel #3
0
// Add standard parameters
func addParams(appInfo AppDetails, params stackongo.Params) stackongo.Params {
	params.Add("key", appInfo.Key)
	params.Add("filter", appInfo.Filters)
	params.Add("site", "stackoverflow")
	return params
}