Build a URL shortener API
The following endpoints must be implemented:
# This file contains the configuration for Credo and you are probably reading | |
# this after creating it with `mix credo.gen.config`. | |
# | |
# If you find anything wrong or unclear in this file, please report an | |
# issue on GitHub: https://github.com/rrrene/credo/issues | |
# | |
%{ | |
# | |
# You can have as many configs as you like in the `configs:` field. | |
configs: [ |
defmodule DecryptPayload do | |
@moduledoc """ | |
Decrypts payload | |
""" | |
def run(payload_hex, key_hex, iv_hex) do | |
payload_bytes = payload_hex |> Base.decode16! | |
key_bytes = key_hex |> Base.decode16! | |
iv_bytes = iv_hex |> Base.decode16! |
Based on my blog post
defmodule Legolas.Geolocation do | |
@moduledoc """ | |
Public interface for all geolocation related functionality | |
""" | |
alias Legolas.Geolocation.Cache | |
alias Legolas.Geolocation.CityLocation | |
alias Legolas.Geolocation.GoogleMaps.Client | |
@type address :: {zip :: String.t, city :: String.t, country :: String.t} |
children = [ | |
# Many children here | |
# ... | |
MyProject.Geolocation | |
] | |
opts = [strategy: :one_for_one, name: MyProject.Supervisor] | |
Supervisor.start_link(children, opts) |
alias MyProject.Geolocation.Cache | |
def child_spec([]) do | |
%{ | |
id: __MODULE__, | |
start: {Cache, :start_link, []} | |
} | |
end |
@type address :: {zip :: String.t, city :: String.t, country :: String.t} | |
@type geolocation :: {latitude :: number, longitude :: number} | |
@doc """ | |
Finds the geolocation for the given address | |
""" | |
@spec lookup(address) :: {:ok, geolocation} | {:error, any} | |
def lookup(address) do | |
# Logic that calls the inner modules | |
end |