prismic.io
Version:
JavaScript development kit for prismic.io
140 lines (114 loc) • 6.12 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: prismic.js</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-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: prismic.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
var experiments = require('./experiments'),
Predicates = require('./predicates'),
api = require('./api'),
Fragments = require('./fragments'),
QuickRoutes = require('./quickRoutes'),
documents = require('./documents');
var Api = api.Api,
Experiments = experiments.Experiments;
/**
* The kit's main entry point; initialize your API like this: Prismic.api(url, {accessToken: "XXX"})
*
* @global
* @alias Api
* @constructor
* @param {string} url - The mandatory URL of the prismic.io API endpoint (like: https://lesbonneschoses.prismic.io/api)
* @param {function} options.callback - Optional callback function that is called after the API was retrieved, which will be called with two parameters: a potential error object and the API object
* @param {string} options.accessToken - The accessToken, necessary if the API is set as private
* @param {string} options.req - The NodeJS request (only use in a NodeJS context)
* @param {function} options.requestHandler - Environment specific HTTP request handling function
* @param {object} options.apiCache - A cache object with get/set functions for caching API responses
* @param {int} options.apiDataTTL - How long (in seconds) to cache data used by the client to make calls (e.g. refs). Defaults to 5 seconds
* @returns {Api} - The Api object that can be manipulated
*/
function getApi(url, options) {
options = options || {};
if (typeof arguments[1] == 'function') {
// Legacy (1) the second argument is the callback
options = {
"complete": arguments[1],
"accessToken": arguments[2],
"requestHandler": arguments[3],
"apiCache": arguments[4],
"apiDataTTL": arguments[5]
};
} else if (typeof arguments[1] == 'string') {
// Legacy (2) the second argument is the accessToken
options = {
"accessToken": arguments[1],
"requestHandler": arguments[2],
"apiCache": arguments[3],
"apiDataTTL": arguments[4]
};
}
var api = new Api(url, options || {});
//Use cached api data if available
return new Promise(function(resolve, reject) {
var cb = function(err, value, xhr) {
if (options.complete) options.complete(err, value, xhr);
if (err) {
reject(err);
} else {
resolve(value);
}
};
api.get(function (err, data) {
if (!err && data) {
api.data = data;
api.bookmarks = data.bookmarks;
api.experiments = new Experiments(data.experiments);
}
cb(err, api);
});
return api;
});
}
module.exports = {
experimentCookie: api.experimentCookie,
previewCookie: api.previewCookie,
Document: documents.Document,
SearchForm: api.SearchForm,
Form: api.Form,
Experiments: Experiments,
Predicates: Predicates,
Fragments: Fragments,
QuickRoutes: QuickRoutes,
api: getApi,
Api: getApi, // Backward compatibility
parseDoc: api.parseDoc
};
module.exports.Prismic = module.exports; // Backward compatibility
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Api.html">Api</a></li><li><a href="Doc.html">Doc</a></li><li><a href="Experiments.html">Experiments</a></li><li><a href="Fragments_Color.html">Fragments:Color</a></li><li><a href="Fragments_CompositeSlice.html">Fragments:CompositeSlice</a></li><li><a href="Fragments_Date.html">Fragments:Date</a></li><li><a href="Fragments_DocumentLink.html">Fragments:DocumentLink</a></li><li><a href="Fragments_Embed.html">Fragments:Embed</a></li><li><a href="Fragments_FileLink.html">Fragments:FileLink</a></li><li><a href="Fragments_GeoPoint.html">Fragments:GeoPoint</a></li><li><a href="Fragments_Group.html">Fragments:Group</a></li><li><a href="Fragments_ImageEl.html">Fragments:ImageEl</a></li><li><a href="Fragments_ImageLink.html">Fragments:ImageLink</a></li><li><a href="Fragments_ImageView.html">Fragments:ImageView</a></li><li><a href="Fragments_Num.html">Fragments:Num</a></li><li><a href="Fragments_Select.html">Fragments:Select</a></li><li><a href="Fragments_Separator.html">Fragments:Separator</a></li><li><a href="Fragments_SimpleSlice.html">Fragments:SimpleSlice</a></li><li><a href="Fragments_SliceZone.html">Fragments:SliceZone</a></li><li><a href="Fragments_StructuredText.html">Fragments:StructuredText</a></li><li><a href="Fragments_Text.html">Fragments:Text</a></li><li><a href="Fragments_Timestamp.html">Fragments:Timestamp</a></li><li><a href="Fragments_WebLink.html">Fragments:WebLink</a></li><li><a href="Ref.html">Ref</a></li><li><a href="Response.html">Response</a></li><li><a href="SearchForm.html">SearchForm</a></li><li><a href="WithFragments.html">WithFragments</a></li></ul><h3>Namespaces</h3><ul><li><a href="Predicates.html">Predicates</a></li></ul><h3>Global</h3><ul><li><a href="global.html#ApiCache">ApiCache</a></li><li><a href="global.html#data">data</a></li><li><a href="global.html#fragments">fragments</a></li><li><a href="global.html#insertSpans">insertSpans</a></li><li><a href="global.html#LRUCache">LRUCache</a></li><li><a href="global.html#parseDoc">parseDoc</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Apr 28 2017 17:29:54 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>