forked from contentstack/contentstack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules_result.js.html
182 lines (159 loc) · 10.7 KB
/
modules_result.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>modules/result.js - Documentation</title>
<link rel="shortcut icon" href="./favicon.ico">
<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 rel="canonical" href="https://www.contentstack.com/docs/developers/platforms/javascript/api-reference/">
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WGP99J7');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WGP99J7" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<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="Contentstack.html">Contentstack</a><ul class='methods'><li data-type='method'><a href="Contentstack.html#Stack">Stack</a></li></ul></li><li><a href="Stack.html">Stack</a><ul class='methods'><li data-type='method'><a href="Stack.html#setPort">setPort</a></li><li data-type='method'><a href="Stack.html#setProtocol">setProtocol</a></li><li data-type='method'><a href="Stack.html#setHost">setHost</a></li><li data-type='method'><a href="Stack.html#setCachePolicy">setCachePolicy</a></li><li data-type='method'><a href="Stack.html#setCacheProvider">setCacheProvider</a></li><li data-type='method'><a href="Stack.html#clearByQuery">clearByQuery</a></li><li data-type='method'><a href="Stack.html#clearByContentType">clearByContentType</a></li><li data-type='method'><a href="Stack.html#clearAll">clearAll</a></li><li data-type='method'><a href="Stack.html#getCacheProvider">getCacheProvider</a></li><li data-type='method'><a href="Stack.html#ContentType">ContentType</a></li><li data-type='method'><a href="Stack.html#Assets">Assets</a></li><li data-type='method'><a href="Stack.html#Query">Query</a></li><li data-type='method'><a href="Stack.html#getLastActivites">getLastActivites</a></li><li data-type='method'><a href="Stack.html#getContentTypes">getContentTypes</a></li><li data-type='method'><a href="Stack.html#sync">sync</a></li><li data-type='method'><a href="Stack.html#imageTransform">imageTransform</a></li></ul></li><li><a href="Assets.html">Assets</a><ul class='methods'><li data-type='method'><a href="Assets.html#toJSON">toJSON</a></li><li data-type='method'><a href="Assets.html#addParam">addParam</a></li><li data-type='method'><a href="Assets.html#fetch">fetch</a></li></ul></li><li><a href="Entry.html">Entry</a><ul class='methods'><li data-type='method'><a href="Entry.html#includeFallback">includeFallback</a></li><li data-type='method'><a href="Entry.html#only">only</a></li><li data-type='method'><a href="Entry.html#except">except</a></li><li data-type='method'><a href="Entry.html#includeReference">includeReference</a></li><li data-type='method'><a href="Entry.html#language">language</a></li><li data-type='method'><a href="Entry.html#addQuery">addQuery</a></li><li data-type='method'><a href="Entry.html#includeSchema">includeSchema</a></li><li data-type='method'><a href="Entry.html#includeReferenceContentTypeUid">includeReferenceContentTypeUid</a></li><li data-type='method'><a href="Entry.html#includeFallback">includeFallback</a></li><li data-type='method'><a href="Entry.html#includeContentType">includeContentType</a></li><li data-type='method'><a href="Entry.html#includeOwner">includeOwner</a></li><li data-type='method'><a href="Entry.html#toJSON">toJSON</a></li><li data-type='method'><a href="Entry.html#addParam">addParam</a></li><li data-type='method'><a href="Entry.html#fetch">fetch</a></li></ul></li><li><a href="Query.html">Query</a><ul class='methods'><li data-type='method'><a href="Query.html#lessThan">lessThan</a></li><li data-type='method'><a href="Query.html#lessThanOrEqualTo">lessThanOrEqualTo</a></li><li data-type='method'><a href="Query.html#greaterThan">greaterThan</a></li><li data-type='method'><a href="Query.html#greaterThanOrEqualTo">greaterThanOrEqualTo</a></li><li data-type='method'><a href="Query.html#notEqualTo">notEqualTo</a></li><li data-type='method'><a href="Query.html#containedIn">containedIn</a></li><li data-type='method'><a href="Query.html#notContainedIn">notContainedIn</a></li><li data-type='method'><a href="Query.html#exists">exists</a></li><li data-type='method'><a href="Query.html#notExists">notExists</a></li><li data-type='method'><a href="Query.html#ascending">ascending</a></li><li data-type='method'><a href="Query.html#descending">descending</a></li><li data-type='method'><a href="Query.html#beforeUid">beforeUid</a></li><li data-type='method'><a href="Query.html#afterUid">afterUid</a></li><li data-type='method'><a href="Query.html#skip">skip</a></li><li data-type='method'><a href="Query.html#limit">limit</a></li><li data-type='method'><a href="Query.html#or">or</a></li><li data-type='method'><a href="Query.html#and">and</a></li><li data-type='method'><a href="Query.html#where">where</a></li><li data-type='method'><a href="Query.html#count">count</a></li><li data-type='method'><a href="Query.html#query">query</a></li><li data-type='method'><a href="Query.html#referenceIn">referenceIn</a></li><li data-type='method'><a href="Query.html#referenceNotIn">referenceNotIn</a></li><li data-type='method'><a href="Query.html#tags">tags</a></li><li data-type='method'><a href="Query.html#includeReferenceContentTypeUid">includeReferenceContentTypeUid</a></li><li data-type='method'><a href="Query.html#includeCount">includeCount</a></li><li data-type='method'><a href="Query.html#addParam">addParam</a></li><li data-type='method'><a href="Query.html#getQuery">getQuery</a></li><li data-type='method'><a href="Query.html#regex">regex</a></li><li data-type='method'><a href="Query.html#search">search</a></li><li data-type='method'><a href="Query.html#find">find</a></li><li data-type='method'><a href="Query.html#findOne">findOne</a></li></ul></li><li><a href="Result.html">Result</a><ul class='methods'><li data-type='method'><a href="Result.html#toJSON">toJSON</a></li><li data-type='method'><a href="Result.html#get">get</a></li><li data-type='method'><a href="Result.html#getDownloadUrl">getDownloadUrl</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">modules/result.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import * as Utils from '../lib/utils'
/**
* @class Result
* @summary Creates an instance of `Result`.
* @description An initializer is responsible for creating Result object.
* @param {Object} object - API result object
* @example
* blogEntry.then(function (result) {
* // sucess function
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* // sucess function
* },function (error) {
* // error function
* })
* @returns {Result}
* @instance
*/
class Result {
constructor(object){
if(object) {
this.object = function() {
return object;
}
}
return this;
}
/**
* @method toJSON
* @memberOf Result
* @description Converts `Result` to plain javascript object.
* @example
* blogEntry.then(function (result) {
* result = result[0][0].toJSON()
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* result = result[0][0].toJSON()
* },function (error) {
* // error function
* })
* @returns {object}
* @instance
*/
toJSON() {
return (this.object()) ? Utils.mergeDeep(JSON.parse(JSON.stringify({})), this.object()) : null;
}
/**
* @method get
* @memberOf Result
* @description Retrieve details of a field based on the UID provided
* @param field_uid uid of the field
* @example
* blogEntry.then(function (result) {
* let value = result[0][0].get(field_uid)
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* let value = result[0][0].get(field_uid)
* },function (error) {
* // error function
* })
* @returns {promise}
* @instance
*/
get(key){
if(this.object() && key) {
let fields = key.split('.');
let value = fields.reduce(function(prev, field) {
return prev[field];
}, this.object());
return value;
}
return ;
}
/**
* @method getDownloadUrl
* @memberOf Result
* @description Retrieves the download URL based on the disposition value.
* @param {String} string - disposition value
* @example
* assetQuery.then(function (result) {
* let value = result[0][0].getDownloadUrl(disposition_value)
* },function (error) {
* // error function
* })
* @returns {Object}
* @instance
*/
getDownloadUrl(disposition) {
if (this.object()) {
let url = (this.object().url) ? this.object().url : null,
_disposition = (disposition && typeof disposition === 'string') ? disposition: 'attachment';
return (url) ? url + '?disposition=' + _disposition : null;
}
}
}
module.exports = function(object) {
return new Result(object);
};</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
<div class="inner-content center">
<span class="copy-right"><a href="mailto:support@contentstack.com" target="_self">support@contentstack.com</a> | © 2016-2020 Contentstack. All rights reserved.</span>
</div>
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>