mapricot-api 0.1.0 → 0.3.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 +4 -10
  3. data/lib/mapricot/api.rb +6 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31d656521ae328f37c56e40ebc8be88f9dcfb2157c530df0af8506239f0926bc
4
- data.tar.gz: 947d9768c032efb16d615f0d662636006376dc0935164d0f357fbebbc61d7f18
3
+ metadata.gz: 738ae3f3ba9a75663dfabf87e3009bb28f583a6b4f8beb9b3ff43fc823e95762
4
+ data.tar.gz: e883dc44c7857e96e357bfcce39ecfb98280e3c7a4c2b083a805ff006d2be46f
5
5
  SHA512:
6
- metadata.gz: b797cf979be35da5c8bcdcf14262e8b989b85e61718c2154bee7e20d1e1644bf14f03da1c8ded58821c457f1983c53df7911517f0c2664902171418bc9f1aca8
7
- data.tar.gz: 2687accc178bff6578f19d3f45abeb42749c69c84d623f18a84eae2050c342297b60bb3a32bfeafdd741c7240718de4a9112462b7dc226e9e4f660a3992ce4fb
6
+ metadata.gz: 0d71ee623decdd044207a89c64996367c031c740b6e3c7f72d836398c1f2f188c58b69a08456a2a494c9e94db2dea5d2ebc2d5de3d8972359b0399cda682af04
7
+ data.tar.gz: 299ffab402dfea95b853569fb4c25c145b525252e2fab8b90bf8c4e9375865b7f416fbda2de6d659c54e18dff3cd3494b5c431f67a998257725ab1122f5aebcc
data/README.md CHANGED
@@ -10,24 +10,18 @@ It needs Ruby 3.1 or later and has no dependencies outside the standard library.
10
10
 
11
11
  ## Quick start
12
12
 
13
- Create a server key in the [dashboard](https://app.mapricot.com/) and set it as `MAPRICOT_KEY`:
14
-
15
- ```sh
16
- export MAPRICOT_KEY="mapricot_sk_…"
17
- ```
13
+ Create a server key in the [dashboard](https://app.mapricot.com/) and pass it to the client. Keep it out of your source code, for example by reading it from an environment variable as here.
18
14
 
19
15
  ```ruby
20
16
  require "mapricot/api"
21
17
 
22
- client = Mapricot::Client.new
18
+ client = Mapricot::Client.new(api_key: ENV.fetch("MAPRICOT_KEY"))
23
19
 
24
20
  data = client.search("128 SW 3rd Ave, Portland", limit: 1)
25
21
  place = data["results"][0]
26
22
  puts place["label"], place["lat"], place["lon"]
27
23
  ```
28
24
 
29
- Pass the key yourself with `Mapricot::Client.new(api_key: "mapricot_sk_…")`.
30
-
31
25
  ## Methods
32
26
 
33
27
  Each method returns the API's JSON as a Hash with string keys, with the same field names as the [API reference](https://mapricot.com/api-reference/).
@@ -39,7 +33,7 @@ Each method returns the API's JSON as a Hash with string keys, with the same fie
39
33
  | `client.reverse(lat, lon, limit:, lang:)` | [`GET /v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
40
34
  | `client.nearby(lat, lon, category:, radius:, limit:, lang:)` | [`GET /v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
41
35
  | `client.place(id, lang:)` | [`GET /v1/places/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
42
- | `client.route(waypoints, mode:)` | [`POST /v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
36
+ | `client.route(waypoints, mode:, geometries:)` | [`POST /v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
43
37
  | `client.ip(address)` | [`GET /v1/ip/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
44
38
  | `client.account` | `GET /v1/account`, which checks a key and is never billed |
45
39
 
@@ -51,7 +45,7 @@ route = client.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214, lon: -12
51
45
  puts route["routes"][0]["durationSeconds"]
52
46
  ```
53
47
 
54
- A route's `polyline` is encoded with six decimal places. Decode it with precision 6, as [decoding a route polyline](https://mapricot.com/docs/polyline/) shows.
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.
55
49
 
56
50
  If your app shows results, show the credits in each response's `attribution`.
57
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.1.0"
9
+ VERSION = "0.3.0"
10
10
 
11
11
  # An error response from the API.
12
12
  class Error < StandardError
@@ -22,8 +22,8 @@ module Mapricot
22
22
 
23
23
  # Each method returns the API's JSON as a Hash with string keys, as in https://mapricot.com/api-reference/.
24
24
  class Client
25
- def initialize(api_key: ENV["MAPRICOT_KEY"], base_url: "https://api.mapricot.com", timeout: 30, max_retries: 2)
26
- raise ArgumentError, "Pass api_key: or set MAPRICOT_KEY." if api_key.nil? || api_key.empty?
25
+ def initialize(api_key:, base_url: "https://api.mapricot.com", timeout: 30, max_retries: 2)
26
+ raise ArgumentError, "Pass api_key:, a Mapricot key." if api_key.nil? || api_key.empty?
27
27
 
28
28
  @api_key = api_key
29
29
  @base_url = base_url
@@ -57,8 +57,9 @@ module Mapricot
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
- def route(waypoints, mode: nil)
61
- body = { waypoints: waypoints, mode: mode }.compact
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
62
63
  request(Net::HTTP::Post, URI("#{@base_url}/v1/route"), JSON.generate(body))
63
64
  end
64
65
 
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mapricot