ex_fieldmask v0.3.0 FieldMask View Source
FieldMask implements Partial Responses protocol of Google+ API purely in Elixir via algorithmic method.
Link to this section Summary
Functions
Compile text with Partial Responses protocol of Google+ API
Get JSON result as a map masked by text
Parse JSON tree from tokens
Get JSON result as a map from compiled tree
Get tokens from text
Link to this section Functions
Link to this function
compile(text) View Source
Compile text with Partial Responses protocol of Google+ API
Examples
iex> FieldMask.compile("a,b,c")
{:ok, %{"a" => %{}, "b" => %{}, "c" => %{}}}
iex> FieldMask.compile("a/b/c")
{:ok, %{"a" => %{"b" => %{"c" => %{}}}}}
iex> FieldMask.compile("a(b,c)")
{:ok, %{"a" => %{"b" => %{}, "c" => %{}}}}
iex> FieldMask.compile("a/*/c")
{:ok, %{"a" => %{"*" => %{"c" => %{}}}}}
iex> FieldMask.compile("a/b,c")
{:ok, %{"a" => %{"b" => %{}}, "c" => %{}}}
iex> FieldMask.compile("ob,a(k,z(f,g/d))")
{
:ok,
%{
"a" => %{"k" => %{}, "z" => %{"f" => %{}, "g" => %{"d" => %{}}}},
"ob" => %{}
}
}
iex> FieldMask.compile("url,object(content,attachments/url)")
{:ok,
%{
"object" => %{"attachments" => %{"url" => %{}}, "content" => %{}},
"url" => %{}
}}
iex> FieldMask.compile("a(b,c")
{:error, "Invalid text with mismatched brackets: a(b,c"}
Link to this function
mask(text, data) View Source
Get JSON result as a map masked by text
Examples
iex> FieldMask.mask("a,b", %{"a" => 1, "b" => 2, "c" => 3})
{:ok, %{"a" => 1, "b" => 2}}
iex> FieldMask.mask("a/b", %{"a" => %{"b" => 2, "c" => 3}})
{:ok, %{"a" => %{"b" => 2}}}
iex> FieldMask.mask("a(b,c)", %{"a" => %{"b" => 1, "c" => 2, "d" => 3}, "e" => 4})
{:ok, %{"a" => %{"b" => 1, "c" => 2}}}
iex> FieldMask.mask("a/*/c", %{"a" => %{"b" => %{"c" => 2, "e" => 1}, "d" => %{ "c" => 4, "f" => 3}}})
{:ok, %{"a" => %{"b" => %{"c" => 2}, "d" => %{"c" => 4}}}}
iex> FieldMask.mask("a/b)", %{"a" => 1, "b" => 2, "c" => 3})
{:error, "Invalid text with mismatched brackets: a/b)"}
Link to this function
parse(tokens) View Source
Parse JSON tree from tokens
Link to this function
reveal(tree, data) View Source
Get JSON result as a map from compiled tree
Link to this function
scan(text) View Source
Get tokens from text
Examples
iex> FieldMask.scan("ob,a(k,z(f,g/d))")
["ob", ",", "a", "(", "k", ",", "z", "(", "f", ",", "g", "/", "d", ")", ")"]
iex> FieldMask.scan("ob,a(k,z(f,g/d)),d")
["ob", ",", "a", "(", "k", ",", "z", "(", "f", ",", "g", "/", "d", ")", ")", ",", "d"]
iex> FieldMask.scan("")
[]
iex> FieldMask.scan("abc/*")
["abc", "/", "*"]