Skip to content

Commit a4a4c05

Browse files
committed
fix minor lint issues
1 parent d641afd commit a4a4c05

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

.rubocop.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ Style/SymbolArray:
2222
Style/FrozenStringLiteralComment:
2323
Enabled: false
2424

25+
# default complexity is low at 8
26+
Metrics/PerceivedComplexity:
27+
Max: 10
28+
29+
# if works as well as safe navigation (&.)
30+
Style/SafeNavigation:
31+
Enabled: false
32+
33+
2534
AllCops:
2635
NewCops: enable
2736
Exclude:

lib/serpapi/client.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module SerpApi
44
# Client for SerpApi.com
55
#
66
class Client
7-
87
# Backend service URL
98
BACKEND = 'serpapi.com'.freeze
109

@@ -43,7 +42,7 @@ def initialize(params = {})
4342
@persistent.freeze
4443

4544
# delete this client only configuration keys
46-
%i(timeout persistent).each do |option|
45+
%i[timeout persistent].each do |option|
4746
params.delete(option) if params.key?(option)
4847
end
4948

@@ -56,9 +55,9 @@ def initialize(params = {})
5655
@params.freeze
5756

5857
# create connection socket
59-
if persistent?
60-
@socket = HTTP.persistent("https://#{BACKEND}")
61-
end
58+
return unless persistent?
59+
60+
@socket = HTTP.persistent("https://#{BACKEND}")
6261
end
6362

6463
# perform a search using SerpApi.com
@@ -119,7 +118,7 @@ def api_key
119118
@params[:api_key]
120119
end
121120

122-
# close open connection
121+
# close open connection
123122
def close
124123
@socket.close if @socket
125124
end
@@ -148,13 +147,13 @@ def persistent?
148147
# @param [Boolean] symbolize_names if true, convert JSON keys to symbols
149148
# @return decoded response as JSON / Hash or String
150149
def get(endpoint, decoder = :json, params = {}, symbolize_names = true)
151-
# execute get via open socket
152-
if persistent?
153-
response = @socket.get(endpoint, params: query(params))
154-
else
155-
response = HTTP.timeout(timeout).get("https://#{BACKEND}#{endpoint}", params: query(params))
156-
end
157-
150+
# execute get via open socket
151+
response = if persistent?
152+
@socket.get(endpoint, params: query(params))
153+
else
154+
HTTP.timeout(timeout).get("https://#{BACKEND}#{endpoint}", params: query(params))
155+
end
156+
158157
# decode response using JSON native parser
159158
case decoder
160159
when :json
@@ -163,15 +162,15 @@ def get(endpoint, decoder = :json, params = {}, symbolize_names = true)
163162
if data.instance_of?(Hash) && data.key?(:error)
164163
raise SerpApiError, "HTTP request failed with error: #{data[:error]} from url: https://#{BACKEND}#{endpoint}, params: #{params}, decoder: #{decoder}, response status: #{response.status} "
165164
elsif response.status != 200
166-
raise SerpApiError, "HTTP request failed with response status: #{response.status} reponse: #{data} on get url: https://#{BACKEND}#{endpoint}, params: #{params}, decoder: #{decoder}"
165+
raise SerpApiError, "HTTP request failed with response status: #{response.status} reponse: #{data} on get url: https://#{BACKEND}#{endpoint}, params: #{params}, decoder: #{decoder}"
167166
end
168167

169168
# discard response body
170169
response.flush if persistent?
171170

172-
return data
171+
data
173172
else
174-
return response.body
173+
response.body
175174
end
176175
end
177176
end

lib/serpapi/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Module includes SerpApi exception
2-
module SerpApi
2+
module SerpApi
33
# SerpApiException wraps any errors related to the SerpApi client.
44
class SerpApiError < StandardError
55
# List the specific types of errors handled by the Error class.

0 commit comments

Comments
 (0)