geogle 0.2.5 → 0.3.1
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/.gitignore +3 -1
- data/README.md +99 -43
- data/lib/geogle.rb +1 -0
- data/lib/geogle/base.rb +5 -4
- data/lib/geogle/directions.rb +6 -1
- data/lib/geogle/geocoder.rb +1 -0
- data/lib/geogle/model.rb +7 -1
- data/lib/geogle/model/area.rb +1 -1
- data/lib/geogle/model/geometry.rb +2 -2
- data/lib/geogle/model/leg.rb +26 -0
- data/lib/geogle/model/place.rb +2 -2
- data/lib/geogle/model/route.rb +22 -0
- data/lib/geogle/model/step.rb +24 -0
- data/lib/geogle/model/text_value.rb +15 -0
- data/lib/geogle/model/time.rb +16 -0
- data/lib/geogle/parametizer.rb +33 -7
- data/lib/geogle/parser.rb +13 -34
- data/lib/geogle/version.rb +1 -1
- data/spec/fixtures/cassettes/directions_by_address.yml +1049 -0
- data/spec/fixtures/cassettes/directions_by_address_no_results.yml +52 -0
- data/spec/fixtures/cassettes/directions_by_latlng.yml +1051 -0
- data/spec/geogle/components_spec.rb +0 -0
- data/spec/geogle/directions_spec.rb +59 -0
- data/spec/geogle/geocoder_spec.rb +19 -1
- data/spec/geogle/parser_spec.rb +264 -90
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc312835c798185f9b4ecc05e853c727e25f0597
|
4
|
+
data.tar.gz: 0bde3ef341b88d5667ed7166a9f252cae58857d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae6ad2a7a4bb5b2f7f82b413a9af61ffd5585e4de15acad2e0dc22406e2b6d3460002e3b5cfaab4b17e22ece3787821d4bf4c938bf971016e34de5dc7aae173
|
7
|
+
data.tar.gz: f78db15efbafcd71331f36617a3e0d1a2876f71a6bb542b5ae6b737ccd99991737553d115881526cee3959ef8c64f8dcf01ebd5618a33fd9c63eb99d29f39375
|
data/.gitignore
CHANGED
@@ -16,4 +16,6 @@ test/tmp
|
|
16
16
|
test/version_tmp
|
17
17
|
tmp
|
18
18
|
spec/integration/business_geocoder_spec.rb
|
19
|
-
spec/
|
19
|
+
spec/integration/business_directions_spec.rb
|
20
|
+
spec/fixtures/cassettes/business_geocode_by_address.yml
|
21
|
+
spec/fixtures/cassettes/business_directions.yml
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# Geogle
|
2
2
|
|
3
|
-
Still in development!
|
4
|
-
|
5
|
-
[](https://app.wercker.com/project/bykey/6122e4f0966ee255949e2eb465aefd10)
|
6
|
-
|
7
3
|
Ruby wrapper for the Geocoding and Directions services provided from the Google Maps API.
|
8
4
|
|
5
|
+
[](https://app.wercker.com/project/bykey/6122e4f0966ee255949e2eb465aefd10)
|
6
|
+
[](http://badge.fury.io/rb/geogle)
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -23,46 +21,45 @@ Or install it yourself as:
|
|
23
21
|
|
24
22
|
## Usage
|
25
23
|
|
26
|
-
|
24
|
+
## Geocoding
|
27
25
|
Google geocoding documentation:
|
28
26
|
https://developers.google.com/maps/documentation/geocoding/
|
29
27
|
|
30
|
-
|
28
|
+
### Setting parameters
|
29
|
+
|
30
|
+
When creating the Geogle::Geocoder these are the setting parameters:
|
31
31
|
|
32
|
-
* **sensor**:
|
33
|
-
* **
|
32
|
+
* **sensor**:
|
33
|
+
* **true**
|
34
|
+
* **false** (default)
|
35
|
+
* **language**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW
|
36
|
+
* **raw**:
|
37
|
+
* **true**: returns the raw json that comes in the body from the response.
|
38
|
+
* **false** (default): returns the object created with auxiliar funtions.
|
34
39
|
|
35
|
-
|
36
|
-
* **
|
37
|
-
* **crypto_key**: Criptographic key.
|
40
|
+
* **client_id** (required for business API): ID of the client. It starts with "gme-" prefix.
|
41
|
+
* **crypto_key** (required for business API): Criptographic key.
|
38
42
|
|
39
43
|
Here's more information about Google Maps API for Business:
|
40
44
|
https://developers.google.com/maps/documentation/business/webservices
|
41
45
|
|
42
|
-
|
43
|
-
* **address**: Geocoding by name of the location.
|
44
|
-
* **latlng**: Reverse geocode.
|
46
|
+
#### Data model
|
45
47
|
|
46
48
|
Both methods return an array of Geogle::Model::Place. Each place is composed by:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
|
50
|
+
* **Coordinates**:
|
51
|
+
* **lat**: Float
|
52
|
+
* **lng**: Float
|
53
|
+
|
54
|
+
* **Area**:
|
55
|
+
* **northeast**: Coordinates
|
56
|
+
* **southwest**: Coordinates
|
57
|
+
|
58
|
+
* **Geometry**:
|
59
|
+
* **location**: Coordinates
|
51
60
|
* **location_type**: String
|
52
|
-
* **bounds**:
|
53
|
-
|
54
|
-
* **lat**: Float
|
55
|
-
* **lng**: Float
|
56
|
-
* **southwest**:
|
57
|
-
* **lat**: Float
|
58
|
-
* **lng**: Float
|
59
|
-
* **viewport**:
|
60
|
-
* **northeast**:
|
61
|
-
* **lat**: Float
|
62
|
-
* **lng**: Float
|
63
|
-
* **southwest**:
|
64
|
-
* **lat**: Float
|
65
|
-
* **lng**: Float
|
61
|
+
* **bounds**: Area
|
62
|
+
* **viewport**: Area
|
66
63
|
* **address**:
|
67
64
|
* **street_number**: String
|
68
65
|
* **street**: String
|
@@ -75,33 +72,92 @@ Both methods return an array of Geogle::Model::Place. Each place is composed by:
|
|
75
72
|
* **country_code**: String
|
76
73
|
* **formatted**: String
|
77
74
|
|
75
|
+
|
78
76
|
### By address without an account
|
79
77
|
|
80
|
-
|
81
|
-
|
78
|
+
```ruby
|
79
|
+
client = Geogle::Geocoder.new({ sensor: false, language: "es" })
|
80
|
+
client.address("Blasco Ibañez, Valencia")
|
81
|
+
```
|
82
82
|
|
83
83
|
### By address making use of the components
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
```ruby
|
86
|
+
client = Geogle::Geocoder.new({ sensor: false, language: "es" })
|
87
|
+
components = { country: 'ES' }
|
88
|
+
client.address("Blasco Ibañez, Valencia", components)
|
89
|
+
```
|
88
90
|
|
89
91
|
Available components to be used can be found here:
|
90
92
|
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
|
91
93
|
|
92
94
|
### Reverse geocoding (by latitude and longitude)
|
93
95
|
|
94
|
-
|
96
|
+
```ruby
|
97
|
+
Geogle::Geocoder.new.latlng(39.5073225, -0.2914778)
|
98
|
+
```
|
95
99
|
|
96
100
|
### Using a business account
|
97
101
|
|
98
|
-
|
99
|
-
|
102
|
+
```ruby
|
103
|
+
client = Geogle::Geocoder.new({ client_id: "gme-client-id", crypto_key: "crypto-key" })
|
104
|
+
client.latlng(39.5073225, -0.2914778)
|
105
|
+
```
|
106
|
+
|
107
|
+
The signature required to do the request will be appended in the URL.
|
108
|
+
|
109
|
+
## Directions
|
110
|
+
|
111
|
+
### Setting parameters
|
112
|
+
|
113
|
+
The same as with **Geocode**.
|
114
|
+
|
115
|
+
#### Data model
|
116
|
+
|
117
|
+
Return an array of Geogle::Model::Route. Each route is composed by:
|
118
|
+
|
119
|
+
* **Time**:
|
120
|
+
* **value**: Integer
|
121
|
+
* **text**: String
|
122
|
+
* **time_zone**: String
|
123
|
+
|
124
|
+
* **TextValue**:
|
125
|
+
* **value**: Integer
|
126
|
+
* **text**: String
|
127
|
+
|
128
|
+
* **Leg**:
|
129
|
+
* **steps**: Step
|
130
|
+
* **distance**: TextValue
|
131
|
+
* **duration**: TextValue
|
132
|
+
* **arrival_time**: Time
|
133
|
+
* **departure_time**: Time
|
134
|
+
* **start_address**: String
|
135
|
+
* **end_address**: String
|
136
|
+
* **start_location**: Coordinates
|
137
|
+
* **end_location**: Coordinates
|
138
|
+
|
139
|
+
* **Route**:
|
140
|
+
* **summary**: String
|
141
|
+
* **legs**: Array[Leg]
|
142
|
+
* **waypoint_order**: Array[Integer]
|
143
|
+
* **bounds**: Area
|
144
|
+
* **copyrights**: String
|
145
|
+
* **warnings**: Array[String]
|
146
|
+
|
147
|
+
|
148
|
+
### Search using address names for origin and destination
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
client = Geogle::Directions.new
|
152
|
+
client.routes("Berlin", "Munich", { region: "de" })
|
153
|
+
```
|
100
154
|
|
101
|
-
|
155
|
+
### Search using geo-locations for origin and destination
|
102
156
|
|
103
|
-
|
104
|
-
|
157
|
+
```ruby
|
158
|
+
client = Geogle::Directions.new
|
159
|
+
client.routes("39.4699889,-0.3759178", "40.4167158,-3.7037799")
|
160
|
+
```
|
105
161
|
|
106
162
|
|
107
163
|
## Contributing
|
data/lib/geogle.rb
CHANGED
data/lib/geogle/base.rb
CHANGED
@@ -5,15 +5,16 @@ require "net/http"
|
|
5
5
|
|
6
6
|
module Geogle
|
7
7
|
class Base
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
@parametizer = Parametizer.new(
|
8
|
+
def initialize(settings = {})
|
9
|
+
@settings = settings
|
10
|
+
@parametizer = Parametizer.new(settings)
|
11
|
+
@raw = settings[:raw] || false
|
11
12
|
end
|
12
13
|
|
13
14
|
protected
|
14
15
|
|
15
16
|
def request(url, params)
|
16
|
-
uri = UrlBuilder.new(url, @
|
17
|
+
uri = UrlBuilder.new(url, @settings).build(params)
|
17
18
|
response = Net::HTTP.get_response(uri)
|
18
19
|
raise InvalidKeyError if response.code == "403"
|
19
20
|
body = JSON.parse(response.body)
|
data/lib/geogle/directions.rb
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Geogle
|
4
4
|
class Directions < Base
|
5
|
-
|
5
|
+
def routes(origin, destination, options = {})
|
6
|
+
params = @parametizer.directions(origin, destination, options)
|
7
|
+
body = request(URL::DIRECTIONS, params)
|
8
|
+
return body["routes"] if @raw
|
9
|
+
Parser.routes(body["routes"])
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
data/lib/geogle/geocoder.rb
CHANGED
data/lib/geogle/model.rb
CHANGED
@@ -2,10 +2,16 @@
|
|
2
2
|
|
3
3
|
module Geogle
|
4
4
|
module Model
|
5
|
+
require "geogle/model/place"
|
5
6
|
require "geogle/model/address"
|
6
7
|
require "geogle/model/area"
|
7
8
|
require "geogle/model/coordinates"
|
8
9
|
require "geogle/model/geometry"
|
9
|
-
|
10
|
+
|
11
|
+
require "geogle/model/route"
|
12
|
+
require "geogle/model/leg"
|
13
|
+
require "geogle/model/step"
|
14
|
+
require "geogle/model/time"
|
15
|
+
require "geogle/model/text_value"
|
10
16
|
end
|
11
17
|
end
|
data/lib/geogle/model/area.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
require 'geogle/model/step'
|
5
|
+
require 'geogle/model/time'
|
6
|
+
require 'geogle/model/text_value'
|
7
|
+
require 'geogle/model/coordinates'
|
8
|
+
|
9
|
+
module Geogle
|
10
|
+
module Model
|
11
|
+
|
12
|
+
class Leg
|
13
|
+
include Virtus.model
|
14
|
+
|
15
|
+
attribute :steps, Array[Step]
|
16
|
+
attribute :distance, TextValue
|
17
|
+
attribute :duration, TextValue
|
18
|
+
attribute :arrival_time, Time
|
19
|
+
attribute :departure_time, Time
|
20
|
+
attribute :start_address, String
|
21
|
+
attribute :end_address, String
|
22
|
+
attribute :start_location, Coordinates
|
23
|
+
attribute :end_location, Coordinates
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/geogle/model/place.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
require 'geogle/model/leg'
|
5
|
+
require 'geogle/model/area'
|
6
|
+
|
7
|
+
module Geogle
|
8
|
+
module Model
|
9
|
+
|
10
|
+
class Route
|
11
|
+
include Virtus.model
|
12
|
+
|
13
|
+
attribute :summary, String
|
14
|
+
attribute :legs, Array[Leg]
|
15
|
+
attribute :waypoint_order, Array[Integer]
|
16
|
+
attribute :overview_polyline, String
|
17
|
+
attribute :bounds, Area
|
18
|
+
attribute :copyrights, String
|
19
|
+
attribute :warnings, Array[String]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
require 'geogle/model/coordinates'
|
5
|
+
require 'geogle/model/text_value'
|
6
|
+
|
7
|
+
module Geogle
|
8
|
+
module Model
|
9
|
+
|
10
|
+
class Step
|
11
|
+
include Virtus.model
|
12
|
+
|
13
|
+
attribute :html_instructions, String
|
14
|
+
attribute :distance, TextValue
|
15
|
+
attribute :duration, TextValue
|
16
|
+
attribute :start_location, Coordinates
|
17
|
+
attribute :end_location, Coordinates
|
18
|
+
attribute :travel_mode, String
|
19
|
+
# Only travel_mode is transit
|
20
|
+
# attribute :sub_steps, String
|
21
|
+
# attribute :transit_details, String
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/geogle/parametizer.rb
CHANGED
@@ -8,20 +8,46 @@ module Geogle
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def address(address, components = {})
|
11
|
-
options = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
options = {
|
12
|
+
address: address,
|
13
|
+
language: @language,
|
14
|
+
components: components(components),
|
15
|
+
sensor: @sensor
|
16
|
+
}
|
17
|
+
compact_hash(options)
|
17
18
|
end
|
18
19
|
|
19
20
|
def latlng(lat, lng)
|
20
|
-
{
|
21
|
+
{
|
22
|
+
latlng: "#{lat},#{lng}",
|
23
|
+
language: @language,
|
24
|
+
sensor: @sensor
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def directions(origin, destination, params)
|
29
|
+
waypoints = params[:waypoints] || []
|
30
|
+
options = {
|
31
|
+
origin: origin,
|
32
|
+
destination: destination,
|
33
|
+
waypoints: waypoints.join("|"),
|
34
|
+
alternatives: params[:alternatives],
|
35
|
+
avoid: params[:avoid],
|
36
|
+
units: params[:units],
|
37
|
+
region: params[:region],
|
38
|
+
departure_time: params[:departure_time],
|
39
|
+
arrival_time: params[:arrival_time],
|
40
|
+
sensor: @sensor
|
41
|
+
}
|
42
|
+
compact_hash(options)
|
21
43
|
end
|
22
44
|
|
23
45
|
private
|
24
46
|
|
47
|
+
def compact_hash(hash)
|
48
|
+
hash.select { |k,v| !v.nil? && !v.to_s.empty? }
|
49
|
+
end
|
50
|
+
|
25
51
|
def components(components)
|
26
52
|
components.collect do |component, value|
|
27
53
|
"#{component}:#{value}"
|