fluro
Version:
Promise based HTTP Fluro client for the browser and node.js
326 lines (249 loc) • 15.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>fluro.core.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FluroAccess.html">FluroAccess</a><ul class='methods'><li data-type='method'><a href="FluroAccess.html#.addEventListener">addEventListener</a></li><li data-type='method'><a href="FluroAccess.html#.can">can</a></li><li data-type='method'><a href="FluroAccess.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="FluroAccess.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="FluroAccess.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="FluroAccess.html#.has">has</a></li><li data-type='method'><a href="FluroAccess.html#.isAuthor">isAuthor</a></li><li data-type='method'><a href="FluroAccess.html#.removeAllListeners">removeAllListeners</a></li><li data-type='method'><a href="FluroAccess.html#.removeEventListener">removeEventListener</a></li><li data-type='method'><a href="FluroAccess.html#.retrieveActionableRealms">retrieveActionableRealms</a></li><li data-type='method'><a href="FluroAccess.html#.retrieveCurrentSession">retrieveCurrentSession</a></li><li data-type='method'><a href="FluroAccess.html#.setDefaultApplication">setDefaultApplication</a></li></ul></li><li><a href="FluroAPI.html">FluroAPI</a><ul class='methods'><li data-type='method'><a href="FluroAPI.html#.delete">delete</a></li><li data-type='method'><a href="FluroAPI.html#.get">get</a></li><li data-type='method'><a href="FluroAPI.html#.post">post</a></li><li data-type='method'><a href="FluroAPI.html#.put">put</a></li></ul></li><li><a href="FluroAsset.html">FluroAsset</a><ul class='methods'><li data-type='method'><a href="FluroAsset.html#.avatarUrl">avatarUrl</a></li><li data-type='method'><a href="FluroAsset.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="FluroAsset.html#.filesize">filesize</a></li><li data-type='method'><a href="FluroAsset.html#.getUrl">getUrl</a></li><li data-type='method'><a href="FluroAsset.html#.imageUrl">imageUrl</a></li><li data-type='method'><a href="FluroAsset.html#.playerUrl">playerUrl</a></li><li data-type='method'><a href="FluroAsset.html#.posterUrl">posterUrl</a></li></ul></li><li><a href="FluroAuth.html">FluroAuth</a><ul class='methods'><li data-type='method'><a href="FluroAuth.html#.addEventListener">addEventListener</a></li><li data-type='method'><a href="FluroAuth.html#.changeAccount">changeAccount</a></li><li data-type='method'><a href="FluroAuth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="FluroAuth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="FluroAuth.html#.login">login</a></li><li data-type='method'><a href="FluroAuth.html#.logout">logout</a></li><li data-type='method'><a href="FluroAuth.html#.refreshAccessToken">refreshAccessToken</a></li><li data-type='method'><a href="FluroAuth.html#.removeAllListeners">removeAllListeners</a></li><li data-type='method'><a href="FluroAuth.html#.removeEventListener">removeEventListener</a></li><li data-type='method'><a href="FluroAuth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="FluroAuth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="FluroAuth.html#.set">set</a></li><li data-type='method'><a href="FluroAuth.html#.signup">signup</a></li><li data-type='method'><a href="FluroAuth.html#.sync">sync</a></li><li data-type='method'><a href="FluroAuth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="FluroCache.html">FluroCache</a><ul class='methods'><li data-type='method'><a href="FluroCache.html#.get">get</a></li><li data-type='method'><a href="FluroCache.html#.reset">reset</a></li></ul></li><li><a href="FluroContent.html">FluroContent</a><ul class='methods'><li data-type='method'><a href="FluroContent.html#.external">external</a></li><li data-type='method'><a href="FluroContent.html#.form">form</a></li><li data-type='method'><a href="FluroContent.html#.get">get</a></li><li data-type='method'><a href="FluroContent.html#.keys">keys</a></li><li data-type='method'><a href="FluroContent.html#.query">query</a></li><li data-type='method'><a href="FluroContent.html#.related">related</a></li><li data-type='method'><a href="FluroContent.html#.retrieve">retrieve</a></li><li data-type='method'><a href="FluroContent.html#.slug">slug</a></li><li data-type='method'><a href="FluroContent.html#.submitInteraction">submitInteraction</a></li><li data-type='method'><a href="FluroContent.html#.submitPost">submitPost</a></li><li data-type='method'><a href="FluroContent.html#.thread">thread</a></li><li data-type='method'><a href="FluroContent.html#.values">values</a></li></ul></li><li><a href="FluroCore.html">FluroCore</a></li><li><a href="FluroDate.html">FluroDate</a><ul class='methods'><li data-type='method'><a href="FluroDate.html#.dateFromID">dateFromID</a></li><li data-type='method'><a href="FluroDate.html#.formatDate">formatDate</a></li><li data-type='method'><a href="FluroDate.html#.isMultiDayEvent">isMultiDayEvent</a></li><li data-type='method'><a href="FluroDate.html#.localDate">localDate</a></li><li data-type='method'><a href="FluroDate.html#.readableEventDate">readableEventDate</a></li><li data-type='method'><a href="FluroDate.html#.readableEventTime">readableEventTime</a></li><li data-type='method'><a href="FluroDate.html#.timeago">timeago</a></li><li data-type='method'><a href="FluroDate.html#.timezones">timezones</a></li></ul></li><li><a href="FluroTypes.html">FluroTypes</a><ul class='methods'><li data-type='method'><a href="FluroTypes.html#.all">all</a></li><li data-type='method'><a href="FluroTypes.html#.get">get</a></li><li data-type='method'><a href="FluroTypes.html#.readable">readable</a></li><li data-type='method'><a href="FluroTypes.html#.reloadTerminology">reloadTerminology</a></li><li data-type='method'><a href="FluroTypes.html#.retrieve">retrieve</a></li></ul></li><li><a href="FluroUtils.html">FluroUtils</a><ul class='methods'><li data-type='method'><a href="FluroUtils.html#.arrayIDs">arrayIDs</a></li><li data-type='method'><a href="FluroUtils.html#.comma">comma</a></li><li data-type='method'><a href="FluroUtils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="FluroUtils.html#.getDefaultValueForField">getDefaultValueForField</a></li><li data-type='method'><a href="FluroUtils.html#.getStringID">getStringID</a></li><li data-type='method'><a href="FluroUtils.html#.guid">guid</a></li><li data-type='method'><a href="FluroUtils.html#.hash">hash</a></li><li data-type='method'><a href="FluroUtils.html#.mapParameters">mapParameters</a></li><li data-type='method'><a href="FluroUtils.html#.matchInArray">matchInArray</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">fluro.core.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>// if (process.browser) {
import FluroAPI from './fluro.api';
import FluroAuth from './fluro.auth';
import FluroAsset from './fluro.asset';
import FluroUtils from './fluro.utils';
import FluroCache from './fluro.cache';
import FluroDate from './fluro.date';
import FluroStats from './fluro.stats';
import FluroTypes from './fluro.types';
import FluroContent from './fluro.content';
import FluroAccess from './fluro.access';
import { EventDispatcher } from './fluro.utils';
// } else {
// const esmImport = require('esm')(module);
// const FluroAPI = esmImport('./fluro.api');
// const FluroAuth = esmImport('./fluro.auth');
// const FluroAsset = esmImport('./fluro.asset');
// const FluroUtils = esmImport('./fluro.utils');
// const FluroCache = esmImport('./fluro.cache');
// const FluroDate = esmImport('./fluro.date');
// const FluroStats = esmImport('./fluro.stats');
// const FluroTypes = esmImport('./fluro.types');
// const FluroContent = esmImport('./fluro.content');
// const FluroAccess = esmImport('./fluro.access');
// const EventDispatcher = FluroUtils.EventDispatcher;
// }
///////////////////////////////////////
/**
* Creates a new FluroCore instance including all of the default sub modules
* @constructor
*
* @param {Object} options
* @param {String} options.apiURL The remote URL of the Fluro API you want to connect to. Options are 'staging', 'production' or you may set a specific URL eg. 'https://api.fluro.io' (do not include trailing slash). If no value is provided, will default to 'production'.
* @param {String} options.applicationToken When running as a static application, (for example a website) you may set the application's access token before you initialize the Fluro instance here.
* @example
*
* //Import the Fluro package
* import Fluro from 'fluro';
*
* //Create a new Fluro instance
* var fluro = new Fluro();
*
* //Request the current user session endpoint from the Fluro API
* fluro.api.get('/session').then(function(res) {
* console.log('User session is ', res.data);
* })
* .catch(function(err) {
* console.log('There was an error', err);
* });
*
* //Use the FluroAsset package to generate an image url
* var link = fluro.asset.imageUrl('5ca3d64dd2bb085eb9d450db', 1920, 1080)
*/
var FluroCore = function(options) {
if (!options) {
options = {
// apiURL,
// applicationToken,
// api:{}
};
}
///////////////////////////////////////
///////////////////////////////////////
if (!options.apiURL || !options.apiURL.length) {
options.apiURL = 'production';
}
///////////////////////////////////////
switch (String(options.apiURL).toLowerCase()) {
case 'production':
options.apiURL = 'https://api.fluro.io';
break;
case 'staging':
options.apiURL = 'https://api.staging.fluro.io';
break;
case 'local':
options.apiURL = 'http://api.fluro.localhost:3000';
break;
}
///////////////////////////////////////
var core = {
apiURL: options.apiURL,
applicationToken: options.applicationToken,
domain: options.domain || '',
global: {},
}
///////////////////////////////////////
/**
* Provides a cache service, used for creating, clearing
* and storing API requests and other information in memory
* @type {FluroCache}
*/
var cache = FluroCache;
Object.defineProperty(core, 'cache', {
value: cache,
writable: false,
});
///////////////////////////////////////
/**
* Provides helper functions for working
* with Fluro data
* @type {FluroUtils}
*/
var utils = FluroUtils;
Object.defineProperty(core, 'utils', {
value: utils,
writable: false,
});
///////////////////////////////////////
//Create a new global dispatcher so we can trigger events
var dispatcher = new EventDispatcher();
dispatcher.bootstrap(core);
//Set the function
core.error = function(err) {
//Dispatch an error event
return core.dispatch('error', utils.errorMessage(err));
}
//And enable notifications with a short message
core.notify = function(message, options) {
return core.dispatch('notification', {message, options});
}
///////////////////////////////////////
/**
* Provides date functions, filters and utilities
* for working with dates and timezones
* @type {FluroDate}
*/
var date = FluroDate;
Object.defineProperty(core, 'date', {
value: date,
writable: false,
});
/**
* The default service for interacting with
* the Fluro REST API, it's a wrapper around the axios library
* that works in conjunction with the other Fluro modules
* @type {FluroAPI}
*/
var api = new FluroAPI(core);
Object.defineProperty(core, 'api', {
value: api,
writable: false,
});
/**
* A helper service for CRUD operations that wraps around the fluro.api service
* @type {FluroContent}
*/
var content = new FluroContent(core);
Object.defineProperty(core, 'content', {
value: content,
writable: false,
});
/**
* The default service for managing authentication
* handles automatic refreshing of access tokens, and provides login, logout
* and other user/application specific functionality
* @type {FluroAuth}
*/
var auth = new FluroAuth(core);
Object.defineProperty(core, 'auth', {
value: auth,
writable: false,
});
/**
* A helper service for understanding a user's access permissions
* @type {FluroAccess}
*/
var access = new FluroAccess(core);
Object.defineProperty(core, 'access', {
value: access,
writable: false,
});
/**
* The default service for managing, rendering and handling files and media from Fluro.
* It contains helper functions for managing connecting to image, audio, asset and video api endpoints.
* @type {FluroAsset}
*/
var asset = new FluroAsset(core);
Object.defineProperty(core, 'asset', {
value: asset,
writable: false,
});
/**
* The default service for handling a user's 'stats' eg. (likes, views, favorites, downvotes etc...)
* This service creates and syncs user's stats when they 'stat' items from Fluro.
* @type {FluroStats}
*/
var stats = new FluroStats(core)
Object.defineProperty(core, 'stats', {
value: new FluroStats(core),
writable: false,
});
/**
* A helper service for retrieving, translating and rendering content types and definitions
* defined within Fluro.
* @type {FluroTypes}
*/
var types = new FluroTypes(core);
Object.defineProperty(core, 'types', {
value: types,
writable: false,
});
///////////////////////////////////////
return core;
}
///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
export default FluroCore;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Sep 05 2019 21:42:53 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>