mapricot-api 0.4.0 → 0.5.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 +8 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae3337cb4d6ca5a0dccab35644cf1ca98dde37f7bd74c0cd774a5be50f0e45c4
4
- data.tar.gz: 1bc1b3b515d89b390f99fc3e1c2cbca1572503fa040b4957c95158e61a6e4834
3
+ metadata.gz: 24849159506d71db67b1e674bf3cf9377f218c78260002730a2f1dab55b713f9
4
+ data.tar.gz: '07499083f22bd04f51f65704bb24e204c0f7767564e84de4f92114c6836aa09e'
5
5
  SHA512:
6
- metadata.gz: ec3514b04cdfbd59b403c83ddd2004d1ab364e41e0f1aafd7f43326def0cb5cb8352f78486ecf972ab62f4c4deeddaf14f4f411faf412af4da7302010c3a8e9d
7
- data.tar.gz: f09e7c6d84856e8bb8fb5210488c98fa300750d488ace6576204988acd33f3d427b09ca25c6a2cc1309ec0dd6e5f0a2fd65d7c15fe9c8ebc103bca7dbf077f67
6
+ metadata.gz: 1b921d6fabb89653dbde12a181390f618e547dada82ea5587108d2e0acc069d8b43e1c427d30d96cf1abe2807933b670462f779aebe4e4499b0b20c23a045b13
7
+ data.tar.gz: e1f406517e97e473fcc7eece8890e609d26c2921523cb88e18c23f72bc84258d553e540b9e9724d883b057722c6137fd79327b04e75fb72b5d331de1e569dc88
data/README.md CHANGED
@@ -34,6 +34,7 @@ Each method returns the API's JSON as a Hash with string keys, with the same fie
34
34
  | `client.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
35
35
  | `client.place(id, lang:)` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
36
36
  | `client.route(waypoints, mode:, geometries:)` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
37
+ | `client.isochrone(location, minutes, mode:)` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
37
38
  | `client.ip(address)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
38
39
  | `client.account` | `GET /account`, which checks a key and is never billed |
39
40
 
@@ -47,6 +48,13 @@ puts route["routes"][0]["durationSeconds"]
47
48
 
48
49
  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.
49
50
 
51
+ 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:
52
+
53
+ ```ruby
54
+ area = client.isochrone({ lat: 45.5189, lon: -122.6793 }, [5, 10], mode: "walk")
55
+ puts area["features"].map { |feature| feature["properties"]["minutes"] }.inspect
56
+ ```
57
+
50
58
  If your app shows results, show the credits in each response's `attribution`.
51
59
 
52
60
  ## Errors and retries
data/lib/mapricot/api.rb CHANGED
@@ -6,7 +6,7 @@ require "net/http"
6
6
  # The official client for the Mapricot API: address and place search, reverse geocoding, nearby places, routing,
7
7
  # and IP geolocation. See https://mapricot.com/docs/ruby/.
8
8
  module Mapricot
9
- VERSION = "0.4.0"
9
+ VERSION = "0.5.0"
10
10
 
11
11
  # An error response from the API.
12
12
  class Error < StandardError
@@ -63,6 +63,13 @@ module Mapricot
63
63
  request(Net::HTTP::Post, URI("#{@base_url}/routing/v1/route"), JSON.generate(body))
64
64
  end
65
65
 
66
+ # The areas reachable from a location, {lat:, lon:}, within 1 to 4 times, each 1 to 60 minutes, as a GeoJSON
67
+ # FeatureCollection with one polygon per time, largest first. mode is as for route.
68
+ def isochrone(location, minutes, mode: nil)
69
+ body = { location: location, minutes: minutes, mode: mode }.compact
70
+ request(Net::HTTP::Post, URI("#{@base_url}/routing/v1/isochrone"), JSON.generate(body))
71
+ end
72
+
66
73
  # Approximate location of a public IP address.
67
74
  def ip(address)
68
75
  get("/ip-geolocation/v1/#{escape(address)}")
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mapricot