Skip to content

Commit 82a50db

Browse files
committed
user query structure changed
1 parent eb449fd commit 82a50db

2 files changed

Lines changed: 141 additions & 26 deletions

File tree

‎examples/Businesses.md‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,91 @@ When both structured params and `query` are provided:
9595
- for `limit`, `cursor`, and `include_total`, plain-text values take priority when present
9696
- if a value is not specified, API defaults are used
9797

98+
### Search businesses with enrichments
99+
100+
`enrichments` can be provided in three formats:
101+
102+
- **Hash (recommended)** — send a structured object with options per enrichment
103+
- **Array** — enable enrichments without options
104+
- **String** — enable a single enrichment without options
105+
106+
#### Enrichments as Hash (recommended)
107+
108+
```ruby
109+
results = client.businessesSearch(
110+
filters: {
111+
country_code: "US",
112+
states: ["CA", "NY"],
113+
types: ["restaurant", "cafe"]
114+
},
115+
limit: 10,
116+
fields: ["name", "phone", "website", "rating", "reviews"],
117+
enrichments: {
118+
"contacts_n_leads" => {
119+
"contacts_per_company" => 4,
120+
"emails_per_contact" => 2
121+
},
122+
"company_insights" => {}
123+
}
124+
)
125+
126+
puts results
127+
```
128+
129+
#### Enrichments as Array
130+
131+
```ruby
132+
results = client.businessesSearch(
133+
filters: { country_code: "US", states: ["NY"] },
134+
limit: 10,
135+
enrichments: ["contacts_n_leads", "company_insights"]
136+
)
137+
138+
puts results
139+
```
140+
141+
#### Enrichments as String
142+
143+
```ruby
144+
results = client.businessesSearch(
145+
filters: { country_code: "US", states: ["NY"] },
146+
limit: 10,
147+
enrichments: "contacts_n_leads"
148+
)
149+
150+
puts results
151+
```
152+
153+
#### Full JSON-style parameters example
154+
155+
```ruby
156+
params = {
157+
filters: {
158+
country_code: "US",
159+
states: ["CA", "NY"],
160+
types: ["restaurant", "cafe"]
161+
},
162+
limit: 900,
163+
cursor: nil,
164+
include_total: false,
165+
fields: [
166+
"name", "types", "address", "country", "website",
167+
"phone", "rating", "reviews"
168+
],
169+
enrichments: {
170+
"contacts_n_leads" => {
171+
"contacts_per_company" => 4,
172+
"emails_per_contact" => 2
173+
},
174+
"company_insights" => {}
175+
},
176+
query: "Find hotels in California and Illinois with rating 4.2+ and status operational. Return fields: name, address, rating and reviews. Limit results to 6. Enrich data with contacts_n_leads. Contact per company set to 8"
177+
}
178+
179+
results = client.businessesSearch(**params)
180+
puts results
181+
```
182+
98183
### Iterate through all results (auto-pagination)
99184

100185
```ruby

‎lib/outscraper.rb‎

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def company_website_finder(query, fields: '', async_request: false)
378378
async: async_request
379379
}).parsed_response['data']
380380
end
381-
381+
382382
def yellowpages_search(query, location: 'New York, NY', limit: 100, region: nil, enrichment: [], fields: '', async_request: false, ui: nil, webhook: nil)
383383
enrichment_array = enrichment.is_a?(Array) ? enrichment : [enrichment]
384384
response = self.class.get('/yellowpages-search', query: {
@@ -428,34 +428,64 @@ def businessesSearch(
428428
raise ArgumentError, 'emails_per_contact must be >= 1'
429429
end
430430

431-
enrichments_payload =
432-
if enrichments.nil?
433-
[]
434-
else
435-
Array(enrichments)
436-
end
431+
enrichments_normalized = nil
437432

438-
payload = {
439-
filters: (filters || {}),
440-
limit: limit,
441-
include_total: include_total,
442-
cursor: cursor,
443-
fields: fields ? Array(fields) : nil,
444-
enrichments: enrichments_payload.empty? ? nil : enrichments_payload,
445-
query: query,
446-
async: async_request,
447-
ui: ui,
448-
webhook: webhook
449-
}.compact
433+
if enrichments.is_a?(Hash)
434+
enrichments_normalized = enrichments
435+
elsif enrichments.is_a?(Array)
436+
enrichments_normalized = enrichments
437+
elsif enrichments.is_a?(String) || enrichments.is_a?(Symbol)
438+
enrichments_normalized = enrichments.to_s
439+
elsif !enrichments.nil?
440+
enrichments_normalized = Array(enrichments)
441+
end
450442

451-
if enrichments_payload.include?('contacts_n_leads')
452-
payload[:contacts_per_company] = contacts_per_company || 3
453-
payload[:emails_per_contact] = emails_per_contact || 1
454-
elsif !contacts_per_company.nil? || !emails_per_contact.nil?
455-
raise ArgumentError, 'contacts_per_company and emails_per_contact require enrichments to include "contacts_n_leads"'
456-
end
443+
if !contacts_per_company.nil? || !emails_per_contact.nil?
444+
cpp = contacts_per_company || 3
445+
epc = emails_per_contact || 1
446+
447+
case enrichments_normalized
448+
when nil
449+
enrichments_normalized = { 'contacts_n_leads' => { 'contacts_per_company' => cpp, 'emails_per_contact' => epc } }
450+
when Hash
451+
enrichments_normalized['contacts_n_leads'] ||= {}
452+
enrichments_normalized['contacts_n_leads']['contacts_per_company'] = cpp
453+
enrichments_normalized['contacts_n_leads']['emails_per_contact'] = epc
454+
when Array
455+
unless enrichments_normalized.map(&:to_s).include?('contacts_n_leads')
456+
raise ArgumentError, 'contacts_per_company and emails_per_contact require enrichments to include "contacts_n_leads"'
457+
end
458+
# Expand array to object so we can include options
459+
expanded = {}
460+
enrichments_normalized.each { |name| expanded[name.to_s] = {} }
461+
expanded['contacts_n_leads']['contacts_per_company'] = cpp
462+
expanded['contacts_n_leads']['emails_per_contact'] = epc
463+
enrichments_normalized = expanded
464+
when String
465+
unless enrichments_normalized == 'contacts_n_leads'
466+
raise ArgumentError, 'contacts_per_company and emails_per_contact require enrichments to include "contacts_n_leads"'
467+
end
468+
enrichments_normalized = { 'contacts_n_leads' => { 'contacts_per_company' => cpp, 'emails_per_contact' => epc } }
469+
else
470+
raise ArgumentError, 'Invalid enrichments type'
471+
end
472+
end
473+
474+
payload = {
475+
filters: (filters || {}),
476+
limit: limit,
477+
include_total: include_total,
478+
cursor: cursor,
479+
fields: fields ? Array(fields) : nil,
480+
enrichments: enrichments_normalized,
481+
query: query,
482+
async: async_request,
483+
ui: ui,
484+
webhook: webhook
485+
}.compact
486+
487+
postAPIRequest('/businesses', payload)
457488

458-
postAPIRequest('/businesses', payload)
459489
end
460490

461491
def businessesIterSearch(

0 commit comments

Comments
 (0)