mapricot-api 0.8.0 → 0.10.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -3
  3. data/lib/mapricot/api.rb +22 -11
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60ae66ee605316bfe6bf97ce5cdee87b0540c914a687d6d9fa32c94116599d91
4
- data.tar.gz: a3614aa73d7395d146158da05b9a3dccb955fd656c646411ce1427c4026f294a
3
+ metadata.gz: e778f6345129b270ba0ba06c9e791051a9093d5c361dbd17afa00aa15a5f0f8e
4
+ data.tar.gz: '092b116567111f7fc1b702add90dff4caf06e7c7ef46307a58346b229ce62730'
5
5
  SHA512:
6
- metadata.gz: 156e3cfd96b2ed32b0fa917d973852cf7df03421ad49b96d89fd4c5ff66dd6bbe3a601a9cfdd6ba95af616e48360ae0ef63127f4402ca1a94cfe22b21558e295
7
- data.tar.gz: 0df9af5005e818d9ef4553fb6b11ada8d1e04d8de040682c2ede03f3ef3990983112e0161affee1d0a8cf4aa8f0d3e84bcd4bf0551bd8ec07d1a333f21c7ee8d
6
+ metadata.gz: '093e71c5a7d7ab43b19c13a30671e3c20b334ebf115daefd01204600f021c7abe97c83dbe0b467c3f8bdac914bf26033de7c956b283c8a102db34f532cc5ebfe'
7
+ data.tar.gz: 7ec4ba130fa05c424d2d19b5caa40c0d3ab4323962fe4a08363e295f01c15535d47b8f2feaab95a1caaef4f79b7e901d0bfbbe690c5c90a479ff6bba13ffd497
data/README.md CHANGED
@@ -29,13 +29,14 @@ Methods are grouped by product, the same way as the API's paths. Each returns th
29
29
  | Method | Endpoint |
30
30
  | --- | --- |
31
31
  | `client.geocoding.search(q, focus:, country:, limit:, lang:)` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
32
+ | `client.geocoding.search_batch(queries)` | [`POST /geocoding/v1/search/batch`](https://mapricot.com/docs/geocoding/#search-a-list-of-addresses) |
32
33
  | `client.geocoding.autocomplete(q, focus:, country:, limit:, lang:)` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
33
34
  | `client.geocoding.reverse(lat, lon, limit:, lang:)` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
34
35
  | `client.places.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
35
36
  | `client.places.get(id, lang:)` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
36
- | `client.routing.route(waypoints, mode:, geometries:, steps:, lang:)` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
37
- | `client.routing.optimize(waypoints, mode:, geometries:, steps:, lang:)` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
38
- | `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:)` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
39
40
  | `client.ip_geolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
40
41
  | `client.account` | `GET /account`, which checks a key and is never billed |
41
42
 
@@ -47,12 +48,21 @@ route = client.routing.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214,
47
48
  puts route["routes"][0]["durationSeconds"]
48
49
  ```
49
50
 
51
+ `search_batch` runs up to 100 searches in one request. Each query is a Hash of `search`'s parameters, and `"responses"` answers them in the same order, each with `"results"` and `"attribution"`, or an `"error"` with the `"code"` and `"message"` that search would get, without raising. Each completed search is billed as one request; errors aren't.
52
+
53
+ ```ruby
54
+ batch = client.geocoding.search_batch([{ q: "128 SW 3rd Ave, Portland", limit: 1 }, { q: "10 Downing Street, London", limit: 1 }])
55
+ batch["responses"].each { |response| puts response.dig("error", "message") || response["results"][0]["label"] }
56
+ ```
57
+
50
58
  A route's path comes as an encoded `polyline` with five decimal places, which polyline decoders assume. Pass `geometries: "geojson"` to get it as a GeoJSON `LineString` in `geometry` instead, which maps draw without decoding, or `geometries: "polyline6"` for six decimal places.
51
59
 
52
60
  Pass `steps: true` and each leg's `steps` has its turn-by-turn directions: an `instruction`, its distance and time, and its `lat` and `lon`. They're in English unless you pass `lang`, such as `lang: "fr"`.
53
61
 
54
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`.
55
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
+
56
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:
57
67
 
