diff --git a/lib/meilisearch/http_request.rb b/lib/meilisearch/http_request.rb index c8ab5d79..d26e162d 100644 --- a/lib/meilisearch/http_request.rb +++ b/lib/meilisearch/http_request.rb @@ -17,13 +17,17 @@ def initialize(url, api_key = nil, options = {}) 'Content-Type' => 'application/json', 'X-Meili-API-Key' => api_key }.compact + @headers_no_body = { + 'X-Meili-API-Key' => api_key + }.compact end def http_get(relative_path = '', query_params = {}) send_request( proc { |path, config| self.class.get(path, config) }, relative_path, - query_params + query_params: query_params, + headers: @headers_no_body ) end @@ -31,8 +35,9 @@ def http_post(relative_path = '', body = nil, query_params = nil) send_request( proc { |path, config| self.class.post(path, config) }, relative_path, - query_params, - body + query_params: query_params, + body: body, + headers: @headers ) end @@ -40,15 +45,17 @@ def http_put(relative_path = '', body = nil, query_params = nil) send_request( proc { |path, config| self.class.put(path, config) }, relative_path, - query_params, - body + query_params: query_params, + body: body, + headers: @headers ) end def http_delete(relative_path = '') send_request( proc { |path, config| self.class.delete(path, config) }, - relative_path + relative_path, + headers: @headers_no_body ) end @@ -56,8 +63,8 @@ def http_delete(relative_path = '') SNAKE_CASE = /[^a-zA-Z0-9]+(.)/.freeze - def send_request(http_method, relative_path, query_params = nil, body = nil) - config = http_config(query_params, body) + def send_request(http_method, relative_path, query_params: nil, body: nil, headers: nil) + config = http_config(query_params, body, headers) begin response = http_method.call(@base_url + relative_path, config) rescue Errno::ECONNREFUSED => e @@ -66,11 +73,10 @@ def send_request(http_method, relative_path, query_params = nil, body = nil) validate(response) end - def http_config(query_params, body) + def http_config(query_params, body, headers) body = transform_attributes(body).to_json - { - headers: @headers, + headers: headers, query: query_params, body: body, timeout: @options[:timeout] || 1, diff --git a/spec/meilisearch/index/base_spec.rb b/spec/meilisearch/index/base_spec.rb index abba158b..66c6aac2 100644 --- a/spec/meilisearch/index/base_spec.rb +++ b/spec/meilisearch/index/base_spec.rb @@ -62,7 +62,7 @@ expect(MeiliSearch::Index).to receive(:get).with( "#{URL}/indexes/options", { - headers: { 'Content-Type' => 'application/json', 'X-Meili-API-Key' => MASTER_KEY }, + headers: { 'X-Meili-API-Key' => MASTER_KEY }, body: 'null', query: {}, max_retries: 1,