defmodule Util do @moduledoc """ Util module containing helpful functions used in the project. """ @doc """ Function for format string and replace spaces with '+' for url format. ## Parameters - text (string): Text to be formatted in the url format. ## Examples iex> Util.format_string("Macabra Pune") "Macabra+Pune" """ def format_string(text) do text |> String.trim |> String.replace(" ", "+") end @doc """ Function to extract the body from the response hash map. ## Parameters - response (HTTPoison.Response): A response from httpoison request. ## Examples iex> Util.extract_body(response) {:ok, body} """ def extract_body(response) do case response do %HTTPoison.Response{body: body, status_code: 200} -> {:ok, body} %HTTPoison.Response{body: _, status_code: status_code} -> {:error, "Error #{status_code} in request."} _ -> {:error, "Unable to parse response."} end end end