|
| 1 | +# Businesses Search With Ruby |
| 2 | + |
| 3 | +The library provides real-time access to business records via the [Outscraper API](https://app.outscraper.com/api-docs). |
| 4 | +It supports classic structured filters and AI-powered plain-text queries for flexible search. |
| 5 | + |
| 6 | +- Structured search using `filters`, `fields`, `limit`, and other parameters |
| 7 | +- AI-powered search using the `query` parameter |
| 8 | +- Combined mode where structured params and `query` are merged by the server |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Install the gem and add it to the application's Gemfile by executing: |
| 15 | + |
| 16 | +```bash |
| 17 | +bundle add outscraper |
| 18 | +``` |
| 19 | + |
| 20 | +If bundler is not being used to manage dependencies, install the gem by executing: |
| 21 | + |
| 22 | +```bash |
| 23 | +gem install outscraper |
| 24 | +``` |
| 25 | + |
| 26 | +[Link to the Ruby package page](https://rubygems.org/gems/outscraper) |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## Initialization |
| 31 | + |
| 32 | +```ruby |
| 33 | +require "outscraper" |
| 34 | + |
| 35 | +client = Outscraper::Client.new("SECRET_API_KEY") |
| 36 | +``` |
| 37 | + |
| 38 | +[Link to the profile page to create the API key](https://app.outscraper.com/profile) |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +### Search businesses with structured filters |
| 45 | + |
| 46 | +```ruby |
| 47 | +results = client.businessesSearch( |
| 48 | + filters: { |
| 49 | + country_code: "US", |
| 50 | + states: ["NY"], |
| 51 | + cities: ["New York", "Buffalo"], |
| 52 | + types: ["restaurant", "cafe"], |
| 53 | + has_website: true, |
| 54 | + has_phone: true, |
| 55 | + business_statuses: ["operational"] |
| 56 | + }, |
| 57 | + limit: 50, |
| 58 | + include_total: false, |
| 59 | + fields: ["name", "phone", "website", "address", "rating", "reviews"] |
| 60 | +) |
| 61 | + |
| 62 | +puts results |
| 63 | +``` |
| 64 | + |
| 65 | +### Search businesses with AI plain-text query |
| 66 | + |
| 67 | +```ruby |
| 68 | +results = client.businessesSearch( |
| 69 | + query: "Find cafes in New York, NY. Limit 25. Return name, address, phone, website, rating and reviews." |
| 70 | +) |
| 71 | + |
| 72 | +puts results |
| 73 | +``` |
| 74 | + |
| 75 | +### Combine structured params and plain-text query |
| 76 | + |
| 77 | +```ruby |
| 78 | +results = client.businessesSearch( |
| 79 | + filters: { |
| 80 | + country_code: "US", |
| 81 | + states: ["CA"], |
| 82 | + types: ["restaurant"] |
| 83 | + }, |
| 84 | + fields: ["name", "phone"], |
| 85 | + limit: 15, |
| 86 | + query: "Add cafes too. Return address and reviews. Limit 20. Include total." |
| 87 | +) |
| 88 | + |
| 89 | +puts results |
| 90 | +``` |
| 91 | + |
| 92 | +When both structured params and `query` are provided: |
| 93 | + |
| 94 | +- `filters` and `fields` are merged |
| 95 | +- for `limit`, `cursor`, and `include_total`, plain-text values take priority when present |
| 96 | +- if a value is not specified, API defaults are used |
| 97 | + |
| 98 | +### Iterate through all results (auto-pagination) |
| 99 | + |
| 100 | +```ruby |
| 101 | +items = client.businessesIterSearch( |
| 102 | + filters: { |
| 103 | + country_code: "US", |
| 104 | + states: ["NY"], |
| 105 | + business_statuses: ["operational"] |
| 106 | + }, |
| 107 | + limit: 100, |
| 108 | + fields: ["name", "phone", "address", "rating", "reviews"] |
| 109 | +) |
| 110 | + |
| 111 | +puts items.length |
| 112 | +``` |
| 113 | + |
| 114 | +### Get business details by ID |
| 115 | + |
| 116 | +```ruby |
| 117 | +business = client.businessesGet( |
| 118 | + "YOUR_BUSINESS_ID", |
| 119 | + fields: ["name", "phone", "website", "address", "rating", "reviews"] |
| 120 | +) |
| 121 | + |
| 122 | +puts business |
| 123 | +``` |
0 commit comments