Manual Reference Source Test
import ContentService from 'clinical6/src/services/ContentService.js'
public class | source

ContentService

Extends:

AbstractServiceJsonApiService → ContentService

Service handling Content calls with specific endpoints.

Our SDK allows users to access and filter through your Clinical6 content, be it text, images, videos, or other media.

For instance, when a user selects an option from a mobile menu, you can provide the user with content related to that option. The user's selection could direct them to a website (using the SDK's in-app browser), in which case you would want to return a URL. Another menu option might direct the user to a series of pictures with captions and links. In this case, your dynamic content request would return URLs, images<sup>1</sup>, and text.

Possible values for the content_type that can be found in dynamic content JSON responses include:

Content Type JavaScript Attribute Name
Dates Category shared_category
Events Category event_category
Country country
Date date
Date with Time date_time
Location location
Email email
Number number
Text string
Phone Number telephone
Text Area text
Rich Text (HTML) richtext
Time time
Time Zone time_zone
URL url
Files files
Action action
Boolean boolean

Constructor Summary

Public Constructor
public

Update type to be dynamic_content__contents

Method Summary

Public Methods
public

async delete(content: Content, cacheMode: String): Promise

public

async filter(query: Query): Promise<Content[]>

Filters and returns a list of the contents for the given content_type

public

find(query: Query): Promise<Content[]>

Makes a request based on permanent link and query given

public

get(params: Object, cacheMode: String): Promise<Content[]|Content>

Get Content

public

Retrieves a single dynamic content type given the id.

public

async getContent(resource: String): Promise<Content[]>

Retrieves a list of dynamic content based on the permanent link given

public

async getContentFavorites(resource: String, page: Number, perPage: Number): Promise<Content[]>

Retrieves a list of favorite dynamic content based on the permanent link given

public

async getRandom(resource: String): Promise<Content>

Retrieves a random dynamic content based on the permanent link given

public

Get Types

public
this method was deprecated. Retrieves the list of vuforia targets associated with the content.
public

async insert(content: Content, cacheMode: String): Promise

Insert dynamic content information.

public

async update(content: Content, cacheMode: String): Promise

Update dynamic content information.

Inherited Summary

From class AbstractService
public get
public set
public
private
From class JsonApiService
public

options: *

public

async delete(obj: Object, options: String): Promise

Call a DELETE request on the main obj.type expecting JSON API information.

public

async get(params: Object, options: String): Promise

Call a GET request expecting JSON API information.

public

async getChildren(parent: Object, child: Object, options: String): Promise

Call a GET request expecting JSON API information for children given a parent.

public

async insert(obj: Object, options: String): Promise

Call a POST request on the main obj.type expecting JSON API information.

public

async update(obj: Object, options: String): Promise

Call a PATCH request on the main obj.type expecting JSON API information.

Public Constructors

public constructor() source

Update type to be dynamic_content__contents

Override:

JsonApiService#constructor

Public Methods

public async delete(content: Content, cacheMode: String): Promise source

Call a DELETE request on the main obj.type expecting JSON API information.

Override:

JsonApiService#delete

Params:

NameTypeAttributeDescription
content Content

Content object in which to delete

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message, likely to be blank

Example:

import { contentService } from 'clinical6';

// You will be able to delete a content using `delete`.
contentService.delete({ id: 23 });
// This will also clear the local storage of this type and id

Test:

public async filter(query: Query): Promise<Content[]> source

Filters and returns a list of the contents for the given content_type

Params:

NameTypeAttributeDescription
query Query
  • nullable: false

a Query object initiated by the Query class

query.resource String
  • nullable: false

the parmanent link of the content the query is based on

Return:

Promise<Content[]>

Promise object that returns a list of Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService, Query } from 'clinical6';

const acronymsQ = new Query('acronyms');
contentService.filter(acronymsQ).then(acronyms => console.log(acronyms));

Test:

public find(query: Query): Promise<Content[]> source

Makes a request based on permanent link and query given

Params:

NameTypeAttributeDescription
query Query
  • nullable: false

a Query object initiated by the Query class

query.resource String
  • nullable: false

the parmanent link of the content the query is based on

Return:

Promise<Content[]>

Promise object that returns a list of Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService, Query } from 'clinical6';

const acronymsQ = new Query('acronyms');

// Calls `contentService.filter`
contentService.find(acronymsQ).then(acronyms => console.log(acronyms));

// usually called through Query.
acronymsQ.find();

Test:

public get(params: Object, cacheMode: String): Promise<Content[]|Content> source

