Exemple #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
}