Method: Booker::Client#all
- Defined in:
- lib/booker.rb
#all(method, result_name, options = {}) ⇒ Object
Useful to pull all of paged results and return them as if you did one request for them all
ex: client.all(:find_locations, ‘Results’)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/booker.rb', line 25 def all method, result_name, = {} page_number = 1 results = [] # this allows page size to be overidden but NOT page_number as I want to # control that to know when we have all results = {"PageSize" => 500}.merge begin .merge!({ "PageNumber" => page_number, }) last_result = self.send(method, ) results << last_result[result_name] results.flatten! if last_result['TotalResultsCount'] total_results = last_result['TotalResultsCount'] else total_results = 0 end page_number+=1 end while results.length < total_results-1 last_result.merge({ result_name => results }) end |