mapricot-api 0.1.0 → 0.2.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 +3 -9
- data/lib/mapricot/api.rb +3 -3
- 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: f71eb9fc26e529343c43b463d9c39a189f27393570c7e4f874481f352e58246e
|
|
4
|
+
data.tar.gz: 05eadfb4de87fa10ac0b07bc7e7684f2835cb84c1677bf13b29e1107d7603609
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b14fc259f3e6de0025ccfeb767fb4e0d5f7971f4fb082252e9485f7bd59bbd3a744a6279afc88159ffca4bd263e04e6efc6c0b9f85bcb1371e30c3795d45994
|
|
7
|
+
data.tar.gz: a6d53c8cd4b0c370137491aa6862e30f1d8a457a2b870611b5bc519147fa3eb1f05b1725170b91877c19bfe2a3a18c8a9ee3626e0a6c8e26329ce942e5cd5c5e
|
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
|
|
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/).
|
|
@@ -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/
|
|
48
|
+
A route's `polyline` is encoded with six decimal places. Decode it with precision 6, as [decoding a route polyline](https://mapricot.com/guides/polyline-decoder/) shows.
|
|
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.
|
|
9
|
+
VERSION = "0.2.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
|
|
26
|
-
raise ArgumentError, "Pass api_key
|
|
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
|