Skip to content

Commit 04a05f2

Browse files
authored
add query param (#9)
1 parent 6048241 commit 04a05f2

3 files changed

Lines changed: 127 additions & 2 deletions

File tree

examples/Businesses.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
```

lib/outscraper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,16 @@ def businessesSearch(
414414
fields: nil,
415415
async_request: false,
416416
ui: false,
417-
webhook: nil
417+
webhook: nil,
418+
query: nil
418419
)
419420
payload = {
420421
filters: (filters || {}),
421422
limit: limit,
422423
include_total: include_total,
423424
cursor: cursor,
424425
fields: fields ? Array(fields) : nil,
426+
query: query,
425427
async: async_request,
426428
ui: ui,
427429
webhook: webhook

lib/outscraper/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Outscraper
4-
VERSION = "0.3.5"
4+
VERSION = "0.3.6"
55
end

0 commit comments

Comments
 (0)