Skip to content

Commit 4103452

Browse files
committed
add more examples
fix broken links in the example
1 parent caac50b commit 4103452

File tree

42 files changed

+459
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+459
-243
lines changed

README.md

Lines changed: 189 additions & 61 deletions
Large diffs are not rendered by default.

README.md.erb

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pp client.account
251251
```
252252

253253
It prints your account information as:
254-
``json
254+
```ruby
255255
{
256256
account_id: "1234567890",
257257
api_key: "your_secret_key",
@@ -274,124 +274,153 @@ It prints your account information as:
274274
## Basic example per search engine
275275

276276
### Search google
277+
277278
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_spec.rb') %>
278-
* doc: [https://serpapi.com/search-api](https://serpapi.com/search-api)
279+
see: [https://serpapi.com/search-api](https://serpapi.com/search-api)
280+
281+
### Search google light
282+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_light_spec.rb') %>
283+
see: [https://serpapi.com/google-light-api](https://serpapi.com/google-light-api)
279284

280285
### Search google scholar
281286
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_scholar_spec.rb') %>
282-
* doc: [https://serpapi.com/google-scholar-api](https://serpapi.com/google-scholar-api)
287+
see: [https://serpapi.com/google-scholar-api](https://serpapi.com/google-scholar-api)
283288

284289
### Search google autocomplete
285290
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_autocomplete_spec.rb') %>
286-
* doc: [https://serpapi.com/google-autocomplete-api](https://serpapi.com/google-autocomplete-api)
291+
see: [https://serpapi.com/google-autocomplete-api](https://serpapi.com/google-autocomplete-api)
287292

288293
### Search google product
289294
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_product_spec.rb') %>
290-
* doc: [https://serpapi.com/google-product-api](https://serpapi.com/google-product-api)
295+
see: [https://serpapi.com/google-product-api](https://serpapi.com/google-product-api)
291296

292297
### Search google reverse image
293298
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_reverse_image_spec.rb') %>
294-
* doc: [https://serpapi.com/google-reverse-image](https://serpapi.com/google-reverse-image)
299+
see: [https://serpapi.com/google-reverse-image](https://serpapi.com/google-reverse-image)
295300

296301
### Search google events
297302
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_events_spec.rb') %>
298-
* doc: [https://serpapi.com/google-events-api](https://serpapi.com/google-events-api)
303+
see: [https://serpapi.com/google-events-api](https://serpapi.com/google-events-api)
299304

300305
### Search google local services
301306
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_local_services_spec.rb') %>
302-
* doc: [https://serpapi.com/google-local-services-api](https://serpapi.com/google-local-services-api)
307+
see: [https://serpapi.com/google-local-services-api](https://serpapi.com/google-local-services-api)
303308

304309
### Search google maps
305310
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_maps_spec.rb') %>
306-
* doc: [https://serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)
311+
see: [https://serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)
307312

308313
### Search google jobs
309314
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_jobs_spec.rb') %>
310-
* doc: [https://serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
315+
see: [https://serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
311316

312317
### Search google play
313318
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_play_spec.rb') %>
314-
* doc: [https://serpapi.com/google-play-api](https://serpapi.com/google-play-api)
319+
see: [https://serpapi.com/google-play-api](https://serpapi.com/google-play-api)
315320

316321
### Search google images
317322
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_images_spec.rb') %>
318-
* doc: [https://serpapi.com/images-results](https://serpapi.com/images-results)
323+
see: [https://serpapi.com/images-results](https://serpapi.com/images-results)
319324

320325
### Search google lens
321326
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_lens_spec.rb') %>
322-
* doc: [https://serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)
327+
see: [https://serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)
323328

324329
### Search google images light
325330
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_images_light_spec.rb') %>
326-
* doc: [https://serpapi.com/google-images-light-api](https://serpapi.com/google-images-light-api)
331+
see: [https://serpapi.com/google-images-light-api](https://serpapi.com/google-images-light-api)
327332

328333
### Search google hotels
329334
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_hotels_spec.rb') %>
330-
* doc: [https://serpapi.com/google-hotels-api](https://serpapi.com/google-hotels-api)
335+
see: [https://serpapi.com/google-hotels-api](https://serpapi.com/google-hotels-api)
331336

332337
### Search google flights
333338
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_flights_spec.rb') %>
334-
* doc: [https://serpapi.com/google-flights-api](https://serpapi.com/google-flights-api)
339+
see: [https://serpapi.com/google-flights-api](https://serpapi.com/google-flights-api)
335340

336341
### Search google finance
337342
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_finance_spec.rb') %>
338-
* doc: [https://serpapi.com/google-finance-api](https://serpapi.com/google-finance-api)
343+
see: [https://serpapi.com/google-finance-api](https://serpapi.com/google-finance-api)
339344

340345
### Search google ai overview
341346
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_ai_overview_spec.rb') %>
342-
* doc: [https://serpapi.com/google-ai-overview-api](https://serpapi.com/google-ai-overview-api)
347+
see: [https://serpapi.com/google-ai-overview-api](https://serpapi.com/google-ai-overview-api)
343348

344349
### Search google news
345350
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_news_spec.rb') %>
346-
* doc: [https://serpapi.com/google-news-api](https://serpapi.com/google-news-api)
351+
see: [https://serpapi.com/google-news-api](https://serpapi.com/google-news-api)
352+
353+
### Search google news light
354+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_news_light_spec.rb') %>
355+
see: [https://serpapi.com/google-news-light-api](https://serpapi.com/google-news-light-api)
347356

348357
### Search google patents
349358
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_patents_spec.rb') %>
350-
* doc: [https://serpapi.com/google-patents-api](https://serpapi.com/google-patents-api)
359+
see: [https://serpapi.com/google-patents-api](https://serpapi.com/google-patents-api)
351360

352361
### Search google trends
353362
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_trends_spec.rb') %>
354-
* doc: [https://serpapi.com/google-trends-api](https://serpapi.com/google-trends-api)
363+
see: [https://serpapi.com/google-trends-api](https://serpapi.com/google-trends-api)
355364

356365
### Search google shopping
357366
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_shopping_spec.rb') %>
358-
* doc: [https://serpapi.com/google-shopping-api](https://serpapi.com/google-shopping-api)
367+
see: [https://serpapi.com/google-shopping-api](https://serpapi.com/google-shopping-api)
368+
369+
### Search google immersive product
370+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_immersive_product_spec.rb') %>
371+
see: [https://serpapi.com/google-immersive-product-api](https://serpapi.com/google-immersive-product-api)
372+
373+
### Search google videos
374+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_google_videos_spec.rb') %>
375+
see: [https://serpapi.com/google-videos-api](https://serpapi.com/google-videos-api)
376+
377+
### Search amazon
378+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_amazon_spec.rb') %>
379+
see: [https://serpapi.com/amazon-search-api](https://serpapi.com/amazon-search-api)
359380

360381
### Search baidu
361382
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_baidu_spec.rb') %>
362-
* doc: [https://serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api)
383+
see: [https://serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api)
363384

364385
### Search yahoo
365386
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_yahoo_spec.rb') %>
366-
* doc: [https://serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api)
387+
see: [https://serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api)
367388

368389
### Search youtube
369390
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_youtube_spec.rb') %>
370-
* doc: [https://serpapi.com/youtube-search-api](https://serpapi.com/youtube-search-api)
391+
see: [https://serpapi.com/youtube-search-api](https://serpapi.com/youtube-search-api)
371392

372393
### Search walmart
373394
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_walmart_spec.rb') %>
374-
* doc: [https://serpapi.com/walmart-search-api](https://serpapi.com/walmart-search-api)
395+
see: [https://serpapi.com/walmart-search-api](https://serpapi.com/walmart-search-api)
375396

376397
### Search ebay
377398
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_ebay_spec.rb') %>
378-
* doc: [https://serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)
399+
see: [https://serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)
379400

380401
### Search naver
381402
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_naver_spec.rb') %>
382-
* doc: [https://serpapi.com/naver-search-api](https://serpapi.com/naver-search-api)
403+
see: [https://serpapi.com/naver-search-api](https://serpapi.com/naver-search-api)
383404

384405
### Search home depot
385406
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_home_depot_spec.rb') %>
386-
* doc: [https://serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-search-api)
407+
see: [https://serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-search-api)
387408

388409
### Search apple app store
389410
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_apple_app_store_spec.rb') %>
390-
* doc: [https://serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)
411+
see: [https://serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)
391412

392413
### Search duckduckgo
393414
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_duckduckgo_spec.rb') %>
394-
* doc: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-search-api)
415+
see: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-search-api)
416+
417+
### Search yandex
418+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_yandex_spec.rb') %>
419+
see: [https://serpapi.com/yandex-search-api](https://serpapi.com/yandex-search-api)
420+
421+
### Search yelp
422+
<%= snippet('ruby', 'spec/serpapi/client/example/example_search_yelp_spec.rb') %>
423+
see: [https://serpapi.com/yelp-search-api](https://serpapi.com/yelp-search-api)
395424

396425
## Migration quick guide
397426

README_ruby_EXAMPLE_SECTION.md

Lines changed: 0 additions & 119 deletions
This file was deleted.

lib/serpapi/error.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Module includes SerpApi exception
1+
# Module includes SerpApi error handling.
2+
# frozen_string_literal: true
23
module SerpApi
3-
# SerpApiException wraps any errors related to the SerpApi client.
4+
# SerpApiError wraps any errors related to the SerpApi client.
45
class SerpApiError < StandardError
56
# List the specific types of errors handled by the Error class.
67
# - HTTP response errors from SerpApi.com
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper'
2+
3+
describe 'example: amazon search' do
4+
it 'prints organic_results' do
5+
# Confirm that the environment variable for SERPAPI_KEY has been set properly.
6+
# Your SerpApi key can be obtained at this URL http://serpapi.com
7+
api_key = ENV['SERPAPI_KEY']
8+
skip('SERPAPI_KEY not set. Please set your SerpApi API key.') if api_key.nil?
9+
10+
# initialize the serp api client
11+
client = SerpApi::Client.new(engine: 'amazon', api_key: api_key)
12+
# run a search using serpapi service
13+
results = client.search({
14+
q: 'coffee'
15+
})
16+
expect(results[:organic_results]).not_to be_nil, "No organic results found! keys available: #{results.keys}"
17+
18+
# print the output of the response in formatted JSON
19+
# pp results[:organic_results]
20+
# doc: https://serpapi.com/amazon-search-api
21+
end
22+
end

spec/serpapi/client/example/example_search_apple_app_store_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
# print the output of the response in formatted JSON
1919
# pp results[:organic_results]
20-
# doc: https://serpapi.com/apple_app_store
20+
# doc: https://serpapi.com/apple-app-store
2121
end
2222
end

spec/serpapi/client/example/example_search_baidu_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
# print the output of the response in formatted JSON
1919
# pp results[:organic_results]
20-
# doc: https://serpapi.com/baidu
20+
# doc: https://serpapi.com/baidu-search-api
2121
end
2222
end

spec/serpapi/client/example/example_search_duckduckgo_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
# print the output of the response in formatted JSON
1919
# pp results[:organic_results]
20-
# doc: https://serpapi.com/duckduckgo
20+
# doc: https://serpapi.com/duckduckgo-search-api
2121
end
2222
end

spec/serpapi/client/example/example_search_ebay_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
# print the output of the response in formatted JSON
1919
# pp results[:organic_results]
20-
# doc: https://serpapi.com/ebay
20+
# doc: https://serpapi.com/ebay-search-api
2121
end
2222
end

spec/serpapi/client/example/example_search_google_ai_overview_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
# print the output of the response in formatted JSON
1919
# pp results[:ai_overview]
20-
# doc: https://serpapi.com/google_ai_overview
20+
# doc: https://serpapi.com/google-ai-overview-api
2121
end
2222
end

0 commit comments

Comments
 (0)