This is an Ember Data adapter/serializer that uses the READ ONLY Content Delivery API from service contentful
http://bondarenkoalex.github.io/ember-contentful-delivery-adapter/
ember new simple-contentful-app
cd simple-contentful-app
ember install ember-contentful-delivery-adapter
You'll want to get an account at Contentful login. After registration adds space. You will have provided key and space.
After installing the addon, you add Namespace and Access Token in config/environment.js
APP: {
// Here you can pass flags/options to your application instance
// when it is created
contentful: {
namespace : '<YOUR CONTENTFUL SPACE>',
access_token : '<YOUR CONTENTFUL ACCESS TOKEN>'
}
}
Contentful account:
<YOUR CONTENTFUL SPACE> : Contentful account -> APIs -> Content delivery / preview keys -> Website Key -> Space ID
<YOUR CONTENTFUL ACCESS TOKEN> : Contentful account -> APIs -> Content delivery / preview keys -> Website Key -> Production
Addon has added models:
// addon/models/
space,
asset,
content-type,
entry
All new models should inherit "entry" model. This model contains the default fields, such as
// addon/models/entry.js
import DS from 'ember-data';
export default DS.Model.extend({
sysCreatedAt: DS.attr('date'),
sysUpdatedAt: DS.attr('date'),
sysRevision : DS.attr('number'),
sysLocale: DS.attr('string'),
sysSpace: DS.belongsTo('space')
});
Example model:
// models/course.js
import DS from 'ember-data';
import Entry from 'ember-contentful-delivery-adapter/models/entry';
export default Entry.extend({
title: DS.attr('string'),
description: DS.attr('string'),
objectives: DS.attr(),
unit: DS.belongsTo('unit-course'),
image: DS.belongsTo('asset')
});
The new models names as ID "content model".
Contentful account -> APIs -> Content model explorer -> <content model (IDENTIFIER)>
Example:
content model (IDENTIFIER) | Name model |
---|---|
course | course |
calendarEvent | calendar-event |
unitCourseSimple | unit-course-simple |
Your application should have configured setting config/environment.js
and created models.
You can use the requests, such as: findRecord, findAll
and query
.
Example:
// app/routes/<file>.js
model() {
return this.store.findAll('course');
}
or
// app/routes/<file>.js
model() {
return this.store.findRecord('course', <Id of Resource>);
}
or
// app/routes/<file>.js
model() {
return this.store.query('course', { 'sys.id':<Id of Resource> } );
}
query
param sees "search parameters"