Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/Google Directions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Emails And Contacts Scraper With Ruby

Returns directions between two points from Google Maps. [Outscraper API](https://app.outscraper.cloud/api-docs#tag/Google/paths/~1maps~1directions/get).

## Installation

Install the gem and add to the application's Gemfile by executing:
```bash
bundle add outscraper
```

If bundler is not being used to manage dependencies, install the gem by executing:
```bash
gem install outscraper
```

[Link to the Ruby package page](https://rubygems.org/gems/outscraper)

## Initialization
```ruby
require 'Outscraper'

client = Outscraper::Client.new('SECRET_API_KEY')
```
[Link to the profile page to create the API key](https://app.outscraper.com/profile)

## Usage

```ruby
# Returns directions:
results = client.google_maps_directions(['29.696596, 76.994928 30.7159662444353, 76.8053887016268', '29.696596, 76.994928 30.723065, 76.770169'])
```
19 changes: 16 additions & 3 deletions lib/outscraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

require_relative "outscraper/version"

QUERY_DELIMITER = ' '

def format_direction_queries(q)
if q.is_a?(Array) && !q.empty? && q.first.is_a?(Array)
return q.map { |pair| pair.join(QUERY_DELIMITER) }
end

return q if q.is_a?(Array)

[q]
end


module Outscraper
class Client
include HTTParty
Expand Down Expand Up @@ -61,10 +74,10 @@ def google_maps_search_v3(query, limit: 20, language: 'en', region: nil, skip: 0
}).parsed_response['data']
end

def google_maps_directions(origin: '', destination: '', departure_time: nil, finish_time: nil, interval: nil, travel_mode: 'best', language: 'en', region: nil, fields: nil, async_request: true)
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: {
origin: Array(origin),
destination: Array(destination),
query: queries,
departure_time: departure_time,
finish_time: finish_time,
interval: interval,
Expand Down
2 changes: 1 addition & 1 deletion lib/outscraper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Outscraper
VERSION = "0.3.3"
VERSION = "0.3.4"
end