Skip to content

Commit

Permalink
Fix rubocop Metrics/ParameterLists
Browse files Browse the repository at this point in the history
* Avoid parameter lists longer than 5 parameters. [6/5]
  • Loading branch information
brunoocasali committed Jan 25, 2022
1 parent 019b083 commit 436af86
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions lib/meilisearch/http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,61 @@ 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

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

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

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

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

Expand All @@ -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

Expand Down

0 comments on commit 436af86

Please sign in to comment.