mapricot-api 0.2.0 → 0.4.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 +9 -9
- data/lib/mapricot/api.rb +12 -11
- 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: ae3337cb4d6ca5a0dccab35644cf1ca98dde37f7bd74c0cd774a5be50f0e45c4
|
|
4
|
+
data.tar.gz: 1bc1b3b515d89b390f99fc3e1c2cbca1572503fa040b4957c95158e61a6e4834
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec3514b04cdfbd59b403c83ddd2004d1ab364e41e0f1aafd7f43326def0cb5cb8352f78486ecf972ab62f4c4deeddaf14f4f411faf412af4da7302010c3a8e9d
|
|
7
|
+
data.tar.gz: f09e7c6d84856e8bb8fb5210488c98fa300750d488ace6576204988acd33f3d427b09ca25c6a2cc1309ec0dd6e5f0a2fd65d7c15fe9c8ebc103bca7dbf077f67
|
data/README.md
CHANGED
|
@@ -28,14 +28,14 @@ Each method returns the API's JSON as a Hash with string keys, with the same fie
|
|
|
28
28
|
|
|
29
29
|
| Method | Endpoint |
|
|
30
30
|
| --- | --- |
|
|
31
|
-
| `client.search(q, focus:, country:, limit:, lang:)` | [`GET /v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
|
|
32
|
-
| `client.autocomplete(q, focus:, country:, limit:, lang:)` | [`GET /v1/autocomplete`](https://mapricot.com/docs/
|
|
33
|
-
| `client.reverse(lat, lon, limit:, lang:)` | [`GET /v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
|
|
34
|
-
| `client.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
|
|
35
|
-
| `client.place(id, lang:)` | [`GET /v1/
|
|
36
|
-
| `client.route(waypoints, mode:)` | [`POST /v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
|
|
37
|
-
| `client.ip(address)` | [`GET /v1/
|
|
38
|
-
| `client.account` | `GET /
|
|
31
|
+
| `client.search(q, focus:, country:, limit:, lang:)` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
|
|
32
|
+
| `client.autocomplete(q, focus:, country:, limit:, lang:)` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
|
|
33
|
+
| `client.reverse(lat, lon, limit:, lang:)` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
|
|
34
|
+
| `client.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
|
|
35
|
+
| `client.place(id, lang:)` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
|
|
36
|
+
| `client.route(waypoints, mode:, geometries:)` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
|
|
37
|
+
| `client.ip(address)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
|
|
38
|
+
| `client.account` | `GET /account`, which checks a key and is never billed |
|
|
39
39
|
|
|
40
40
|
Every keyword argument is optional. `focus` and each waypoint are `{ lat:, lon: }`. `country` and `category` take an Array or a comma-separated String.
|
|
41
41
|
|
|
@@ -45,7 +45,7 @@ route = client.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214, lon: -12
|
|
|
45
45
|
puts route["routes"][0]["durationSeconds"]
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
A route's `polyline`
|
|
48
|
+
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
49
|
|
|
50
50
|
If your app shows results, show the credits in each response's `attribution`.
|
|
51
51
|
|
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.
|
|
9
|
+
VERSION = "0.4.0"
|
|
10
10
|
|
|
11
11
|
# An error response from the API.
|
|
12
12
|
class Error < StandardError
|
|
@@ -33,43 +33,44 @@ module Mapricot
|
|
|
33
33
|
|
|
34
34
|
# Find addresses and places matching free text. focus is {lat:, lon:}; country is an Array or a String.
|
|
35
35
|
def search(q, focus: nil, country: nil, limit: nil, lang: nil)
|
|
36
|
-
get("/v1/search", q: q, focus: focus, country: country, limit: limit, lang: lang)
|
|
36
|
+
get("/geocoding/v1/search", q: q, focus: focus, country: country, limit: limit, lang: lang)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# Suggest addresses and places as someone types.
|
|
40
40
|
def autocomplete(q, focus: nil, country: nil, limit: nil, lang: nil)
|
|
41
|
-
get("/v1/autocomplete", q: q, focus: focus, country: country, limit: limit, lang: lang)
|
|
41
|
+
get("/geocoding/v1/autocomplete", q: q, focus: focus, country: country, limit: limit, lang: lang)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# Find the address nearest a coordinate, or the area around it.
|
|
45
45
|
def reverse(lat, lon, limit: nil, lang: nil)
|
|
46
|
-
get("/v1/reverse", lat: lat, lon: lon, limit: limit, lang: lang)
|
|
46
|
+
get("/geocoding/v1/reverse", lat: lat, lon: lon, limit: limit, lang: lang)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# List places around a coordinate, optionally by category, an Array or a String.
|
|
50
50
|
def nearby(lat, lon, category: nil, radius: nil, limit: nil, lang: nil)
|
|
51
|
-
get("/v1/nearby", lat: lat, lon: lon, category: category, radius: radius, limit: limit, lang: lang)
|
|
51
|
+
get("/places/v1/nearby", lat: lat, lon: lon, category: category, radius: radius, limit: limit, lang: lang)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Look up one place by its Mapricot ID.
|
|
55
55
|
def place(id, lang: nil)
|
|
56
|
-
get("/v1
|
|
56
|
+
get("/places/v1/#{escape(id)}", lang: lang)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# Find a route through 2 to 20 waypoints, each {lat:, lon:}. mode is "drive" (the default), "walk", or "bicycle".
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
# geometries is "polyline" (the default), "polyline6", or "geojson".
|
|
61
|
+
def route(waypoints, mode: nil, geometries: nil)
|
|
62
|
+
body = { waypoints: waypoints, mode: mode, geometries: geometries }.compact
|
|
63
|
+
request(Net::HTTP::Post, URI("#{@base_url}/routing/v1/route"), JSON.generate(body))
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
# Approximate location of a public IP address.
|
|
66
67
|
def ip(address)
|
|
67
|
-
get("/v1
|
|
68
|
+
get("/ip-geolocation/v1/#{escape(address)}")
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
# The key's account. Not billed, so it checks a key for free.
|
|
71
72
|
def account
|
|
72
|
-
get("/
|
|
73
|
+
get("/account")
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
private
|