ex_fieldmask v0.3.1 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 tokens from text

Link to this section Functions

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"}

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)"}

Parse JSON tree from tokens

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", "/", "*"]