Skip to content

A Ruby client for the SearchAPI.io API, supporting various services including Google Search, YouTube, Instagram, and others.

Notifications You must be signed in to change notification settings

EndlessInternational/searchapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Ruby client for the SearchAPI.io API, supporting various services including Google Search, YouTube, Instagram, and others.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages