A Ruby client for the SearchApi.io API, providing access to Google Search, YouTube, Instagram, TikTok, and more.
Add to your Gemfile:
gem 'searchapi'Or install directly:
gem install searchapirequire 'searchapi'
SearchApi.api_key ENV['SEARCH_API_KEY']| API | Method | Description |
|---|---|---|
| Google Search | SearchApi.google(query) |
Full Google search with all features |
| Google Light | SearchApi.google_light(query) |
Fast, lightweight Google search |
| Google News | SearchApi.news(query) |
Google News articles |
| Google News Portal | SearchApi.news_portal(query) |
Google News Portal with topics |
| Google News Light | SearchApi.news_light(query) |
Fast, lightweight news search |
| Google Images | SearchApi.images(query) |
Google Image search |
| Google Local | SearchApi.local(query) |
Local business search |
| Google Scholar | SearchApi.scholar(query) |
Academic papers and citations |
| Google Finance | SearchApi.finance(symbol) |
Stock quotes and financial data |
| Google Flights | SearchApi.flights(options) |
Flight search and booking |
| YouTube | SearchApi.youtube(query) |
YouTube video search |
SearchApi.instagram(username) |
Instagram profile data | |
| TikTok | SearchApi.tiktok(username) |
TikTok profile data |
response = SearchApi.google('ruby programming')
response.result.organic_results.each do |result|
puts "#{ result.title } - #{ result.link }"
endresponse = SearchApi.news('technology', time_period: :last_week)
response.result.each do |article|
puts "#{ article.title } (#{ article.source })"
endresponse = SearchApi.images('sunset', size: :large, color: :orange)
response.result.each do |image|
puts "#{ image.title } - #{ image.original.link }"
endresponse = SearchApi.finance('AAPL:NASDAQ')
puts "#{ response.result.summary.title }: $#{ response.result.summary.price }"options = SearchApi::GoogleFlightsOptions.build do
departure_id 'JFK'
arrival_id 'LAX'
outbound_date '2026-06-15'
flight_type :one_way
end
response = SearchApi.flights(options)
puts "Cheapest: $#{ response.result.cheapest&.price }"response = SearchApi.youtube('ruby tutorial')
response.result.videos.each do |video|
puts "#{ video.title } by #{ video.channel.title }"
end# Instagram
response = SearchApi.instagram('instagram')
puts "#{ response.result.profile.username }: #{ response.result.followers } followers"
# TikTok
response = SearchApi.tiktok('tiktok')
puts "#{ response.result.profile.name }: #{ response.result.hearts } hearts"Each API supports options via a block or hash:
# Block syntax
options = SearchApi::GoogleSearchOptions.build do
device :mobile
gl 'us'
hl 'en'
time_period :last_week
end
response = SearchApi.google('news', options)
# Hash syntax
response = SearchApi.google('news', { device: :mobile, gl: 'us' })Options are case-insensitive and normalized automatically:
# These are equivalent
SearchApi::GoogleFinanceOptions.build { window :'1d' } # => '1D'
SearchApi::GoogleFinanceOptions.build { window :'1D' } # => '1D'
SearchApi::GoogleFinanceOptions.build { window :MAX } # => 'MAX'All responses return a Faraday response with a result accessor:
response = SearchApi.google('test')
response.success? # HTTP success
response.result.success? # API success (no error field)
response.result.search_metadata
response.result.search_parameters
response.result.organic_resultsResults are enumerable where it makes sense:
response = SearchApi.google('ruby')
response.result.each { |r| puts r.title } # Iterates organic_results
response.result.first # First organic result
response.result.count # Number of organic resultsSee the /readme directory for detailed documentation on each API endpoint.
Bug reports and pull requests are welcome on GitHub at https://github.com/EndlessInternational/searchapi.
The gem is available as open source under the terms of the MIT License.