mapricot-api 0.7.0 → 0.9.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 +11 -0
  3. data/lib/mapricot/api.rb +21 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85ceb14ed10d1d3499221e1e2f4378cd3e40c58b4b3274e341004452bc873518
4
- data.tar.gz: 3a01af9ed6d7431e07255bb635e09d77dd01232c613b9a469da9815d601cd659
3
+ metadata.gz: a4ab17244df7dcde59e10619f66ad46c84678daaead1900996dc8a284500e8f8
4
+ data.tar.gz: 7b39f91e9e319ce5caa5600ab88bf5af044ad5749f3c114b8f9198535dcf918d
5
5
  SHA512:
6
- metadata.gz: 46a943e94e0f8c2d0d22ddb9d1f7857034b6599fa87633ddbf3d71b982172abf70f096edfbf560b139a0f7a00708d0ef8f5c9a85e2bd97671ec7268c391f8eb1
7
- data.tar.gz: e5d5becbf5f3de0301f40963ef84317efde3f606ebca3a90050a2c2e98ec23ba3d631e54274f5f3c97fd0aeda837a9a69328bec76c2ff5c872152b1347f98779
6
+ metadata.gz: fd4c75fbb3ef76fe024d05639c0f6173c8916a920529d551fbd60023da3b40b26bed1efa2b4c9db9620654ecdde982cbf3b4e537fa74ca033da17649f5fb5d27
7
+ data.tar.gz: 80479d041ae94f4aed582895c778aff3e52979cc12742934ecdbabb2123599e22fea02c8bb7a7aae99e0e0b78f177db588ce632c40c4e5c40842a3f4be722aed
data/README.md CHANGED
@@ -29,11 +29,13 @@ 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
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) |
37
39
  | `client.routing.isochrone(location, minutes, mode:)` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
38
40
  | `client.ip_geolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
39
41
  | `client.account` | `GET /account`, which checks a key and is never billed |
@@ -46,10 +48,19 @@ route = client.routing.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214,
46
48
  puts route["routes"][0]["durationSeconds"]
47
49
  ```
48
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
+
49
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.
50
59
 
51
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"`.
52
61
 
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
+
53
64
  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:
54
65
 
55
66
  ```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.7.0"
10
+ VERSION = "0.9.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)
@@ -155,6 +165,14 @@ module Mapricot
155
165
  @post.call("/routing/v1/route", body)
156
166
  end
157
167
 
168
+ # Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. It
169
+ # takes the same arguments as route, and the route adds "waypointOrder": the indexes of the waypoints sent, in
170
+ # 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 }
173
+ @post.call("/routing/v1/optimize", body)
174
+ end
175
+
158
176
  # The areas reachable from a location, {lat:, lon:}, within 1 to 4 times, each 1 to 60 minutes, as a GeoJSON
159
177
  # FeatureCollection with one polygon per time, largest first. mode is as for route.
160
178
  def isochrone(location, minutes, mode: nil)
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.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mapricot