@@ -17,47 +17,54 @@ def initialize(url, api_key = nil, options = {})
1717 'Content-Type' => 'application/json' ,
1818 'X-Meili-API-Key' => api_key
1919 } . compact
20+ @headers_no_body = {
21+ 'X-Meili-API-Key' => api_key
22+ } . compact
2023 end
2124
2225 def http_get ( relative_path = '' , query_params = { } )
2326 send_request (
2427 proc { |path , config | self . class . get ( path , config ) } ,
2528 relative_path ,
26- query_params
29+ query_params : query_params ,
30+ headers : @headers_no_body
2731 )
2832 end
2933
3034 def http_post ( relative_path = '' , body = nil , query_params = nil )
3135 send_request (
3236 proc { |path , config | self . class . post ( path , config ) } ,
3337 relative_path ,
34- query_params ,
35- body
38+ query_params : query_params ,
39+ body : body ,
40+ headers : @headers
3641 )
3742 end
3843
3944 def http_put ( relative_path = '' , body = nil , query_params = nil )
4045 send_request (
4146 proc { |path , config | self . class . put ( path , config ) } ,
4247 relative_path ,
43- query_params ,
44- body
48+ query_params : query_params ,
49+ body : body ,
50+ headers : @headers
4551 )
4652 end
4753
4854 def http_delete ( relative_path = '' )
4955 send_request (
5056 proc { |path , config | self . class . delete ( path , config ) } ,
51- relative_path
57+ relative_path ,
58+ headers : @headers_no_body
5259 )
5360 end
5461
5562 private
5663
5764 SNAKE_CASE = /[^a-zA-Z0-9]+(.)/ . freeze
5865
59- def send_request ( http_method , relative_path , query_params = nil , body = nil )
60- config = http_config ( query_params , body )
66+ def send_request ( http_method , relative_path , query_params : nil , body : nil , headers : nil )
67+ config = http_config ( query_params , body , headers )
6168 begin
6269 response = http_method . call ( @base_url + relative_path , config )
6370 rescue Errno ::ECONNREFUSED => e
@@ -66,11 +73,10 @@ def send_request(http_method, relative_path, query_params = nil, body = nil)
6673 validate ( response )
6774 end
6875
69- def http_config ( query_params , body )
76+ def http_config ( query_params , body , headers )
7077 body = transform_attributes ( body ) . to_json
71-
7278 {
73- headers : @ headers,
79+ headers : headers ,
7480 query : query_params ,
7581 body : body ,
7682 timeout : @options [ :timeout ] || 1 ,
0 commit comments