Project

searchapi

0.0
No release in over 3 years
A Ruby client for the SearchApi.io API. Supports various services including Google Search, YouTube, Instagram, TikTok, Google Finance, Google Flights, Google News, Google Images, Google Scholar, and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.9
~> 5.25
~> 6.3

Runtime

 Project Readme

SearchAPI Ruby Gem

A Ruby client for the SearchAPI.io API, providing access to Google Search, YouTube, Instagram, TikTok, and more.

Installation

Add to your Gemfile:

gem 'searchapi'

Or install directly:

gem install searchapi

Configuration

require 'searchapi'

SearchAPI.api_key ENV['SEARCH_API_KEY']

Available APIs

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
Instagram SearchAPI.instagram(username) Instagram profile data
TikTok SearchAPI.tiktok(username) TikTok profile data

Quick Examples

Google Search

response = SearchAPI.google('ruby programming')
response.result.organic_results.each do |result|
  puts "#{ result.title } - #{ result.link }"
end

Google News

response = SearchAPI.news('technology', time_period: :last_week)
response.result.each do |article|
  puts "#{ article.title } (#{ article.source })"
end

Google Images

response = SearchAPI.images('sunset', size: :large, color: :orange)
response.result.each do |image|
  puts "#{ image.title } - #{ image.original.link }"
end

Google Finance

response = SearchAPI.finance('AAPL:NASDAQ')
puts "#{ response.result.summary.title }: $#{ response.result.summary.price }"

Google Flights

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 }"

YouTube Search

response = SearchAPI.youtube('ruby tutorial')
response.result.videos.each do |video|
  puts "#{ video.title } by #{ video.channel.title }"
end

Social Media Profiles

# 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"

Using Options

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'

Response Structure

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_results

Results 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 results

Documentation

See the /readme directory for detailed documentation on each API endpoint.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/EndlessInternational/searchapi.

License

The gem is available as open source under the terms of the MIT License.