lib/eco/api/session/batch.rb in eco-helpers-1.5.0 vs lib/eco/api/session/batch.rb in eco-helpers-1.5.1

- old
+ new

@@ -90,53 +90,10 @@ fatal "cannot batch get without api connnection, please provide a valid api connection!" unless people_api = api&.people params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params) client = people_api.client - looping = !params.key?(:page) - page = params[:page] || 1 - - people = []; total_pages = nil - cursor_id = nil - loop do - params.merge!(cursor_id: cursor_id) unless !cursor_id - people_res, response = client_get(client, params: params.merge(page: page), silent: silent) - people += people_res - - total_iterations ||= response.body["total_pages"] - no_pages = !response.body["total_pages"] - total_results ||= response.body["total_results"] - - if !total_iterations - total_iterations ||= (total_results.to_f / params[:per_page]).ceil - end - - msg = "iteration number: #{page}/#{total_iterations}, got num people #{people_res.length}, with total #{people.length} people got" - msg = "search(q=#{params[:q]}) " + msg if params.key?(:q) - logger.info(msg) unless silent - - iterate = (no_pages && cursor_id = response.body["cursor_id"]) || (looping && page < total_iterations) - break unless iterate - page += 1 - end - - return people - end - - def client_get(client, params:, silent: false) - response = client.get("/people", params: params) - unless response.success? - msg = "Request failed - params: #{params}" - msg += "\n Error message: - Status #{response.status}: #{response.body}" - fatal msg - end - people = [] - response.body["results"].each do |person_hash| - person = Ecoportal::API::Internal::Person.new(person_hash) - yield person if block_given? - people.push(person) - end - [people, response] + return people_api.get_all(params: params, silent: silent) end def batch_from(data, method:, params: {}, silent: false) fatal "Invalid batch method: #{method}." if !self.class.valid_method?(method) return nil if !data || !data.is_a?(Enumerable)