README.md in elasticsearch-api-7.9.0 vs README.md in elasticsearch-api-7.10.0.pre

- old
+ new

@@ -73,16 +73,17 @@ When you want to mix the library into your own client, it must conform to a following _contract_: * It responds to a `perform_request(method, path, params, body, headers)` method, * the method returns an object with `status`, `body` and `headers` methods. -A simple client could look like this: +A simple client could look like this (_with a dependency on `active_support` to parse the query params_): ```ruby require 'multi_json' require 'faraday' require 'elasticsearch/api' +require 'active_support' class MySimpleClient include Elasticsearch::API CONNECTION = ::Faraday::Connection.new url: 'http://localhost:9200' @@ -90,12 +91,27 @@ def perform_request(method, path, params, body, headers = nil) puts "--> #{method.upcase} #{path} #{params} #{body} #{headers}" CONNECTION.run_request \ method.downcase.to_sym, - path, + path_with_params(path, params), ( body ? MultiJson.dump(body): nil ), {'Content-Type' => 'application/json'} + end + + private + + def path_with_params(path, params) + return path if params.blank? + + case params + when String + "#{path}?#{params}" + when Hash + "#{path}?#{params.to_query}" + else + raise ArgumentError, "Cannot parse params: '#{params}'" + end end end client = MySimpleClient.new