58
68
  ```ruby
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.8.0"
10
+ VERSION = "0.10.0"
11
11
 
12
12
  # An error response from the API.
13
13
  class Error < StandardError
@@ -33,7 +33,7 @@ module Mapricot
33
33
  @base_url = base_url
34
34
  @timeout = timeout
35
35
  @max_retries = max_retries
36
- @geocoding = GeocodingService.new(method(:get))
36
+ @geocoding = GeocodingService.new(method(:get), method(:post), method(:query_value))
37
37
  @places = PlacesService.new(method(:get))
38
38
  @routing = RoutingService.new(method(:post))
39
39
  @ip_geolocation = IpGeolocationService.new(method(:get))
@@ -104,8 +104,10 @@ module Mapricot
104
104
 
105
105
  # client.geocoding: the /geocoding/v1 endpoints.
106
106
  class GeocodingService
107
- def initialize(get)
107
+ def initialize(get, post, query_value)
108
108
  @get = get
109
+ @post = post
110
+ @query_value = query_value
109
111
  end
110
112
 
111
113
  # Find addresses and places matching free text. focus is {lat:, lon:}; country is an Array or a String.
@@ -113,6 +115,14 @@ module Mapricot
113
115
  @get.call("/geocoding/v1/search", q: q, focus: focus, country: country, limit: limit, lang: lang)
114
116
  end
115
117
 
118
+ # Run up to 100 searches in one request, each a Hash of search's parameters, as in { q: "…", limit: 1 }. Each
119
+ # completed search is billed as one request. "responses" answers them in order, each with "results" and
120
+ # "attribution", or an "error" with the code and message the search would get on its own, which isn't raised.
121
+ def search_batch(queries)
122
+ body = { queries: queries.map { |query| query.compact.transform_values { |value| @query_value.call(value) } } }
123
+ @post.call("/geocoding/v1/search/batch", body)
124
+ end
125
+
116
126
  # Suggest addresses and places as someone types.
117
127
  def autocomplete(q, focus: nil, country: nil, limit: nil, lang: nil)
118
128
  @get.call("/geocoding/v1/autocomplete", q: q, focus: focus, country: country, limit: limit, lang: lang)
@@ -149,24 +159,25 @@ module Mapricot
149
159
 
150
160
  # Find a route through 2 to 20 waypoints, each {lat:, lon:}. mode is "drive" (the default), "walk", or "bicycle".
151
161
  # geometries is "polyline" (the default), "polyline6", or "geojson". steps: true adds each leg's turn-by-turn
152
- # steps, in lang, an ISO 639-1 language, English by default.
153
- def route(waypoints, mode: nil, geometries: nil, steps: nil, lang: nil)
154
- body = { waypoints: waypoints, mode: mode, geometries: geometries, steps: steps, lang: lang }
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 }
155
166
  @post.call("/routing/v1/route", body)
156
167
  end
157
168
 
158
169
  # Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. It
159
170
  # takes the same arguments as route, and the route adds "waypointOrder": the indexes of the waypoints sent, in
160
171
  # visiting order.
161
- def optimize(waypoints, mode: nil, geometries: nil, steps: nil, lang: nil)
162
- 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 }
163
174
  @post.call("/routing/v1/optimize", body)
164
175
  end
165
176
 
166
177
  # The areas reachable from a location, {lat:, lon:}, within 1 to 4 times, each 1 to 60 minutes, as a GeoJSON
167
- # FeatureCollection with one polygon per time, largest first. mode is as for route.
168
- def isochrone(location, minutes, mode: nil)
169
- @post.call("/routing/v1/isochrone", { location: location, minutes: minutes, mode: mode })
178
+ # FeatureCollection with one polygon per time, largest first. mode and costing are as for route.
179
+ def isochrone(location, minutes, mode: nil, costing: nil)
180
+ @post.call("/routing/v1/isochrone", { location: location, minutes: minutes, mode: mode, costing: costing })
170
181
  end
171
182
  end
172
183
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapricot-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mapricot