Class: Outscraper::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/outscraper.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



27
28
29
# File 'lib/outscraper.rb', line 27

def initialize(api_key)
  self.class.headers 'X-API-KEY' => api_key, 'Accept-Encoding' => 'utf-8'
end

Instance Method Details

#address_scraper(query, async_request: false) ⇒ Object



321
322
323
324
325
326
# File 'lib/outscraper.rb', line 321

def address_scraper(query, async_request: false)
  response = self.class.get('/whitepages-addresses', query: {
    query: query.is_a?(Array) ? query : [query],
    async: async_request
  }).parsed_response['data']
end

#amazon_products(query, limit: 24, domain: 'amazon.com', postal_code: '11201', fields: nil, async_request: false) ⇒ Object



180
181
182
183
184
185
186
187
188
189
# File 'lib/outscraper.rb', line 180

def amazon_products(query, limit: 24, domain: 'amazon.com', postal_code: '11201', fields: nil, async_request: false)
  response = self.class.get('/amazon/products-v2', query: {
    query: query,
    limit: limit,
    domain: domain,
    postal_code: postal_code,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#amazon_reviews(query, limit: 10, sort: 'helpful', filter_by_reviewer: 'all_reviews', filter_by_star: 'all_stars', domain: nil, fields: nil, async_request: false) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/outscraper.rb', line 191

def amazon_reviews(query, limit: 10, sort: 'helpful', filter_by_reviewer: 'all_reviews', filter_by_star: 'all_stars', domain: nil, fields: nil, async_request: false)
  response = self.class.get('/amazon/reviews', query: {
    query: query,
    limit: limit,
    sort: sort,
    filterByReviewer: filter_by_reviewer,
    filterByStar: filter_by_star,
    domain: domain,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#app_store_reviews(query, limit: 100, sort: 'mosthelpful', cutoff: nil, fields: '', async_request: false) ⇒ Object



232
233
234
235
236
237
238
239
240
241
# File 'lib/outscraper.rb', line 232

def app_store_reviews(query, limit: 100, sort: 'mosthelpful', cutoff: nil, fields: '', async_request: false)
  response = self.class.get('/appstore/reviews', query: {
    query: query,
    limit: limit,
    sort: sort,
    cutoff: cutoff,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#businessesGet(business_id, fields: nil, async_request: false, ui: false, webhook: nil) ⇒ Object

Raises:

  • (ArgumentError)


533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/outscraper.rb', line 533

def businessesGet(business_id, fields: nil, async_request: false, ui: false, webhook: nil)
  raise ArgumentError, 'business_id is required' if business_id.nil? || business_id.to_s.strip.empty?

  fields_param =
    if fields.is_a?(Array)
      fields.map(&:to_s).join(',')
    else
      fields
    end

  response = self.class.get("/businesses/#{CGI.escape(business_id.to_s)}", query: {
    fields: fields_param,
    async: async_request,
    ui: ui,
    webhook: webhook
  }.compact).parsed_response
  response.is_a?(Hash) && response.key?('data') ? response['data'] : response
end

#businessesIterSearch(filters: {}, limit: 10, fields: nil, include_total: false, enrichments: nil, contacts_per_company: nil, emails_per_contact: nil, query: nil) ⇒ Object



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/outscraper.rb', line 491

def businessesIterSearch(
  filters: {},
  limit: 10,
  fields: nil,
  include_total: false,
  enrichments: nil,
  contacts_per_company: nil,
  emails_per_contact: nil,
  query: nil
)
  cursor = nil
  all_items = []

  loop do
    page = businessesSearch(
      filters: filters,
      limit: limit,
      include_total: include_total,
      cursor: cursor,
      fields: fields,
      enrichments: enrichments,
      contacts_per_company: contacts_per_company,
      emails_per_contact: emails_per_contact,
      query: query,
      async_request: false
    )

    items = page.is_a?(Hash) ? (page['items'] || []) : []
    break if !items.is_a?(Array) || items.empty?

    all_items.concat(items)

    has_more = !!(page['has_more'])
    next_cursor = page['next_cursor']
    break if !has_more || next_cursor.nil? || next_cursor.to_s.strip.empty?

    cursor = next_cursor.to_s
  end

  all_items
end

#businessesSearch(filters: {}, limit: 10, include_total: false, cursor: nil, fields: nil, enrichments: nil, contacts_per_company: nil, emails_per_contact: nil, async_request: false, ui: false, webhook: nil, query: nil) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/outscraper.rb', line 409

def businessesSearch(
  filters: {},
  limit: 10,
  include_total: false,
  cursor: nil,
  fields: nil,
  enrichments: nil,
  contacts_per_company: nil,
  emails_per_contact: nil,
  async_request: false,
  ui: false,
  webhook: nil,
  query: nil
)
  if contacts_per_company && contacts_per_company < 1
    raise ArgumentError, 'contacts_per_company must be >= 1'
  end

  if emails_per_contact && emails_per_contact < 1
    raise ArgumentError, 'emails_per_contact must be >= 1'
  end

enrichments_normalized = nil

if enrichments.is_a?(Hash)
  enrichments_normalized = enrichments
elsif enrichments.is_a?(Array)
  enrichments_normalized = enrichments
elsif enrichments.is_a?(String) || enrichments.is_a?(Symbol)
  enrichments_normalized = enrichments.to_s
elsif !enrichments.nil?
  enrichments_normalized = Array(enrichments)
end

if !contacts_per_company.nil? || !emails_per_contact.nil?
  cpp = contacts_per_company || 3
  epc = emails_per_contact || 1

  case enrichments_normalized
  when nil
enrichments_normalized = { 'contacts_n_leads' => { 'contacts_per_company' => cpp, 'emails_per_contact' => epc } }
  when Hash
enrichments_normalized['contacts_n_leads'] ||= {}
enrichments_normalized['contacts_n_leads']['contacts_per_company'] = cpp
enrichments_normalized['contacts_n_leads']['emails_per_contact'] = epc
  when Array
unless enrichments_normalized.map(&:to_s).include?('contacts_n_leads')
  raise ArgumentError, 'contacts_per_company and emails_per_contact require enrichments to include "contacts_n_leads"'
end
# Expand array to object so we can include options
expanded = {}
enrichments_normalized.each { |name| expanded[name.to_s] = {} }
expanded['contacts_n_leads']['contacts_per_company'] = cpp
expanded['contacts_n_leads']['emails_per_contact'] = epc
enrichments_normalized = expanded
  when String
unless enrichments_normalized == 'contacts_n_leads'
  raise ArgumentError, 'contacts_per_company and emails_per_contact require enrichments to include "contacts_n_leads"'
end
enrichments_normalized = { 'contacts_n_leads' => { 'contacts_per_company' => cpp, 'emails_per_contact' => epc } }
  else
raise ArgumentError, 'Invalid enrichments type'
  end
end

payload = {
  filters: (filters || {}),
  limit: limit,
  include_total: include_total,
  cursor: cursor,
  fields: fields ? Array(fields) : nil,
  enrichments: enrichments_normalized,
  query: query,
  async: async_request,
  ui: ui,
  webhook: webhook
}.compact

postAPIRequest('/businesses', payload)

end

#capterra_reviews(query, limit: 100, sort: '', cutoff: nil, language: 'en', region: nil, fields: nil, async_request: false) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/outscraper.rb', line 287

def capterra_reviews(query, limit: 100, sort: '', cutoff: nil, language: 'en', region: nil, fields: nil, async_request: false)
  response = self.class.get('/capterra-reviews', query: {
    query: query,
    limit: limit,
    sort: sort,
    cutoff: cutoff,
    language: language,
    region: region,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#company_insights(query, fields: '', async_request: false, enrichments: []) ⇒ Object



328
329
330
331
332
333
334
335
# File 'lib/outscraper.rb', line 328

def company_insights(query, fields: '', async_request: false, enrichments: [])
  response = self.class.get('/company-insights', query: {
    query: query.is_a?(Array) ? query : [query],
    fields: fields,
    enrichments: enrichments.is_a?(Array) ? enrichments : [enrichments],
    async: async_request
  }).parsed_response['data']
end

#company_website_finder(query, fields: '', async_request: false) ⇒ Object



374
375
376
377
378
379
380
# File 'lib/outscraper.rb', line 374

def company_website_finder(query, fields: '', async_request: false)
  response = self.class.get('/company-website-finder', query: {
    query: query.is_a?(Array) ? query : [query],
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#contacts_and_leads(query, fields: nil, async_request: true, preferred_contacts: nil, contacts_per_company: 3, emails_per_contact: 1, skip_contacts: 0, general_emails: false, ui: false, webhook: nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/outscraper.rb', line 140

def contacts_and_leads(
  query,
  fields: nil,
  async_request: true,
  preferred_contacts: nil,
  contacts_per_company: 3,
  emails_per_contact: 1,
  skip_contacts: 0,
  general_emails: false,
  ui: false,
  webhook: nil
)
  response = self.class.get('/leads-and-contacts', query: {
    query: query,
    fields: fields ? Array(fields) : nil,
    async: ui ? true : async_request,
    preferred_contacts: preferred_contacts ? Array(preferred_contacts) : nil,
    contacts_per_company: contacts_per_company,
    emails_per_contact: emails_per_contact,
    skip_contacts: skip_contacts,
    general_emails: general_emails,
    ui: ui,
    webhook: webhook
  }).parsed_response['data']
end

#emails_and_contacts(query) ⇒ Object



166
167
168
169
170
171
# File 'lib/outscraper.rb', line 166

def emails_and_contacts(query)
  response = self.class.get("/emails-and-contacts", 'query': {
    query: query,
    async: false,
  }).parsed_response['data']
end

#g2_reviews(query, limit: 100, sort: '', cutoff: nil, fields: nil, async_request: false) ⇒ Object



254
255
256
257
258
259
260
261
262
263
# File 'lib/outscraper.rb', line 254

def g2_reviews(query, limit: 100, sort: '', cutoff: nil, fields: nil, async_request: false)
  response = self.class.get('/g2/reviews', query: {
    query: query,
    limit: limit,
    sort: sort,
    cutoff: cutoff,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#geocoding(query, async_request: false) ⇒ Object



300
301
302
303
304
305
# File 'lib/outscraper.rb', line 300

def geocoding(query, async_request: false)
  response = self.class.get('/geocoding', query: {
    query: query,
    async: async_request
  }).parsed_response['data']
end

#get_google_maps_photos(query, options = {}) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/outscraper.rb', line 112

def get_google_maps_photos(query, options = {})
  response = self.class.get('/maps/photos-v3', query: {
    query: query,
    photosLimit: options[:photosLimit] || 100,
    limit: options[:limit] || 1,
    tag: options[:tag] || 'all',
    language: options[:language] || 'en',
    region: options[:region],
    fields: options[:fields],
    async: options.key?(:async) ? options[:async] : true,
    ui: options[:ui] || false,
    webhook: options[:webhook]
  }).parsed_response['data']
end

#glassdoor_reviews(query, limit: 100, sort: 'DATE', cutoff: nil, async_request: false) ⇒ Object



277
278
279
280
281
282
283
284
285
# File 'lib/outscraper.rb', line 277

def glassdoor_reviews(query, limit: 100, sort: 'DATE', cutoff: nil, async_request: false)
  response = self.class.get('/glassdoor/reviews', query: {
    query: query,
    limit: limit,
    sort: sort,
    cutoff: cutoff,
    async: async_request
  }).parsed_response['data']
end

#google_maps_directions(query:, departure_time: nil, finish_time: nil, interval: nil, travel_mode: 'best', language: 'en', region: nil, fields: nil, async_request: true) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/outscraper.rb', line 79

def google_maps_directions(query:, departure_time: nil, finish_time: nil, interval: nil, travel_mode: 'best', language: 'en', region: nil, fields: nil, async_request: true)
  queries = format_direction_queries(query)
  response = self.class.get('/maps/directions', query: {
    query: queries,
    departure_time: departure_time,
    finish_time: finish_time,
    interval: interval,
    travel_mode: travel_mode,
    language: language,
    region: region,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#google_maps_reviews(query, reviews_limit: 10, limit: 1, sort: 'most_relevant', skip: 0, start: 0, cutoff: 0, cutoff_rating: 0, ignore_empty: false, language: 'en', region: nil, reviews_query: nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/outscraper.rb', line 94

def google_maps_reviews(query, reviews_limit: 10, limit: 1, sort: 'most_relevant', skip: 0, start: 0, cutoff: 0, cutoff_rating: 0, ignore_empty: false, language: 'en', region: nil, reviews_query: nil)
  response = self.class.get("/maps/reviews-v3", 'query': {
    query: query,
    reviewsLimit: reviews_limit,
    limit: limit,
    sort: sort,
    skip: skip,
    start: start,
    cutoff: cutoff,
    reviewsQuery: reviews_query,
    cutoffRating: cutoff_rating,
    ignoreEmpty: ignore_empty,
    language: language,
    region: region,
    async: false,
  }).parsed_response['data']
end

#google_maps_search(query, limit: 20, drop_duplicates: false, language: 'en', region: nil, skip: 0) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/outscraper.rb', line 54

def google_maps_search(query, limit: 20, drop_duplicates: false, language: 'en', region: nil, skip: 0)
  response = self.class.get("/maps/search-v2", 'query': {
    query: query,
    limit: limit,
    drop_duplicates: drop_duplicates,
    language: language,
    region: region,
    skipPlaces: skip,
    async: false,
  }).parsed_response['data']
end

#google_maps_search_v3(query, limit: 20, language: 'en', region: nil, skip: 0, drop_duplicates: false, enrichment: nil, async_request: true) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/outscraper.rb', line 66

def google_maps_search_v3(query, limit: 20, language: 'en', region: nil, skip: 0, drop_duplicates: false, enrichment: nil, async_request: true)
  response = self.class.get('/maps/search-v3', query: {
    query: query,
    language: language,
    region: region,
    organizationsPerQueryLimit: limit,
    skipPlaces: skip,
    dropDuplicates: drop_duplicates,
    enrichment: enrichment ? Array(enrichment) : nil,
    async: async_request
  }).parsed_response['data']
end

#google_play_reviews(query, reviews_limit: 100, sort: 'most_relevant', cutoff: nil, rating: nil, language: 'en', fields: nil, async_request: false) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/outscraper.rb', line 127

def google_play_reviews(query, reviews_limit: 100, sort: 'most_relevant', cutoff: nil, rating: nil, language: 'en', fields: nil, async_request: false)
  response = self.class.get('/google-play/reviews', query: {
    query: query,
    limit: reviews_limit,
    sort: sort,
    cutoff: cutoff,
    rating: rating,
    language: language,
    async: async_request,
    fields: fields ? Array(fields) : nil
  }).parsed_response['data']
end

#google_search(query, pages_per_query: 1, uule: '', language: 'en', region: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/outscraper.rb', line 31

def google_search(query, pages_per_query: 1, uule: '', language: 'en', region: nil)
  response = self.class.get("/google-search-v3", 'query': {
    query: query,
    pagesPerQuery: pages_per_query,
    uule: uule,
    language: language,
    region: region,
    async: false,
  }).parsed_response['data']
end

#google_search_news(query, pages_per_query: 1, uule: '', tbs: '', language: 'en', region: nil, async_request: false) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/outscraper.rb', line 42

def google_search_news(query, pages_per_query: 1, uule: '', tbs: '', language: 'en', region: nil, async_request: false)
  response = self.class.get('/google-search-news', query: {
    query: query,
    pagesPerQuery: pages_per_query,
    uule: uule,
    tbs: tbs,
    language: language,
    region: region,
    async: async_request
  }).parsed_response['data']
end

#phone_identity_finder(query, async_request: false) ⇒ Object



314
315
316
317
318
319
# File 'lib/outscraper.rb', line 314

def phone_identity_finder(query, async_request: false)
  response = self.class.get('/whitepages-phones', query: {
    query: query.is_a?(Array) ? query : [query],
    async: async_request
  }).parsed_response['data']
end

#phones_enricher(query) ⇒ Object



173
174
175
176
177
178
# File 'lib/outscraper.rb', line 173

def phones_enricher(query)
  response = self.class.get("/phones-enricher", 'query': {
    query: query,
    async: false,
  }).parsed_response['data']
end

#postAPIRequest(path, parameters = {}) ⇒ Object



397
398
399
400
401
402
403
404
405
406
407
# File 'lib/outscraper.rb', line 397

def postAPIRequest(path, parameters = {})
  payload = parameters || {}

  response = self.class.post(
    path,
    headers: { 'Content-Type' => 'application/json' },
    body: payload.to_json
  ).parsed_response

  response.is_a?(Hash) && response.key?('data') ? response['data'] : response
end

#reverse_geocoding(query, async_request: false) ⇒ Object



307
308
309
310
311
312
# File 'lib/outscraper.rb', line 307

def reverse_geocoding(query, async_request: false)
  response = self.class.get('/reverse-geocoding', query: {
    query: query,
    async: async_request
  }).parsed_response['data']
end

#similarweb(query, fields: '', async_request: false) ⇒ Object



366
367
368
369
370
371
372
# File 'lib/outscraper.rb', line 366

def similarweb(query, fields: '', async_request: false)
  response = self.class.get('/similarweb', query: {
    query: query.is_a?(Array) ? query : [query],
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#tripadvisor_reviews(query, limit: 100, async_request: false) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/outscraper.rb', line 224

def tripadvisor_reviews(query, limit: 100, async_request: false)
  response = self.class.get('/tripadvisor-reviews', query: {
    query: query,
    limit: limit,
    async: async_request
  }).parsed_response['data']
end

#trustpilot(query, enrichment: [], fields: '', async_request: false) ⇒ Object



344
345
346
347
348
349
350
351
352
# File 'lib/outscraper.rb', line 344

def trustpilot(query, enrichment: [], fields: '', async_request: false)
  enrichment_array = enrichment ? (enrichment.is_a?(Array) ? enrichment : [enrichment]) : []
  response = self.class.get('/trustpilot', query: {
    query: query.is_a?(Array) ? query : [query],
    enrichment: enrichment_array,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#trustpilot_reviews(query, limit: 100, languages: 'default', sort: '', cutoff: nil, fields: '', async_request: false) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/outscraper.rb', line 265

def trustpilot_reviews(query, limit: 100, languages: 'default', sort: '', cutoff: nil, fields: '', async_request: false)
  response = self.class.get('/trustpilot/reviews', query: {
    query: query,
    limit: limit,
    languages: languages,
    sort: sort,
    cutoff: cutoff,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#trustpilot_search(query, limit: 100, skip: 0, enrichment: [], fields: '', async_request: false) ⇒ Object



354
355
356
357
358
359
360
361
362
363
364
# File 'lib/outscraper.rb', line 354

def trustpilot_search(query, limit: 100, skip: 0, enrichment: [], fields: '', async_request: false)
  enrichment_array = enrichment.is_a?(Array) ? enrichment : [enrichment]
  response = self.class.get('/trustpilot', query: {
    query: query.is_a?(Array) ? query : [query],
    limit: limit,
    skip: skip,
    enrichment: enrichment_array,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#validate_emails(query, async_request: false) ⇒ Object



337
338
339
340
341
342
# File 'lib/outscraper.rb', line 337

def validate_emails(query, async_request: false)
  response = self.class.get('/email-validator', query: {
    query: query.is_a?(Array) ? query : [query],
    async: async_request
  }).parsed_response['data']
end

#yellowpages_search(query, location: 'New York, NY', limit: 100, region: nil, enrichment: [], fields: '', async_request: false, ui: nil, webhook: nil) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/outscraper.rb', line 382

def yellowpages_search(query, location: 'New York, NY', limit: 100, region: nil, enrichment: [], fields: '', async_request: false, ui: nil, webhook: nil)
  enrichment_array = enrichment.is_a?(Array) ? enrichment : [enrichment]
  response = self.class.get('/yellowpages-search', query: {
    query: query.is_a?(Array) ? query : [query],
    location: location,
    limit: limit,
    region: region,
    enrichment: enrichment_array,
    fields: fields,
    async: async_request,
    ui: ui,
    webhook: webhook
  }).parsed_response['data']
end

#yelp_reviews(query, limit: 100, cursor: '', sort: 'relevance_desc', cutoff: '', fields: '', async_request: false) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/outscraper.rb', line 212

def yelp_reviews(query, limit: 100, cursor: '', sort: 'relevance_desc', cutoff: '', fields: '', async_request: false)
  response = self.class.get('/yelp/reviews', query: {
    query: query,
    limit: limit,
    cursor: cursor,
    sort: sort,
    cutoff: cutoff,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end

#yelp_search(query, limit: 100, async_request: false) ⇒ Object



204
205
206
207
208
209
210
# File 'lib/outscraper.rb', line 204

def yelp_search(query, limit: 100, async_request: false)
  response = self.class.get('/yelp-search', query: {
    query: query,
    limit: limit,
    async: async_request
  }).parsed_response['data']
end

#youtube_comments(query, per_query: 100, language: 'en', region: '', fields: '', async_request: false) ⇒ Object



243
244
245
246
247
248
249
250
251
252
# File 'lib/outscraper.rb', line 243

def youtube_comments(query, per_query: 100, language: 'en', region: '', fields: '', async_request: false)
  response = self.class.get('/youtube-comments', query: {
    query: query,
    perQuery: per_query,
    language: language,
    region: region,
    fields: fields,
    async: async_request
  }).parsed_response['data']
end