Get Content

Override:

JsonApiService#get

Params:

NameTypeAttributeDescription
params Object

Parameters used to get information from server

params.id Number
  • optional

Id to get data from the server

params.type String
  • optional

Type to be used for storage

params.filters Object
  • optional

Filters to be used for get

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Content[]|Content>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

// You will be able to access these entry groups using the `get` method.
contentService.get({ id: 15 }).then(templates => console.log(templates));

// get all cars
contentService.get('cars');

public async getById(id: String | Number): Promise<Content> source

Retrieves a single dynamic content type given the id.

Params:

NameTypeAttributeDescription
id String | Number
  • nullable: false

The unique indicator to retrieve content.

Return:

Promise<Content>

Promise object that returns Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

contentService.getById(32).then(content => console.log(content));

Test:

public async getContent(resource: String): Promise<Content[]> source

Retrieves a list of dynamic content based on the permanent link given

Params:

NameTypeAttributeDescription
resource String
  • nullable: false

The permanent link for the requested content_type. Note: this param is part of the URL

Return:

Promise<Content[]>

Promise object that returns a list of Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

contentService.getContent('acronyms').then(acronyms => console.log(acronyms));

Test:

public async getContentFavorites(resource: String, page: Number, perPage: Number): Promise<Content[]> source

Retrieves a list of favorite dynamic content based on the permanent link given

Params:

NameTypeAttributeDescription
resource String
  • nullable: false

The permanent link for the requested content_type. Note: this param is part of the URL

page Number
  • optional
  • default: 0
  • nullable: true

The page number of the results given.

perPage Number
  • optional
  • default: 0
  • nullable: true

The number of content to return per page.

Return:

Promise<Content[]>

Promise object that returns a list of Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

// All
contentService.getContentFavorites('acronyms').then(acronyms => console.log(acronyms));

// The first 10
contentService.getContentFavorites('acronyms', 1, 10).then(acronyms => console.log(acronyms));

Test:

public async getRandom(resource: String): Promise<Content> source

Retrieves a random dynamic content based on the permanent link given

Params:

NameTypeAttributeDescription
resource String
  • nullable: false

The permanent link for the requested content_type. Note: this param is part of the URL

Return:

Promise<Content>

Promise object that returns a random Content

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

contentService.getRandom('acronyms').then(content => console.log(content));

Test:

public getTypes(params: Object, cacheMode: String): Promise<ContentType[]|ContentType> source

Get Types

Params:

NameTypeAttributeDescription
params Object
  • optional

Parameters used to get information from server

params.id Number
  • optional

Id to get data from the server

params.type String
  • optional

Type to be used for storage

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<ContentType[]|ContentType>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

// You will be able to access these entry groups using the `getType` method.
contentService.getTypes().then(types => console.log(types));

Test:

public async getVuforiaDynamicContent(id: Number): Promise<VuforiaTarget> source

this method was deprecated. Retrieves the list of vuforia targets associated with the content.

Params:

NameTypeAttributeDescription
id Number
  • nullable: false

The id of the content whose vuforia targets will be returned.

Return:

Promise<VuforiaTarget>

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService } from 'clinical6';

contentService.getVuforiaDynamicContent(23).then(vuforia => console.log(vuforia));

Test:

public async insert(content: Content, cacheMode: String): Promise source

Insert dynamic content information. Use the Content#save method when possible.

Override:

JsonApiService#insert

Params:

NameTypeAttributeDescription
content Content
  • nullable: false

A content subclass containing information to insert

content.title String
  • nullable: true

Required title of the content

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService, Content } from 'clinical6';

let car = new Content('car');
car.set('title', 'My Car');
car.set('make', 'Toyota')
car.set('model', 'Corolla')
car.set('year', 2006)

contentService.insert(car);

// Frankly, we just call the `Content.save` method.
car.save();

Test:

public async update(content: Content, cacheMode: String): Promise source

Update dynamic content information. Use the Content#save method when possible.

Override:

JsonApiService#update

Params:

NameTypeAttributeDescription
content Content
  • nullable: false

Some dynamic content object that is used to update an existing content.

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { contentService, Content } from 'clinical6';

let car = new Content();
car.set('content_type', 'car');
car.set('title', 'My Car');
car.set('make', 'Toyota')
car.set('model', 'Corolla')
car.set('year', 2006)

// inserts
car.save().then(() => {
  // car now has id

  // We can do this, but it's easier to just call the save method
  contentService.update(car);

  // Car has id from insert, so this last save is an update
  return car.save();
});

Test: