diff --git a/lib/meilisearch/http_request.rb b/lib/meilisearch/http_request.rb index d93a581b..0e00f9f4 100644 --- a/lib/meilisearch/http_request.rb +++ b/lib/meilisearch/http_request.rb @@ -26,9 +26,11 @@ def http_get(relative_path = '', query_params = {}) send_request( proc { |path, config| self.class.get(path, config) }, relative_path, - query_params: query_params, - headers: remove_headers(@headers.dup, 'Content-Type'), - options: @options + config: { + query_params: query_params, + headers: remove_headers(@headers.dup, 'Content-Type'), + options: @options + } ) end @@ -36,10 +38,12 @@ def http_post(relative_path = '', body = nil, query_params = nil, options = {}) send_request( proc { |path, config| self.class.post(path, config) }, relative_path, - query_params: query_params, - body: body, - headers: @headers.dup.merge(options[:headers] || {}), - options: @options.merge(options) + config: { + query_params: query_params, + body: body, + headers: @headers.dup.merge(options[:headers] || {}), + options: @options.merge(options) + } ) end @@ -47,10 +51,12 @@ def http_put(relative_path = '', body = nil, query_params = nil) send_request( proc { |path, config| self.class.put(path, config) }, relative_path, - query_params: query_params, - body: body, - headers: @headers, - options: @options + config: { + query_params: query_params, + body: body, + headers: @headers, + options: @options + } ) end @@ -58,10 +64,12 @@ def http_patch(relative_path = '', body = nil, query_params = nil) send_request( proc { |path, config| self.class.patch(path, config) }, relative_path, - query_params: query_params, - body: body, - headers: @headers, - options: @options + config: { + query_params: query_params, + body: body, + headers: @headers, + options: @options + } ) end @@ -69,8 +77,10 @@ def http_delete(relative_path = '') send_request( proc { |path, config| self.class.delete(path, config) }, relative_path, - headers: remove_headers(@headers.dup, 'Content-Type'), - options: @options + config: { + headers: remove_headers(@headers.dup, 'Content-Type'), + options: @options + } ) end @@ -88,13 +98,15 @@ def remove_headers(data, *keys) data.delete_if { |k| keys.include?(k) } end - def send_request(http_method, relative_path, query_params: nil, body: nil, options: {}, headers: {}) - config = http_config(query_params, body, options, headers) + def send_request(http_method, relative_path, config: {}) + config = http_config(config[:query_params], config[:body], config[:options], config[:headers]) + begin response = http_method.call(@base_url + relative_path, config) rescue Errno::ECONNREFUSED => e raise CommunicationError, e.message end + validate(response) end