mapricot-api 0.8.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 +8 -0
  3. data/lib/mapricot/api.rb +13 -3
  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: a4ab17244df7dcde59e10619f66ad46c84678daaead1900996dc8a284500e8f8
4
+ data.tar.gz: 7b39f91e9e319ce5caa5600ab88bf5af044ad5749f3c114b8f9198535dcf918d
5
5
  SHA512:
6
- metadata.gz: 156e3cfd96b2ed32b0fa917d973852cf7df03421ad49b96d89fd4c5ff66dd6bbe3a601a9cfdd6ba95af616e48360ae0ef63127f4402ca1a94cfe22b21558e295
7
- data.tar.gz: 0df9af5005e818d9ef4553fb6b11ada8d1e04d8de040682c2ede03f3ef3990983112e0161affee1d0a8cf4aa8f0d3e84bcd4bf0551bd8ec07d1a333f21c7ee8d
6
+ metadata.gz: fd4c75fbb3ef76fe024d05639c0f6173c8916a920529d551fbd60023da3b40b26bed1efa2b4c9db9620654ecdde982cbf3b4e537fa74ca033da17649f5fb5d27
7
+ data.tar.gz: 80479d041ae94f4aed582895c778aff3e52979cc12742934ecdbabb2123599e22fea02c8bb7a7aae99e0e0b78f177db588ce632c40c4e5c40842a3f4be722aed
data/README.md CHANGED
@@ -29,6 +29,7 @@ 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) |
@@ -47,6 +48,13 @@ 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"`.
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.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)
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.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mapricot