mapricot-api 0.9.0 → 0.11.0
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/README.md +10 -6
- data/lib/mapricot/api.rb +12 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3aa156c2854ba75ee6f5277d91f46bc586e5c1807b47057a253fa7b0b117a930
|
|
4
|
+
data.tar.gz: f321e6ebdbcceb3f94ae5b51e8af98da8aa1abc4fac9d05914f7377df6feb63c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25afe81cbda109fc6272517af7b6bf1b3d3b29ec2a6d81eda812830834da030a3c7bbb23e7ef644f63875771b1ff907a97870c56d930a448965ab34195ef3866
|
|
7
|
+
data.tar.gz: 73c41d224dc22f7c5c90db74814fb7cb5202110bab0f0abc3610dced8adca8334c430887a28d4a02c279359eaf7a4c617d1baef53982ea5a61b754036dd9331c
|
data/README.md
CHANGED
|
@@ -24,7 +24,7 @@ puts place["label"], place["lat"], place["lon"]
|
|
|
24
24
|
|
|
25
25
|
## Methods
|
|
26
26
|
|
|
27
|
-
Methods are grouped by product, the same way as the API's paths. Each returns the API's JSON as a Hash with string keys, with the same field names as the [API reference](https://mapricot.com/api-reference/).
|
|
27
|
+
Methods are grouped by product, the same way as the API's paths. Each returns the API's JSON as a Hash with string keys, with the same field names as the [API reference](https://mapricot.com/docs/api-reference/).
|
|
28
28
|
|
|
29
29
|
| Method | Endpoint |
|
|
30
30
|
| --- | --- |
|
|
@@ -34,9 +34,9 @@ Methods are grouped by product, the same way as the API's paths. Each returns th
|
|
|
34
34
|
| `client.geocoding.reverse(lat, lon, limit:, lang:)` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
|
|
35
35
|
| `client.places.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
|
|
36
36
|
| `client.places.get(id, lang:)` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
|
|
37
|
-
| `client.routing.route(waypoints, mode:, geometries:, steps:, lang:)` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
|
|
38
|
-
| `client.routing.optimize(waypoints, mode:, geometries:, steps:, lang:)` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
|
|
39
|
-
| `client.routing.isochrone(location, minutes, mode:)` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
|
|
37
|
+
| `client.routing.route(waypoints, mode:, geometries:, steps:, lang:, costing:)` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
|
|
38
|
+
| `client.routing.optimize(waypoints, mode:, geometries:, steps:, lang:, costing:)` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
|
|
39
|
+
| `client.routing.isochrone(location, minutes, mode:, costing:, generalize:)` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
|
|
40
40
|
| `client.ip_geolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
|
|
41
41
|
| `client.account` | `GET /account`, which checks a key and is never billed |
|
|
42
42
|
|
|
@@ -61,6 +61,8 @@ Pass `steps: true` and each leg's `steps` has its turn-by-turn directions: an `i
|
|
|
61
61
|
|
|
62
62
|
`routing.optimize` takes the same arguments as `routing.route` and returns the route that visits the waypoints in a fast order, keeping the first and last in place. It adds `"waypointOrder"`: the indexes of your waypoints in visiting order, which `"legs"` follow. Every pair of waypoints must be within 400 km of each other for `drive`, or 200 km for `walk` and `bicycle`.
|
|
63
63
|
|
|
64
|
+
`costing` changes how a route, optimized route, or isochrone picks its roads, with Valhalla's [costing options](https://mapricot.com/docs/routing/#costing-options) for the mode, such as `costing: { useTolls: 0, useHighways: 0 }` to drive avoiding tolls and highways where it can.
|
|
65
|
+
|
|
64
66
|
An isochrone is a GeoJSON `FeatureCollection` with one polygon per time, largest first, so a map that draws them in order shows the smaller ones on top:
|
|
65
67
|
|
|
66
68
|
```ruby
|
|
@@ -68,6 +70,8 @@ area = client.routing.isochrone({ lat: 45.5189, lon: -122.6793 }, [5, 10], mode:
|
|
|
68
70
|
puts area["features"].map { |feature| feature["properties"]["minutes"] }.inspect
|
|
69
71
|
```
|
|
70
72
|
|
|
73
|
+
`generalize` smooths each outline to within that many meters, from 10 to 5000, so it has fewer points. The API picks it from the travel time when you leave it out. A long drive's outlines are detailed and large, and `generalize: 300` makes them much smaller while keeping their shape at city scale.
|
|
74
|
+
|
|
71
75
|
If your app shows results, show the credits in each response's `attribution`.
|
|
72
76
|
|
|
73
77
|
## Errors and retries
|
|
@@ -82,11 +86,11 @@ rescue Mapricot::Error => e
|
|
|
82
86
|
end
|
|
83
87
|
```
|
|
84
88
|
|
|
85
|
-
The client retries `503` responses and `429 concurrency_exceeded`, up to twice, waiting longer each time. Errors aren't billed. Pass `max_retries:` and `timeout:` (seconds) to `Mapricot::Client.new` to change this. The [API reference](https://mapricot.com/api-reference/#errors) lists every status.
|
|
89
|
+
The client retries `503` responses and `429 concurrency_exceeded`, up to twice, waiting longer each time. Errors aren't billed. Pass `max_retries:` and `timeout:` (seconds) to `Mapricot::Client.new` to change this. The [API reference](https://mapricot.com/docs/api-reference/#errors) lists every status.
|
|
86
90
|
|
|
87
91
|
## Links
|
|
88
92
|
|
|
89
93
|
- [Mapricot](https://mapricot.com/)
|
|
90
94
|
- [Ruby docs](https://mapricot.com/docs/ruby/)
|
|
91
|
-
- [API reference](https://mapricot.com/api-reference/)
|
|
95
|
+
- [API reference](https://mapricot.com/docs/api-reference/)
|
|
92
96
|
- [Pricing](https://mapricot.com/pricing/)
|
data/lib/mapricot/api.rb
CHANGED
|
@@ -7,7 +7,7 @@ require "net/http"
|
|
|
7
7
|
# The official client for the Mapricot API: address and place search, reverse geocoding, nearby places, routing,
|
|
8
8
|
# and IP geolocation. See https://mapricot.com/docs/ruby/.
|
|
9
9
|
module Mapricot
|
|
10
|
-
VERSION = "0.
|
|
10
|
+
VERSION = "0.11.0"
|
|
11
11
|
|
|
12
12
|
# An error response from the API.
|
|
13
13
|
class Error < StandardError
|
|
@@ -22,7 +22,7 @@ module Mapricot
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# Methods are grouped by product, as in client.geocoding.search. Each returns the API's JSON as a Hash with string
|
|
25
|
-
# keys, as in https://mapricot.com/api-reference/.
|
|
25
|
+
# keys, as in https://mapricot.com/docs/api-reference/.
|
|
26
26
|
class Client
|
|
27
27
|
attr_reader :geocoding, :places, :routing, :ip_geolocation
|
|
28
28
|
|
|
@@ -159,24 +159,26 @@ module Mapricot
|
|
|
159
159
|
|
|
160
160
|
# Find a route through 2 to 20 waypoints, each {lat:, lon:}. mode is "drive" (the default), "walk", or "bicycle".
|
|
161
161
|
# geometries is "polyline" (the default), "polyline6", or "geojson". steps: true adds each leg's turn-by-turn
|
|
162
|
-
# steps, in lang, an ISO 639-1 language, English by default.
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
# steps, in lang, an ISO 639-1 language, English by default. costing takes Valhalla's costing options for the mode,
|
|
163
|
+
# such as { useTolls: 0 }: https://mapricot.com/docs/routing/#costing-options.
|
|
164
|
+
def route(waypoints, mode: nil, geometries: nil, steps: nil, lang: nil, costing: nil)
|
|
165
|
+
body = { waypoints: waypoints, mode: mode, geometries: geometries, steps: steps, lang: lang, costing: costing }
|
|
165
166
|
@post.call("/routing/v1/route", body)
|
|
166
167
|
end
|
|
167
168
|
|
|
168
169
|
# Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. It
|
|
169
170
|
# takes the same arguments as route, and the route adds "waypointOrder": the indexes of the waypoints sent, in
|
|
170
171
|
# visiting order.
|
|
171
|
-
def optimize(waypoints, mode: nil, geometries: nil, steps: nil, lang: nil)
|
|
172
|
-
body = { waypoints: waypoints, mode: mode, geometries: geometries, steps: steps, lang: lang }
|
|
172
|
+
def optimize(waypoints, mode: nil, geometries: nil, steps: nil, lang: nil, costing: nil)
|
|
173
|
+
body = { waypoints: waypoints, mode: mode, geometries: geometries, steps: steps, lang: lang, costing: costing }
|
|
173
174
|
@post.call("/routing/v1/optimize", body)
|
|
174
175
|
end
|
|
175
176
|
|
|
176
177
|
# The areas reachable from a location, {lat:, lon:}, within 1 to 4 times, each 1 to 60 minutes, as a GeoJSON
|
|
177
|
-
# FeatureCollection with one polygon per time, largest first. mode
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
# FeatureCollection with one polygon per time, largest first. mode and costing are as for route. generalize smooths
|
|
179
|
+
# each outline to within that many meters, from 10 to 5000; left out, the API picks it from the travel time.
|
|
180
|
+
def isochrone(location, minutes, mode: nil, costing: nil, generalize: nil)
|
|
181
|
+
@post.call("/routing/v1/isochrone", { location: location, minutes: minutes, mode: mode, costing: costing, generalize: generalize })
|
|
180
182
|
end
|
|
181
183
|
end
|
|
182
184
|
|