DatoCMS Client

Provides access to data in a DatoCMS site.

Installation

The package can be installed by adding datocms_rest_client to your list of dependencies in mix.exs:

def deps do
[{:datocms_rest_client, "~> 0.3.0"}]
end

Configuration

Via config.exs

Assuming your config/config.exs includes environment-specific secrets files excluded from your repo, put the following in {dev|production}.secrets.exs:

config :datocms_rest_client, :api_config,
%{headers: ["Authorization": "Bearer nnnnnnnnnnnnnnnnnnnnn"]}

Where nnnnnnnnnnnnnnnnnnnnn should be replaced by either your read-write or read-only DatoCMS API key.

If you are only reading data, you can use your read-only access token.

If you see timeout errors when downloading data, add the following:

config :datocms_rest_client, :api_config,
%{
headers: ["Authorization": "Bearer nnnnnnnnnnnnnnnnnnnnn"],
options: [recv_timeout: :infinity]
}

Programmatically

Application.put_env(
:datocms_rest_client,
:api_config,
%{
headers: ["Authorization": "Bearer nnnnnnnnnnnnnnnnnnnnn"],
options: [recv_timeout: :infinity]
}
)

Overview

DatoCMS.Client

This module contains a REST client for the datocms.com API. The code is generated by the json_hyperschema_client_builder.

The generated documentation can be found at https://hexdocs.pm/datocms_rest_client.

DatoCMS

Provides access to the main data access functionality:

Calling load/0 downloads site.json from the DatoCMS API plus all (paginated) items.json files.

DatoCMS.Repo

Internalized Data

All data is held in Elixir Map structues with atom keys.

A site's data is stored internally as a keyword list containing 3 data structures:

Data Structures

Internalized Item

{
id: "12345",
item_type: :post,
type: "item",
attributes: {
updated_at: "2017-01-01T13:29:49.359Z",
is_valid: true,
seo: {
image: {
alt: null,
path: "/11/1111111111-index.jpg",
size: 9525,
title: null,
width: 225,
format: "jpg",
height: 224
},
title: "SEO Title",
description: "SEO Description"
},
title: {
it: "Il titolo",
en: "The Title"
},
body: "Ciao",
category: "12346",
tags: ["12347"]
},
relationships: {
item_type: {
data: {
id: "123",
type: "item_type"
}
},
last_editor: {
data: {
id: "145",
type: "user"
}
}
}
}