Created
November 19, 2015 22:54
-
-
Save danmcclain/b3ba06da0a73d7aee5d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Logobase.Deserializer do | |
def init(options) do | |
options | |
end | |
def call(conn, _opts) do | |
case Phoenix.Controller.get_format(conn) do | |
"json-api" -> | |
_deserialize(conn) | |
_ -> | |
conn | |
end | |
end | |
defp _deserialize(%Plug.Conn{}=conn) do | |
Map.put(conn, :params, _deserialize(conn.params)) | |
end | |
defp _deserialize(%{}=params) do | |
Enum.into(params, %{}, fn({key, value}) -> { _underscore(key), _deserialize(value) } end) | |
end | |
defp _deserialize(value), do: value | |
defp _underscore(key), do: String.replace(key, "-", "_") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment