changed README.md
 
@@ -10,7 +10,7 @@ by adding `geospatial` to your list of dependencies in `mix.exs`:
10
10
```elixir
11
11
def deps do
12
12
[
13
- {:geospatial, "~> 0.1.0"}
13
+ {:geospatial, "~> 0.2.0"}
14
14
]
15
15
end
16
16
```
changed hex_metadata.config
 
@@ -37,4 +37,4 @@
37
37
{<<"optional">>,false},
38
38
{<<"repository">>,<<"hexpm">>},
39
39
{<<"requirement">>,<<"~> 1.6">>}]]}.
40
- {<<"version">>,<<"0.1.0">>}.
40
+ {<<"version">>,<<"0.2.0">>}.
changed lib/providers/google_maps.ex
 
@@ -76,6 +76,30 @@ defmodule Geospatial.Providers.GoogleMaps do
76
76
end
77
77
end
78
78
79
+ @impl Provider
80
+ @doc """
81
+ Google Maps implementation for `c:Geospatial.Providers.Provider.get_by_id/2`.
82
+ """
83
+ @spec get_by_id(String.t(), keyword()) :: list(Address.t())
84
+ def get_by_id(id, options \\ []) do
85
+ url = build_url(:place_details, %{place_id: id}, options)
86
+
87
+ Logger.debug("Asking Google Maps for address with #{url}")
88
+
89
+ %Tesla.Env{status: 200, body: body} = HTTP.get!(url)
90
+
91
+ case body do
92
+ %{"result" => result, "status" => "OK"} ->
93
+ [process_data(result, options)]
94
+
95
+ %{"status" => "REQUEST_DENIED", "error_message" => error_message} ->
96
+ raise ArgumentError, message: to_string(error_message)
97
+
98
+ %{"status" => "ZERO_RESULTS"} ->
99
+ []
100
+ end
101
+ end
102
+
79
103
@spec build_url(:search | :geocode | :place_details, map(), list()) :: String.t() | no_return
80
104
defp build_url(method, args, options) do
81
105
limit = Keyword.get(options, :limit, 10)
changed lib/providers/pelias.ex
 
@@ -39,11 +39,23 @@ defmodule Geospatial.Providers.Pelias do
39
39
|> fetch_features
40
40
end
41
41
42
+ @impl Provider
43
+ @doc """
44
+ Pelias implementation for `c:Geospatial.Providers.Provider.get_by_id/2`.
45
+ """
46
+ @spec get_by_id(String.t(), keyword()) :: list(Address.t())
47
+ def get_by_id(id, options \\ []) do
48
+ :get_by_id
49
+ |> build_url(%{id: id}, options)
50
+ |> fetch_features
51
+ end
52
+
42
53
@spec build_url(atom(), map(), list()) :: String.t()
43
54
defp build_url(method, args, options) do
44
55
limit = Keyword.get(options, :limit, 10)
45
56
lang = Keyword.get(options, :lang, "en")
46
57
endpoint = Keyword.get(options, :endpoint, endpoint(__MODULE__))
58
+ auth = [api_key: Keyword.get(options, :api_key, api_key())]
47
59
48
60
url =
49
61
case method do
 
@@ -54,9 +66,14 @@ defmodule Geospatial.Providers.Pelias do
54
66
55
67
:geocode ->
56
68
"#{endpoint}/v1/reverse?point.lon=#{args.lon}&point.lat=#{args.lat}"
69
+
70
+ :get_by_id ->
71
+ "#{endpoint}/v1/place?ids=#{args.id}"
57
72
end
58
73
59
- add_parameter(url, options, :country_code)
74
+ url
75
+ |> add_parameter(options, :country_code)
76
+ |> add_parameter(auth, :api_key)
60
77
end
61
78
62
79
@spec fetch_features(String.t()) :: list(Address.t())
 
@@ -93,7 +110,7 @@ defmodule Geospatial.Providers.Pelias do
93
110
description: Map.get(properties, "name"),
94
111
postal_code: Map.get(properties, "postalcode"),
95
112
street: street_address(properties),
96
- origin_id: "#{Map.get(properties, "id")}",
113
+ origin_id: "#{Map.get(properties, "gid")}",
97
114
origin_provider: "pelias",
98
115
type: get_type(properties)
99
116
}
 
@@ -146,4 +163,11 @@ defmodule Geospatial.Providers.Pelias do
146
163
147
164
defp do_add_parameter(url, :country_code, country_code),
148
165
do: "#{url}&boundary.country=#{country_code}"
166
+
167
+ defp do_add_parameter(url, :api_key, api_key),
168
+ do: "#{url}&api_key=#{api_key}"
169
+
170
+ defp api_key do
171
+ Application.get_env(:geospatial, __MODULE__) |> get_in([:api_key])
172
+ end
149
173
end
changed lib/providers/photon.ex
 
@@ -4,7 +4,7 @@
4
4
5
5
defmodule Geospatial.Providers.Photon do
6
6
@moduledoc """
7
- [Photon](https://photon.komoot.de) backend.
7
+ [Photon](https://photon.komoot.io) backend.
8
8
"""
9
9
10
10
alias Geospatial.Address
changed lib/providers/provider.ex
 
@@ -9,7 +9,7 @@ defmodule Geospatial.Providers.Provider do
9
9
## Supported backends
10
10
11
11
* `Geospatial.Providers.Nominatim` [🔗](https://wiki.openstreetmap.org/wiki/Nominatim)
12
- * `Geospatial.Providers.Photon` [🔗](https://photon.komoot.de)
12
+ * `Geospatial.Providers.Photon` [🔗](https://photon.komoot.io)
13
13
* `Geospatial.Providers.Addok` [🔗](https://github.com/addok/addok)
14
14
* `Geospatial.Providers.MapQuest` [🔗](https://developer.mapquest.com/documentation/open/)
15
15
* `Geospatial.Providers.GoogleMaps` [🔗](https://developers.google.com/maps/documentation/geocoding/intro)
changed mix.exs
 
@@ -6,7 +6,7 @@ defmodule Geospatial.MixProject do
6
6
def project do
7
7
[
8
8
app: :geospatial,
9
- version: "0.1.0",
9
+ version: "0.2.0",
10
10
elixir: "~> 1.9",
11
11
build_embedded: Mix.env() == :prod,
12
12
start_permanent: Mix.env() == :prod,
 
@@ -29,7 +29,8 @@ defmodule Geospatial.MixProject do
29
29
{:geo, "~> 3.4"},
30
30
{:tz_world, "~> 1.0"},
31
31
{:mox, "~> 1.0", only: :test},
32
- {:hackney, "~> 1.6"}
32
+ {:hackney, "~> 1.6"},
33
+ {:ex_doc, "~> 0.29", only: :dev, runtime: false}
33
34
]
34
35
end