View Source CloudflareApi.Utils (cloudflare_api v0.0.3)

Link to this section Summary

Functions

Macro that makes a function public in test, private in non-test

Quick regex check to see if the supplied string is a valid UUID

Takes a list of strings or atoms and returns a list with string and atoms.

Convert a map with String keys into a map with Atom keys.

Convert a map with String keys into a map with Atom keys.

Convert a map to a String, suitable for printing.

Checks if the passed item is nil or empty string.

Easy drop-in to a pipe to inspect the return value of the previous function.

if value (value of the argument) is nil, this will raise CloudflareApi.CantBeNil

if value (value of the argument) is nil, this will raise CloudflareApi.CantBeNil

Converts a struct to a regular map by deleting the :__meta__ key

Generate a new UUIDv4

Link to this section Functions

Link to this macro

defp_testable(head, body \\ nil)

View Source (macro)

Macro that makes a function public in test, private in non-test

See: https://stackoverflow.com/a/47598190/2062384

Quick regex check to see if the supplied string is a valid UUID

Check is done by simple regular expression and is not overly sophisticated.

Return true || false

Examples

iex> CloudflareApi.Utils.is_uuid?(nil)
false
iex> CloudflareApi.Utils.is_uuid?("hello world")
false
iex> CloudflareApi.Utils.is_uuid?("4c2fd8d3-a6e3-4e4b-a2ce-3f21456eeb85")
true
Link to this function

list_to_strings_and_atoms(list)

View Source

Takes a list of strings or atoms and returns a list with string and atoms.

Examples

iex> list_to_strings_and_atoms([:circle])
[:circle, "circle"]

iex> list_to_strings_and_atoms([:circle, :square])
[:square, "square", :circle, "circle"]

iex> list_to_strings_and_atoms(["circle", "square"])
["square", :square, "circle", :circle]
Link to this function

map_atom_keys_to_strings(map)

View Source

Convert a map with String keys into a map with Atom keys.

Examples

iex> CloudflareApi.Utils.map_atom_keys_to_strings(%{one: "one", two: "two"})
%{"one" => "one", "two" => "two"}
Link to this function

map_string_keys_to_atoms(map)

View Source

Convert a map with String keys into a map with Atom keys.

Examples

iex> CloudflareApi.Utils.map_string_keys_to_atoms(%{"one" => "one", "two" => "two"})
%{one: "one", two: "two"}m
Link to this function

map_to_string(map, mask_keys \\ [])

View Source

Convert a map to a String, suitable for printing.

Optionally pass a list of keys to mask.

Examples

iex> map_to_string(%{michael: "knight"})
"michael: 'knight'"

iex> map_to_string(%{michael: "knight", kitt: "karr"})
"kitt: 'karr', michael: 'knight'"

iex> map_to_string(%{michael: "knight", kitt: "karr"}, [:kitt])
"kitt: '****', michael: 'knight'"

iex> map_to_string(%{michael: "knight", kitt: "karr"}, [:kitt, :michael])
"kitt: '****', michael: '******'"

iex> map_to_string(%{"michael" => "knight", "kitt" => "karr", "carr" => "hart"}, ["kitt", "michael"])
"carr: 'hart', kitt: '****', michael: '******'"
Link to this function

nil_or_empty?(str_or_nil)

View Source

Checks if the passed item is nil or empty string.

The param will be passed to to_string() and then String.trim() and checked for empty string

Examples

iex> CloudflareApi.Utils.nil_or_empty?("hello")
false
iex> CloudflareApi.Utils.nil_or_empty?("")
true
iex> CloudflareApi.Utils.nil_or_empty?(nil)
true
Link to this function

pry_pipe(retval, arg1 \\ nil, arg2 \\ nil, arg3 \\ nil, arg4 \\ nil)

View Source

Easy drop-in to a pipe to inspect the return value of the previous function.

Examples

conn
|> put_status(:not_found)
|> put_view(CloudflareApiWeb.ErrorView)
|> render(:"404")
|> pry_pipe()

if value (value of the argument) is nil, this will raise CloudflareApi.CantBeNil

argn (name of the argument) will be passed to allow for more helpful error messages that tell you the name of the variable that was nil

Examples

iex> CloudflareApi.Utils.raise_if_nil!("someval")
"someval"
iex> CloudflareApi.Utils.raise_if_nil!(nil)
** (CloudflareApi.CantBeNil) variable 'somevar' was nil but cannot be
    (malan 0.1.0) lib/malan/utils.ex:142: CloudflareApi.Utils.raise_if_nil!/1
Link to this function

raise_if_nil!(varname, value)

View Source

if value (value of the argument) is nil, this will raise CloudflareApi.CantBeNil

argn (name of the argument) will be passed to allow for more helpful error messages that tell you the name of the variable that was nil

Examples

iex> CloudflareApi.Utils.raise_if_nil!("somevar", "someval")
"someval"
iex> CloudflareApi.Utils.raise_if_nil!("somevar", nil)
** (CloudflareApi.CantBeNil) variable 'somevar' was nil but cannot be
    (malan 0.1.0) lib/malan/utils.ex:135: CloudflareApi.Utils.raise_if_nil!/2

Converts a struct to a regular map by deleting the :__meta__ key

Examples

CloudflareApi.Utils.struct_to_map(%Something{hello: "world"})
%{hello: "world"}

Generate a new UUIDv4

Examples

CloudflareApi.Utils.uuidgen()
"4c2fd8d3-a6e3-4e4b-a2ce-3f21456eeb85"