Contentful SDK v0.3.2 Contentful.Delivery.Entries View Source

Entries allows for querying the entries of a space via Contentful.Query.

Fetching a single entry

import Contentful.Query
alias Contentful.Delivery.Entries

{:ok, entry} = Entries |> fetch_one("my_entry_id")

Simple querying of a collection of entries

import Contentful.Query
alias Contentful.Delivery.Entries

# fetches the entries based on the `space_id`, `environment` and `access_token` in config/config.exs
{:ok, entries, total: _total_count_of_entries} =
  Entries |> fetch_all

# fetches the entries by passing  `space_id`, `environment` and `access_token`
space_id = "<my_space_id>"
environment = "<my_environment>"
access_token = "<my_access_token>"

{:ok, entries, total: _total_count_of_entries} =
  Entries |> fetch_all(space_id, environment, access_token)

More advanced query with included assets

Entries can have assets included, which limits the amount of times a client has to request data from the server:

import Contentful.Query
alias Contentful.{Asset, Entry}
alias Contentful.Delivery.Entries

# The default include depth is 1 (max 10)
{:ok, [ %Entry{assets: assets} = entry | _ ], total: _total_count_of_entries} =
  Entries |> include |> fetch_all

assets |> Enum.map(fn %Asset{fields: fields} -> {fields.title, fields.file} end)

# you can also just get the assets belonging to an entry lazily:

Entries |> include |> stream |> Stream.flat_map(fn entry -> entry.assets end) |> Enum.take(2)

Accessing common resource attributes

Entries embed Contentful.SysData with extra information about the entry:

import Contentful.Query alias Contentful.{ContentType, Entry, SysData} alias Contentful.Delivery.Entries

= Entries |> fetch_one("my_entry_id")

"my_entry_id" = entry.id "<a timestamp for updated_at>" = entry.sys.updated_at "<a timestamp for created_at>" = entry.sys.created_at "<a locale string>" = entry.sys.locale %ContentType{id: "the_associated_content_type_id"} = entry.sys.content_type

Link to this section Summary

Functions

maps a standard API response for queries compliant with the Contentful.Queryable behaviour.

maps a standard API response for a single entry returned, compliant with the Contentful.Queryable behaviour.

Link to this section Functions

Link to this function

resolve_collection_response(map)

View Source

maps a standard API response for queries compliant with the Contentful.Queryable behaviour.

Link to this function

resolve_entity_response(map)

View Source

maps a standard API response for a single entry returned, compliant with the Contentful.Queryable behaviour.