Skip to content

Commit e09e5ae

Browse files
committed
fix constructor declaration style in doc and demo to align with Ruby style guide
1 parent c3f30dc commit e09e5ae

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ Here is an example of asynchronous searches using Ruby
125125
require 'serpapi'
126126

127127
company_list = %w[meta amazon apple netflix google]
128-
client = SerpApi::Client.new(engine: 'google', async: true, persistent: true, api_key: ENV.fetch('SERPAPI_KEY', nil))
128+
client = SerpApi::Client.new(engine: 'google', async: true, persistent: true, api_key: ENV['SERPAPI_KEY'])
129129
schedule_search = Queue.new
130130
result = nil
131131
company_list.each do |company|
132-
result = client.search({ q: company })
132+
result = client.search(q: company)
133133
puts "#{company}: search results found in cache for: #{company}" if result[:search_metadata][:status] =~ /Cached/
134134

135135
schedule_search.push(result[:search_metadata][:id])
@@ -208,7 +208,7 @@ require 'serpapi'
208208

209209
require 'pp'
210210

211-
client = SerpApi::Client.new({api_key: ENV['SERPAPI_KEY']})
211+
client = SerpApi::Client.new(api_key: ENV['SERPAPI_KEY'])
212212
params = {
213213
q: 'coffee'
214214
}
@@ -229,7 +229,7 @@ exit 0
229229

230230
```ruby
231231
require 'serpapi'
232-
client = SerpApi::Client.new()
232+
client = SerpApi::Client.new
233233
location_list = client.location(q: "Austin", limit: 3)
234234
puts "number of location: #{location_list.size}"
235235
pp location_list

README.md.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ Here is an example of asynchronous searches using Ruby
145145
require 'serpapi'
146146

147147
company_list = %w[meta amazon apple netflix google]
148-
client = SerpApi::Client.new(engine: 'google', async: true, persistent: true, api_key: ENV.fetch('SERPAPI_KEY', nil))
148+
client = SerpApi::Client.new(engine: 'google', async: true, persistent: true, api_key: ENV['SERPAPI_KEY'])
149149
schedule_search = Queue.new
150150
result = nil
151151
company_list.each do |company|
152-
result = client.search({ q: company })
152+
result = client.search(q: company)
153153
puts "#{company}: search results found in cache for: #{company}" if result[:search_metadata][:status] =~ /Cached/
154154

155155
schedule_search.push(result[:search_metadata][:id])
@@ -228,7 +228,7 @@ require 'serpapi'
228228

229229
require 'pp'
230230

231-
client = SerpApi::Client.new({api_key: ENV['SERPAPI_KEY']})
231+
client = SerpApi::Client.new(api_key: ENV['SERPAPI_KEY'])
232232
params = {
233233
q: 'coffee'
234234
}
@@ -249,7 +249,7 @@ exit 0
249249

250250
```ruby
251251
require 'serpapi'
252-
client = SerpApi::Client.new()
252+
client = SerpApi::Client.new
253253
location_list = client.location(q: "Austin", limit: 3)
254254
puts "number of location: #{location_list.size}"
255255
pp location_list

demo/demo.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
require 'serpapi'
1111

1212
# client initialization with default parameters
13-
client = SerpApi::Client.new({
14-
engine: 'google',
15-
api_key: ENV['SERPAPI_KEY']
16-
})
13+
client = SerpApi::Client.new(
14+
engine: 'google',
15+
api_key: ENV['SERPAPI_KEY']
16+
)
1717
# search for coffee
1818
results = client.search(q: 'coffee')
1919
unless results[:organic_results]

demo/demo_async.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232

3333
# target MAANG companies
3434
company_list = %w[meta amazon apple netflix google]
35-
client = SerpApi::Client.new(engine: 'google', async: true, persistent: true, api_key: ENV.fetch('SERPAPI_KEY', nil))
35+
client = SerpApi::Client.new(
36+
engine: 'google',
37+
async: true,
38+
persistent: true,
39+
api_key: ENV['SERPAPI_KEY']
40+
)
3641
schedule_search = Queue.new
3742
result = nil
3843
company_list.each do |company|

demo/demo_suggest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
raise 'SERPAPI_KEY environment variable must be set' if ENV['SERPAPI_KEY'].nil?
1919

2020
# client initialization with default parameters for Google Autocomplete
21-
client = SerpApi::Client.new({
21+
client = SerpApi::Client.new(
2222
engine: 'google_autocomplete',
2323
client: 'safari',
2424
hl: 'en', # language
2525
gl: 'us', # country
2626
api_key: ENV['SERPAPI_KEY'], # API key from environment variable
2727
persistent: false,
2828
timeout: 2
29-
})
29+
)
3030
params = {
3131
q: 'coffee'
3232
}

demo/demo_thread_pool.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@
6060
runtime = Benchmark.measure do
6161
# create a thread pool of 4 threads with a persistent connection to serpapi.com
6262
pool = ConnectionPool.new(size: n, timeout: 5) do
63-
SerpApi::Client.new(engine: 'google', api_key: ENV.fetch('SERPAPI_KEY', nil), timeout: 30, persistent: true)
63+
SerpApi::Client.new(engine: 'google',
64+
api_key: ENV['SERPAPI_KEY'],
65+
timeout: 30,
66+
persistent: true)
6467
end
6568

6669
# run user thread to search for your favorites coffee type

0 commit comments

Comments
 (0)