View Source CFSync.Entry.Extractors (CFSync v0.12.0)

Utility functions to extract data from contenful JSON.

Link to this section Summary

Types

Entry's payload as provided to CFSync.Entry.Fields.new/1

Functions

Returns value of field_name as an atom.

Returns value of field_name as a binary.

Returns value of field_name as a boolean.

Returns value of field_name processed by fun.

Returns value of field_name as a Date.

Returns value of field_name as a list of CFSync.Link.

Returns value of field_name as a list.

Returns value of field_name as a map.

Returns value of field_name as a number.

Link to this section Types

@opaque data()

Entry's payload as provided to CFSync.Entry.Fields.new/1

Link to this section Functions

Link to this function

extract_atom(data, field_name, mapping, default \\ nil)

View Source
@spec extract_atom(data(), String.t(), %{required(any()) => atom()}, atom()) ::
  nil | atom()

Returns value of field_name as an atom.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)
  • mapping is a map of "value" => :atom used to find which atom correspond to the field's value

Returns default on failure (field empty, no mapping...)

Link to this function

extract_binary(data, field_name, default \\ nil)

View Source
@spec extract_binary(data(), String.t(), nil | String.t()) :: nil | String.t()

Returns value of field_name as a binary.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a string...)

Link to this function

extract_boolean(data, field_name, default \\ nil)

View Source
@spec extract_boolean(data(), String.t(), nil | boolean()) :: nil | boolean()

Returns value of field_name as a boolean.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a boolean...)

Link to this function

extract_custom(data, field_name, fun)

View Source
@spec extract_custom(data(), String.t(), (any() -> any())) :: any()

Returns value of field_name processed by fun.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)
  • fun is a function of arity 1

Returns nil if the field is not included in the payload.

Link to this function

extract_date(data, field_name, default \\ nil)

View Source
@spec extract_date(data(), String.t(), nil | Date.t()) :: nil | Date.t()

Returns value of field_name as a Date.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, invalid format, invalid date...)

Link to this function

extract_datetime(data, field_name, default \\ nil)

View Source
@spec extract_datetime(data(), String.t(), nil | DateTime.t()) :: nil | DateTime.t()

Returns value of field_name as a DateTime.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, invalid format, invalid datetime...)

Link to this function

extract_link(data, field_name, default \\ nil)

View Source
@spec extract_link(data(), String.t(), nil | CFSync.Link.t()) :: nil | CFSync.Link.t()

Returns value of field_name as a CFSync.Link.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a link...)

Link to this function

extract_links(data, field_name, default \\ nil)

View Source
@spec extract_links(data(), String.t(), nil | [CFSync.Link.t()]) ::
  nil | [CFSync.Link.t()]

Returns value of field_name as a list of CFSync.Link.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a list...)

Link to this function

extract_list(data, field_name, default \\ nil)

View Source
@spec extract_list(data(), String.t(), nil | list()) :: nil | list()

Returns value of field_name as a list.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a list...)

Link to this function

extract_map(data, field_name, default \\ nil)

View Source
@spec extract_map(data(), String.t(), nil | map()) :: nil | map()

Returns value of field_name as a map.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a map...)

Link to this function

extract_number(data, field_name, default \\ nil)

View Source
@spec extract_number(data(), String.t(), nil | number()) :: nil | number()

Returns value of field_name as a number.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Be careful with the result as it can be either an integer or float, depending of it's value. A contentful decimal value of 1.0 will be stored as 1 in the JSON and read as an integer by JASON.

Returns default on failure (field empty, not a number...)

Link to this function

extract_rich_text(data, field_name, default \\ nil)

View Source
@spec extract_rich_text(data(), String.t(), nil | CFSync.RichText.t()) ::
  nil | CFSync.RichText.t()

Returns value of field_name as CFSync.RichText tree.

  • data is the entry's payload as provided to CFSync.Entry.Fields.new/1
  • field_name is the field's id in Contentful (ie. What is configured in Contentful app)

Returns default on failure (field empty, not a richtext...)