Skip to content

Commit

Permalink
Use the 'keys: :atoms' option for Poison, instead of String.to_atom
Browse files Browse the repository at this point in the history
  • Loading branch information
jwarlander committed Oct 12, 2016
1 parent 6d06d94 commit 53feab2
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions lib/dayron/adapters/httpoison_adapter.ex
Expand Up @@ -17,7 +17,6 @@ defmodule Dayron.HTTPoisonAdapter do
json responses to Maps or a List of Maps. Maps keys are also converted to
atoms by default.
"""
require Crutches
require Poison
use HTTPoison.Base

Expand All @@ -28,21 +27,11 @@ defmodule Dayron.HTTPoisonAdapter do

def process_response_body(body) do
try do
body |> Poison.decode! |> process_decoded_body
body |> Poison.decode!(keys: :atoms)
rescue
Poison.SyntaxError -> body
end
end

defp process_decoded_body(body) when is_list(body) do
body |> Enum.map(&process_decoded_body(&1))
end

defp process_decoded_body(body) do
body
|> Enum.into(%{})
|> Crutches.Map.dkeys_update(fn (key) -> String.to_atom(key) end)
end
end

@doc """
Expand Down

0 comments on commit 53feab2

Please sign in to comment.