lib/survey_gizmo/resource.rb in survey-gizmo-ruby-6.2.6 vs lib/survey_gizmo/resource.rb in survey-gizmo-ruby-6.2.9

- old
+ new

@@ -33,29 +33,32 @@ # SurveyGizmo expects for its internal filtering. # # Properties from the conditions hash (e.g. survey_id) will be added to the returned objects def all(conditions = {}) fail ':all_pages and :page are mutually exclusive' if conditions[:page] && conditions[:all_pages] - logger.warn('WARNING: Only retrieving first page of results!') unless conditions[:page] || conditions[:all_pages] + logger.warn('Only retrieving first page of results!') unless conditions[:page] || conditions[:all_pages] all_pages = conditions.delete(:all_pages) conditions[:resultsperpage] ||= SurveyGizmo.configuration.results_per_page Enumerator.new do |yielder| response = nil while !response || (all_pages && response['page'] < response['total_pages']) - conditions[:page] = response ? response['page'] + 1 : conditions.fetch(:page, 1) + conditions[:page] = response ? response['page'] + 1 : conditions.fetch(:page, 1) + + start_fetch_time = Time.now logger.debug("Fetching #{name} page #{conditions} - #{conditions[:page]}#{response ? "/#{response['total_pages']}" : ''}...") response = Connection.get(create_route(:create, conditions)).body collection = response['data'].map { |datum| datum.is_a?(Hash) ? new(conditions.merge(datum)) : datum } # Sub questions are not pulled by default so we have to retrieve them manually. SurveyGizmo # claims they will fix this bug and eventually all questions will be returned in one request. if self == SurveyGizmo::API::Question collection += collection.flat_map { |question| question.sub_questions } end + logger.debug(" Fetched #{conditions[:resultsperpage]} of #{name} in #{(Time.now - start_fetch_time).to_i}s...") collection.each { |e| yielder.yield(e) } end end end