~ihabunek/triglav

e4647d20772c2ca6302f9907410ecd18f5955a13 — Ivan Habunek a month ago 2b49fb9
Improve naming and typespec
1 files changed, 5 insertions(+), 5 deletions(-)

M lib/triglav/autotrolej/api.ex
M lib/triglav/autotrolej/api.ex => lib/triglav/autotrolej/api.ex +5 -5
@@ 35,16 35,16 @@ defmodule Triglav.Autotrolej.Api do
          variant: String.t()
        }

  @spec fetch_stops() :: {:ok, [stop()]} | {:error, Tesla.Ent.t()}
  @spec fetch_stops() :: {:ok, [stop()]} | {:error, Tesla.Env.t()}
  def fetch_stops() do
    with {:ok, data} <- do_get("/ATstanice.json") do
    with {:ok, data} <- fetch("/ATstanice.json") do
      {:ok, Enum.map(data, &convert_stop/1)}
    end
  end

  # @spec fetch_routes() :: {:ok, [route()]} | {:error, Tesla.Ent.t()}
  @spec fetch_routes() :: {:ok, [route()]} | {:error, Tesla.Env.t()}
  def fetch_routes() do
    with {:ok, data} <- do_get("/ATlinije.json") do
    with {:ok, data} <- fetch("/ATlinije.json") do
      stops =
        data
        |> Stream.dedup_by(&Map.drop(&1, ["Id"]))


@@ 76,7 76,7 @@ defmodule Triglav.Autotrolej.Api do
    }
  end

  defp do_get(path) do
  defp fetch(path) do
    with {:ok, response} <- get(path) do
      if response.status == 200, do: {:ok, response.body}, else: {:error, response}
    end