Braintree.Util (Braintree v0.14.0)

General purpose utility functions.

Summary

Functions

Recursively convert a map of string keys into a map with atom keys. Intended to prepare responses for conversion into structs. Note that it converts any string into an atom, whether it existed or not.

Converts underscored values to hyphenated strings.

Converts hyphenated values to underscore delimited strings.

Functions

@spec atomize(map()) :: map()

Recursively convert a map of string keys into a map with atom keys. Intended to prepare responses for conversion into structs. Note that it converts any string into an atom, whether it existed or not.

For unknown maps with unknown keys this is potentially dangerous, but should be fine when used with known Braintree endpoints.

Example

iex> Braintree.Util.atomize(%{"a" => 1, "b" => %{"c" => 2}})
%{a: 1, b: %{c: 2}}

iex> Braintree.Util.atomize(%{a: 1, b: %{"c" => 2}})
%{a: 1, b: %{c: 2}}
Link to this function

hyphenate(value)

@spec hyphenate(String.t() | atom()) :: String.t()

Converts underscored values to hyphenated strings.

Examples

iex> Braintree.Util.hyphenate("brain_tree")
"brain-tree"

iex> Braintree.Util.hyphenate(:brain_tree)
"brain-tree"
Link to this function

underscorize(value)

@spec underscorize(String.t() | atom()) :: String.t()

Converts hyphenated values to underscore delimited strings.

Examples

iex> Braintree.Util.underscorize("brain-tree")
"brain_tree"

iex> Braintree.Util.underscorize(:"brain-tree")
"brain_tree"