ContentService
Extends:
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 |
|
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 |
|
|
public |
Filters and returns a list of the contents for the given content_type |
|
public |
Makes a request based on permanent link and query given |
|
public |
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 |
Retrieves a list of favorite dynamic content based on the permanent link given |
|
public |
Retrieves a random dynamic content based on the permanent link given |
|
public |
getTypes(params: Object, cacheMode: String): Promise<ContentType[]|ContentType> Get Types |
|
public |
async getVuforiaDynamicContent(id: Number): Promise<VuforiaTarget> this method was deprecated. Retrieves the list of vuforia targets associated with the content.
|
|
public |
Insert dynamic content information. |
|
public |
Update dynamic content information. |
Inherited Summary
From class AbstractService | ||
public get |
|
|
public set |
|
|
public |
|
|
private |
|
From class JsonApiService | ||
public |
options: * |
|
public |
Call a DELETE request on the main obj.type expecting JSON API information. |
|
public |
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 |
Call a POST request on the main obj.type expecting JSON API information. |
|
public |
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#constructorPublic 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#deleteExample:
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
public async filter(query: Query): Promise<Content[]> source
Filters and returns a list of the contents for the given content_type
Throw:
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:
- [unit] ContentService.filter should throw an error when query is not of type Query
- [unit] ContentService.filter should throw an error when there are no search values to query
- [unit] ContentService.filter should make a properly formatted POST request
- [unit] ContentService.filter should get a valid response for a POST request with search
- [unit] ContentService.getByNumber should throw an error when getByNumber is called without max,min,or values
- [unit] ContentService.getByNumber should make a properly formatted POST request and response
- [unit] ContentService.getByLocation should throw an error when getByLocation is called incorrectly
- [unit] ContentService.getByLocation should make a properly formatted POST request
- [unit] ContentService.getByLocation should get a valid response for a POST request for location radius
- [unit] ContentService.getByLocation should get a valid response for a POST request for address match
- [unit] ContentService.getByLocation should get a valid response for a POST request for box filter
- [unit] ContentService.getByTagNames should throw an error when getByTagNames is called incorrectly
- [unit] ContentService.getByTagNames should get a valid response for a POST request
- [unit] ContentService.getByDate should throw an error when getByDate is called without max and/or min
- [unit] ContentService.getByDate should get a valid response for a POST request
- [unit] ContentService.getByTagIds should throw an error when getByTagIds is called incorrectly
- [unit] ContentService.getByTagIds should get a valid response for a POST request
public find(query: Query): Promise<Content[]> source
Makes a request based on permanent link and query given
Throw:
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();
public get(params: Object, cacheMode: String): Promise<Content[]|Content> source
Get Content
Override:
JsonApiService#getParams:
Name | Type | Attribute | Description |
params | Object | Parameters used to get information from server |
|
params.id | Number |
|
Id to get data from the server |
params.type | String |
|
Type to be used for storage |
params.filters | Object |
|
Filters to be used for get |
cacheMode | String |
|
Override the caching method for this call |
Throw:
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.
Throw:
If missing token or missing required parameters |
Example:
import { contentService } from 'clinical6';
contentService.getById(32).then(content => console.log(content));
public async getContent(resource: String): Promise<Content[]> source
Retrieves a list of dynamic content based on the permanent link given
Params:
Name | Type | Attribute | Description |
resource | String |
|
The permanent link for the requested content_type. Note: this param is part of the URL |
Throw:
If missing token or missing required parameters |
Example:
import { contentService } from 'clinical6';
contentService.getContent('acronyms').then(acronyms => console.log(acronyms));
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:
Name | Type | Attribute | Description |
resource | String |
|
The permanent link for the requested content_type. Note: this param is part of the URL |
page | Number |
|
The page number of the results given. |
perPage | Number |
|
The number of content to return per page. |
Throw:
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));
public async getRandom(resource: String): Promise<Content> source
Retrieves a random dynamic content based on the permanent link given
Params:
Name | Type | Attribute | Description |
resource | String |
|
The permanent link for the requested content_type. Note: this param is part of the URL |
Throw:
If missing token or missing required parameters |
Example:
import { contentService } from 'clinical6';
contentService.getRandom('acronyms').then(content => console.log(content));
public getTypes(params: Object, cacheMode: String): Promise<ContentType[]|ContentType> source
Get Types
Throw:
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));
public async getVuforiaDynamicContent(id: Number): Promise<VuforiaTarget> source
Params:
Name | Type | Attribute | Description |
id | Number |
|
The id of the content whose vuforia targets will be returned. |
Throw:
If missing token or missing required parameters |
Example:
import { contentService } from 'clinical6';
contentService.getVuforiaDynamicContent(23).then(vuforia => console.log(vuforia));
public async insert(content: Content, cacheMode: String): Promise source
Insert dynamic content information. Use the Content#save method when possible.
Override:
JsonApiService#insertThrow:
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();
public async update(content: Content, cacheMode: String): Promise source
Update dynamic content information. Use the Content#save method when possible.
Override:
JsonApiService#updateThrow:
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();
});