outscraper 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/Google Directions.md +32 -0
- data/lib/outscraper/version.rb +1 -1
- data/lib/outscraper.rb +102 -3
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9476b68f4bd7fc5b7af263cc5cb28b5e753960d760c44d1e697681123aee6236
|
|
4
|
+
data.tar.gz: 298ec43dbdec09108bbf6e98660b0e1150dce799d3408740a2c6d8fdbfd33c43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb819008c8e1a0e634c4a73779842810153156b7c22fc2ce94954e8a030ee363d8dc57127a0db61e190b40dab50d349a93c852d5faf1ebe1cefeba7b7674dde0
|
|
7
|
+
data.tar.gz: 2b8beb1a3fdf33a45d0bfc20f293516b535106dfb723f5499f831fea583e5f5788423033939665ce109536ac804ecb2b47dd17f016265f860c45efdb197a7fe2
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Emails And Contacts Scraper With Ruby
|
|
2
|
+
|
|
3
|
+
Returns directions between two points from Google Maps. [Outscraper API](https://app.outscraper.cloud/api-docs#tag/Google/paths/~1maps~1directions/get).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
```bash
|
|
9
|
+
bundle add outscraper
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
13
|
+
```bash
|
|
14
|
+
gem install outscraper
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
[Link to the Ruby package page](https://rubygems.org/gems/outscraper)
|
|
18
|
+
|
|
19
|
+
## Initialization
|
|
20
|
+
```ruby
|
|
21
|
+
require 'Outscraper'
|
|
22
|
+
|
|
23
|
+
client = Outscraper::Client.new('SECRET_API_KEY')
|
|
24
|
+
```
|
|
25
|
+
[Link to the profile page to create the API key](https://app.outscraper.com/profile)
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# Returns directions:
|
|
31
|
+
results = client.google_maps_directions(['29.696596, 76.994928 30.7159662444353, 76.8053887016268', '29.696596, 76.994928 30.723065, 76.770169'])
|
|
32
|
+
```
|
data/lib/outscraper/version.rb
CHANGED
data/lib/outscraper.rb
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "httparty"
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "json"
|
|
4
6
|
|
|
5
7
|
require_relative "outscraper/version"
|
|
6
8
|
|
|
9
|
+
QUERY_DELIMITER = ' '
|
|
10
|
+
|
|
11
|
+
def format_direction_queries(q)
|
|
12
|
+
if q.is_a?(Array) && !q.empty? && q.first.is_a?(Array)
|
|
13
|
+
return q.map { |pair| pair.join(QUERY_DELIMITER) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
return q if q.is_a?(Array)
|
|
17
|
+
|
|
18
|
+
[q]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
7
22
|
module Outscraper
|
|
8
23
|
class Client
|
|
9
24
|
include HTTParty
|
|
@@ -61,10 +76,10 @@ module Outscraper
|
|
|
61
76
|
}).parsed_response['data']
|
|
62
77
|
end
|
|
63
78
|
|
|
64
|
-
def google_maps_directions(
|
|
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)
|
|
80
|
+
queries = format_direction_queries(query)
|
|
65
81
|
response = self.class.get('/maps/directions', query: {
|
|
66
|
-
|
|
67
|
-
destination: Array(destination),
|
|
82
|
+
query: queries,
|
|
68
83
|
departure_time: departure_time,
|
|
69
84
|
finish_time: finish_time,
|
|
70
85
|
interval: interval,
|
|
@@ -378,5 +393,89 @@ module Outscraper
|
|
|
378
393
|
webhook: webhook
|
|
379
394
|
}).parsed_response['data']
|
|
380
395
|
end
|
|
396
|
+
|
|
397
|
+
def postAPIRequest(path, parameters = {})
|
|
398
|
+
payload = parameters || {}
|
|
399
|
+
|
|
400
|
+
response = self.class.post(
|
|
401
|
+
path,
|
|
402
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
403
|
+
body: payload.to_json
|
|
404
|
+
).parsed_response
|
|
405
|
+
|
|
406
|
+
response.is_a?(Hash) && response.key?('data') ? response['data'] : response
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
def businessesSearch(
|
|
410
|
+
filters: {},
|
|
411
|
+
limit: 10,
|
|
412
|
+
include_total: false,
|
|
413
|
+
cursor: nil,
|
|
414
|
+
fields: nil,
|
|
415
|
+
async_request: false,
|
|
416
|
+
ui: false,
|
|
417
|
+
webhook: nil
|
|
418
|
+
)
|
|
419
|
+
payload = {
|
|
420
|
+
filters: (filters || {}),
|
|
421
|
+
limit: limit,
|
|
422
|
+
include_total: include_total,
|
|
423
|
+
cursor: cursor,
|
|
424
|
+
fields: fields ? Array(fields) : nil,
|
|
425
|
+
async: async_request,
|
|
426
|
+
ui: ui,
|
|
427
|
+
webhook: webhook
|
|
428
|
+
}.compact
|
|
429
|
+
|
|
430
|
+
postAPIRequest('/businesses', payload)
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
def businessesIterSearch(filters: {}, limit: 10, fields: nil, include_total: false)
|
|
434
|
+
cursor = nil
|
|
435
|
+
all_items = []
|
|
436
|
+
|
|
437
|
+
loop do
|
|
438
|
+
page = businessesSearch(
|
|
439
|
+
filters: filters,
|
|
440
|
+
limit: limit,
|
|
441
|
+
include_total: include_total,
|
|
442
|
+
cursor: cursor,
|
|
443
|
+
fields: fields,
|
|
444
|
+
async_request: false
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
items = page.is_a?(Hash) ? (page['items'] || []) : []
|
|
448
|
+
break if !items.is_a?(Array) || items.empty?
|
|
449
|
+
|
|
450
|
+
all_items.concat(items)
|
|
451
|
+
|
|
452
|
+
has_more = !!(page['has_more'])
|
|
453
|
+
next_cursor = page['next_cursor']
|
|
454
|
+
break if !has_more || next_cursor.nil? || next_cursor.to_s.strip.empty?
|
|
455
|
+
|
|
456
|
+
cursor = next_cursor.to_s
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
all_items
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
def businessesGet(business_id, fields: nil, async_request: false, ui: false, webhook: nil)
|
|
463
|
+
raise ArgumentError, 'business_id is required' if business_id.nil? || business_id.to_s.strip.empty?
|
|
464
|
+
|
|
465
|
+
fields_param =
|
|
466
|
+
if fields.is_a?(Array)
|
|
467
|
+
fields.map(&:to_s).join(',')
|
|
468
|
+
else
|
|
469
|
+
fields
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
response = self.class.get("/businesses/#{CGI.escape(business_id.to_s)}", query: {
|
|
473
|
+
fields: fields_param,
|
|
474
|
+
async: async_request,
|
|
475
|
+
ui: ui,
|
|
476
|
+
webhook: webhook
|
|
477
|
+
}.compact).parsed_response
|
|
478
|
+
response.is_a?(Hash) && response.key?('data') ? response['data'] : response
|
|
479
|
+
end
|
|
381
480
|
end
|
|
382
481
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: outscraper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Outscraper
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -44,6 +44,7 @@ files:
|
|
|
44
44
|
- examples/Contacts And Leads.md
|
|
45
45
|
- examples/Email Addresses Finder.md
|
|
46
46
|
- examples/Emails And Contacts.md
|
|
47
|
+
- examples/Google Directions.md
|
|
47
48
|
- examples/Google Maps Photos Scraper.md
|
|
48
49
|
- examples/Google Maps Reviews.md
|
|
49
50
|
- examples/Google Maps.md
|