medium v0.1.0 Medium.Middlewares.Codec

This module acts as a Tesla middleware in order to process the responses coming from the Medium API.

Summary

Functions

This method is caled when this module is plugged as a middleware, and is in charge of processing the request by

Extract from the response Map the errors or the response data

Converts to snake_case all the keys of all maps inside a list

Converts all string keys in list of maps to atom keys

Functions

call(env, next, opts)

This method is caled when this module is plugged as a middleware, and is in charge of processing the request by:

descompose_keys(response)
descompose_keys(Map.t) :: Map

Extract from the response Map the errors or the response data.

snake_keys(data)
snake_keys(Map.t) :: Map
snake_keys(List.t) :: Map

Converts to snake_case all the keys of all maps inside a list

Examples

string_to_atom_keys([%{“keyOne” => 1}, %{“keyTwo” => 2}]) //=> [%{“key_one” => 1}, %{“key_two” => 2}]

string_to_atom_keys(map)
string_to_atom_keys(Map.t) :: Map
string_to_atom_keys(List.t) :: List

Converts all string keys in list of maps to atom keys

Examples

string_to_atom_keys(%{“one” => 1}) //=> %{one: 1}