lib/ecoportal/api/v1/people.rb in ecoportal-api-0.4.2 vs lib/ecoportal/api/v1/people.rb in ecoportal-api-0.4.3

- old
+ new

@@ -17,27 +17,27 @@ @client = client end # Iterates all the people of the organization. # @note - # - it ignores the key `page:` of `params:`. + # - it ignores the key `results_from:` of `params:`. # - `each` is called by `to_a` # @param params [Hash] # @option params [String] :per_page the number of people you get per request. # @option params [String] :q some text to search. Omit this parameter to target all the people. # @yield [person] does some stuff with the person. # @yieldparam person [Person] def each(params: {}, &block) return to_enum(:each) unless block - page = 1 + results_from = nil loop do - response = client.get("/people", params: params.merge(page: page)) + params.update(results_from: results_from) if results_from + response = client.get("/people", params: params) raise "Request failed." unless response.success? response.body["results"].each do |person| yield person_class.new(person) end - break if page >= response.body["total_pages"] - page += 1 + break unless (results_from = response.body["next_results_from"]) end self end # Gets all the people via api requests.