Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -93,7 +93,8 @@ defmodule Mobilizon.Service.Geospatial.Addok do
|
||||
if is_nil(value), do: url, else: do_add_parameter(url, key, value)
|
||||
end
|
||||
|
||||
@spec do_add_parameter(String.t(), atom(), any()) :: String.t()
|
||||
@spec do_add_parameter(String.t(), :coords | :type, %{lat: float, lon: float} | :administrative) ::
|
||||
String.t()
|
||||
defp do_add_parameter(url, :coords, coords),
|
||||
do: "#{url}&lat=#{coords.lat}&lon=#{coords.lon}"
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
@doc """
|
||||
Google Maps implementation for `c:Mobilizon.Service.Geospatial.Provider.geocode/3`.
|
||||
"""
|
||||
@spec geocode(String.t(), keyword()) :: list(Address.t())
|
||||
@spec geocode(String.t(), keyword()) :: list(Address.t()) | no_return
|
||||
def geocode(lon, lat, options \\ []) do
|
||||
url = build_url(:geocode, %{lon: lon, lat: lat}, options)
|
||||
|
||||
@@ -50,7 +50,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
@doc """
|
||||
Google Maps implementation for `c:Mobilizon.Service.Geospatial.Provider.search/2`.
|
||||
"""
|
||||
@spec search(String.t(), keyword()) :: list(Address.t())
|
||||
@spec search(String.t(), keyword()) :: list(Address.t()) | no_return
|
||||
def search(q, options \\ []) do
|
||||
url = build_url(:search, %{q: q}, options)
|
||||
|
||||
@@ -68,7 +68,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
end
|
||||
end
|
||||
|
||||
@spec build_url(atom(), map(), list()) :: String.t()
|
||||
@spec build_url(atom(), map(), list()) :: String.t() | no_return
|
||||
defp build_url(method, args, options) do
|
||||
limit = Keyword.get(options, :limit, 10)
|
||||
lang = Keyword.get(options, :lang, "en")
|
||||
@@ -148,6 +148,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
end
|
||||
end
|
||||
|
||||
@spec do_fetch_place_details(String.t() | nil, Keyword.t()) :: String.t() | no_return
|
||||
defp do_fetch_place_details(place_id, options) do
|
||||
url = build_url(:place_details, %{place_id: place_id}, options)
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ defmodule Mobilizon.Service.Geospatial.Provider do
|
||||
iex> geocode(48.11, -1.77)
|
||||
%Address{}
|
||||
"""
|
||||
@callback geocode(longitude :: number, latitude :: number, options :: keyword) :: [Address.t()]
|
||||
@callback geocode(longitude :: number, latitude :: number, options :: keyword) ::
|
||||
[Address.t()] | {:error, atom()}
|
||||
|
||||
@doc """
|
||||
Search for an address
|
||||
@@ -62,12 +63,12 @@ defmodule Mobilizon.Service.Geospatial.Provider do
|
||||
iex> search("10 rue Jangot")
|
||||
%Address{}
|
||||
"""
|
||||
@callback search(address :: String.t(), options :: keyword) :: [Address.t()]
|
||||
@callback search(address :: String.t(), options :: keyword) :: [Address.t()] | {:error, atom()}
|
||||
|
||||
@doc """
|
||||
Returns a `Geo.Point` for given coordinates
|
||||
"""
|
||||
@spec coordinates([number], number) :: Geo.Point.t() | nil
|
||||
@spec coordinates([number | String.t()], number) :: Geo.Point.t() | nil
|
||||
def coordinates(coords, srid \\ 4326)
|
||||
|
||||
def coordinates([x, y], srid) when is_number(x) and is_number(y) do
|
||||
|
||||
Reference in New Issue
Block a user