lib/eco/api/session/batch.rb in eco-helpers-0.6.4 vs lib/eco/api/session/batch.rb in eco-helpers-0.6.5
- old
+ new
@@ -22,19 +22,14 @@
end
return nil if !people || !people.is_a?(Array)
batch_from(people, method, api || self.api, params: params)
end
- def valid_methods
- VALID_METHODS
- end
-
def valid_method?(value)
VALID_METHODS.include?(value)
end
-
private
def new_status(queue, method)
BatchStatus.new(enviro, queue: queue, method: method)
end
@@ -47,11 +42,11 @@
end
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
client = people_api.client
people = [];
- if (page = params.fetch(:page, false))
+ if page = params[:page]
res, response = get(client, params: params)
people +=res
logger.info("page number: #{page}, got num people #{people.length}")
else
page = 1
@@ -77,11 +72,11 @@
logger.fatal(msg)
raise msg
end
people = []
response.body["results"].each do |person_hash|
- person = INTERNAL::Person.new(person_hash)
+ person = Ecoportal::API::Internal::Person.new(person_hash)
yield person if block_given?
people.push(person)
end
[people, response]
end
@@ -100,10 +95,10 @@
# param q does not make sense here, even for GET method
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
per_page = params.fetch(:per_page)
iteration = 1; done = 0
- iterations = (people.length / per_page).ceil
+ iterations = (people.length.to_f / per_page).ceil
people.each_slice(per_page) do |slice|
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{people.length} -- #{done} done"
logger.info(msg)