lib/zendesk2/client/mock.rb in zendesk2-1.4.1 vs lib/zendesk2/client/mock.rb in zendesk2-1.4.2

- old
+ new

@@ -63,12 +63,16 @@ def html_url_for(path) File.join(@url, path.to_s) end - def url_for(path) - File.join(@url, "/api/v2", path.to_s) + def url_for(path, options={}) + Addressable::URI.parse( + File.join(@url, "/api/v2", path.to_s) + ).tap do |uri| + uri.query_values = options.fetch(:query, {}) + end.to_s end def resources(collection, path, collection_root, options={}) filter = options[:filter] resources = self.data[collection].values @@ -84,23 +88,25 @@ ) end def page(params, collection, path, collection_root, options={}) page_params = Zendesk2.paging_parameters(params) - page_size = (page_params["per_page"] || 50).to_i + page_size = (page_params["per_page"] || 100).to_i page_index = (page_params["page"] || 1).to_i offset = (page_index - 1) * page_size filter = options[:filter] resources = options[:resources] || self.data[collection].values resources = filter.call(resources) if filter count = resources.size total_pages = (count / page_size) + 1 + query = options.fetch(:query, {}) + next_page = if page_index < total_pages - url_for("#{path}?page=#{page_index + 1}&per_page=#{page_size}") + url_for(path, query: {page: page_index + 1, per_page: page_size}.merge(query)) end previous_page = if page_index > 1 - url_for("#{path}?page=#{page_index - 1}&per_page=#{page_size}") + url_for(path, query: {page: page_index - 1, per_page: page_size}.merge(query)) end resource_page = resources.slice(offset, page_size) body = {