Skip to content

Commit daa6693

Browse files
Merge pull request #1 from builtio-contentstack/add_param_method
Add param method
2 parents bc593eb + 3e75ff7 commit daa6693

23 files changed

+540
-63
lines changed

csio-templates/tmpl/layout.tmpl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@
4040
<p>You need Node.js version 4.4.7 or later installed to use the Contentstack JavaScript SDK.</p>
4141
<h3><a id="Setup_and_Installation_13"></a>Setup and Installation</h3>
4242
<h4><a id="For_JavaScript_Browser_15"></a>For JavaScript (Browser)</h4>
43-
<p>To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a> and include it in the &lt;script&gt; tag:</p>
44-
<pre><code>&lt;script type="text/javascript" src="/path/to/contentstack.min.js"&gt;&lt;/script&gt;;
43+
<p>To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a> and include it in the &lt;script&gt; tag:</p>
44+
<pre class="prettyprint"><code>&lt;script type="text/javascript" src="/path/to/contentstack.min.js"&gt;&lt;/script&gt;;
4545
</code></pre>
4646
<p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
47-
<pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
47+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
4848
</code></pre>
4949
<h4><a id="For_Nodejs_25"></a>For Node.js</h4>
50-
<p>Node.js uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install it via npm:</p>
51-
<pre><code>npm -i contentstack
50+
<p>Node.js uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install it via npm:</p>
51+
<pre class="prettyprint"><code>npm -i contentstack
5252
</code></pre>
5353
<p>To import the SDK in your project, use the following command:</p>
54-
<pre><code>import contentstack from ‘contentstack’
54+
<pre class="prettyprint"><code>import contentstack from ‘contentstack’
5555
</code></pre>
5656
<p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
57-
<pre><code>const Stack = Contentstack.Stack("api_key","access_token","environment_name");
57+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key","access_token","environment_name");
5858
</code></pre>
5959
<h4><a id="For_React_Native_39"></a>For React Native</h4>
60-
<p>React Native uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install ist via npm:</p>
61-
<pre><code>npm -i contentstack
60+
<p>React Native uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install ist via npm:</p>
61+
<pre class="prettyprint"><code>npm -i contentstack
6262
</code></pre>
6363
<p>To import the SDK in your project, use the following command:</p>
64-
<pre><code>import contentstack from `contentstack/react-native`
64+
<pre class="prettyprint" class="prettyprint"><code>import contentstack from `contentstack/react-native`
6565
</code></pre>
6666
<p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
67-
<pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
67+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
6868
</code></pre>
6969
<h3><a id="Key_Concepts_for_using_Contentstack_54"></a>Key Concepts for using Contentstack</h3>
7070
<h4><a id="Stack_56"></a>Stack</h4>
@@ -80,12 +80,12 @@
8080
<h3><a id="Contentstack_JavaScript_SDK_5minute_Quickstart_78"></a>Contentstack JavaScript SDK: 5-minute Quickstart</h3>
8181
<h4><a id="Initializing_your_SDK_80"></a>Initializing your SDK</h4>
8282
<p>You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK:</p>
83-
<pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
83+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
8484
</code></pre>
8585
<p>Once you have initialized the SDK, you can start getting content in your app.</p>
8686
<h4><a id="Querying_content_from_your_stack_90"></a>Querying content from your stack</h4>
8787
<p>To get a single entry, you need to specify the content type as well as the ID of the entry.</p>
88-
<pre><code>const Query = Stack.ContentType('blog').Entry("blt123something");
88+
<pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Entry("blt123something");
8989

9090
Query.fetch()
9191
.then(function success(entry) {
@@ -96,7 +96,7 @@
9696
});
9797
</code></pre>
9898
<p>To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.</p>
99-
<pre><code>const Query = Stack.ContentType('blog').Query();
99+
<pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Query();
100100

101101
Query
102102
.where("title", "welcome")
@@ -117,17 +117,17 @@
117117
<p>You can set a cache policy on a stack and/or query object.</p>
118118
<h5><a id="Setting_a_cache_policy_on_a_stack_127"></a>Setting a cache policy on a stack</h5>
119119
<p>This option allows you to globalize a cache policy. This means the cache policy you set will be applied to all the query objects of the stack.</p>
120-
<pre><code>//Setting a cache policy on a stack
120+
<pre class="prettyprint"><code>//Setting a cache policy on a stack
121121
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
122122
</code></pre>
123123
<h5><a id="Setting_a_cache_policy_on_a_query_object_134"></a>Setting a cache policy on a query object</h5>
124124
<p>This option allows you to set/override a cache policy on a specific query object.</p>
125-
<pre><code>// setting a cache policy on a queryobject
125+
<pre class="prettyprint"><code>// setting a cache policy on a queryobject
126126
Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
127127
</code></pre>
128128
<h3><a id="Advanced_Queries_141"></a>Advanced Queries</h3>
129129
<p>You can query for content types, entries, assets and more using our JavaScript API Reference.</p>
130-
<p><a href="https://contentstack.com/docs/platforms/javascript-browser/api-reference">JavaScript API Reference Doc</a></p>
130+
<p><a href="https://www.contentstack.com/docs/platforms/javascript-browser/api-reference/">JavaScript API Reference Doc</a></p>
131131
<h3><a id="Working_with_Images_147"></a>Working with Images</h3>
132132
<p>We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.</p>
133133
<p>For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, <a href="https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400">https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400</a>. There are several more parameters that you can use for your images.</p>
@@ -136,8 +136,8 @@
136136
<h3><a id="Helpful_Links_157"></a>Helpful Links</h3>
137137
<ul>
138138
<li><a href="https://www.contentstack.com">Contentstack Website</a></li>
139-
<li><a href="https://contentstack.com/docs">Official Documentation</a></li>
140-
<li><a href="https://contentstack.com/docs/apis/content-delivery-api/">Content Delivery API Docs</a></li>
139+
<li><a href="https://www.contentstack.com/docs">Official Documentation</a></li>
140+
<li><a href="https://www.contentstack.com/docs/apis/content-delivery-api/">Content Delivery API Docs</a></li>
141141
</ul>
142142
<h3><a id="The_MIT_License_MIT_163"></a>The MIT License (MIT)</h3>
143143
<p>Copyright © 2012-2017 <a href="https://www.built.io/">Built.io</a>. All Rights Reserved</p>

dist/node/contentstack.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ function Request(options) {
13131313
return new Promise(function (resolve, reject) {
13141314
var queryParams = void 0;
13151315
var serialize = function serialize(obj, prefix) {
1316+
13161317
var str = [],
13171318
p = void 0;
13181319
if ((typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object" && obj.length !== undefined) {
@@ -1323,7 +1324,7 @@ function Request(options) {
13231324
for (p in obj) {
13241325
var k = prefix ? prefix + "[" + p + "]" : p,
13251326
v = obj[p];
1326-
str.push(v !== null && (typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && p !== 'query' ? serialize(v, k) : k + "=" + (p !== 'query' ? encodeURIComponent(v) : JSON.stringify(v)));
1327+
str.push(v !== null && (typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && p !== 'query' ? serialize(v, k) : k + "=" + encodeURIComponent(p !== 'query' ? v : JSON.stringify(v)));
13271328
}
13281329
}
13291330
return str.join("&");
@@ -1753,6 +1754,23 @@ var Entry = function () {
17531754
return this;
17541755
}
17551756

1757+
/**
1758+
* @method AddParam
1759+
* @description This method includes query parameter in query.
1760+
* @example blogQuery.addParam('include_count', 'true').fetch()
1761+
*/
1762+
1763+
}, {
1764+
key: "addParam",
1765+
value: function addParam(key, value) {
1766+
if (key && value && typeof key === 'string' && typeof value === 'string') {
1767+
this._query[key] = value;
1768+
return this;
1769+
} else {
1770+
console.error("Kindly provide valid parameters.");
1771+
}
1772+
}
1773+
17561774
/**
17571775
* @method fetch
17581776
* @description fetch entry of requested content_type of defined query if present.
@@ -2210,6 +2228,24 @@ var Query = function (_Entry) {
22102228
return this;
22112229
}
22122230

2231+
/**
2232+
* @method AddParam
2233+
* @description This method includes query parameter in query.
2234+
* @example blogQuery.addParam('include_count', 'true')
2235+
* @returns {Query}
2236+
*/
2237+
2238+
}, {
2239+
key: 'addParam',
2240+
value: function addParam(key, value) {
2241+
if (key && value && typeof key === 'string' && typeof value === 'string') {
2242+
this._query[key] = value;
2243+
return this;
2244+
} else {
2245+
console.error("Kindly provide valid parameters.");
2246+
}
2247+
}
2248+
22132249
/**
22142250
* @method getQuery
22152251
* @summary returns the raw query which can be used for futher calls(.and/.or).
@@ -7058,6 +7094,7 @@ var Assets = function () {
70587094
function Assets() {
70597095
_classCallCheck(this, Assets);
70607096

7097+
this._query = {};
70617098
/**
70627099
* @method only
70637100
* @description This method is use to show the selected fields of the assets in resultset.
@@ -7114,6 +7151,23 @@ var Assets = function () {
71147151
return this;
71157152
}
71167153

7154+
/**
7155+
* @method AddParam
7156+
* @description This method includes query parameter in query.
7157+
* @example Stack.Assets('bltsomething123').addParam('include_dimension', 'true').fetch()
7158+
*/
7159+
7160+
}, {
7161+
key: 'addParam',
7162+
value: function addParam(key, value) {
7163+
if (key && typeof key === 'string' && value && typeof value === 'string') {
7164+
this._query[key] = value;
7165+
return this;
7166+
} else {
7167+
console.error("Kindly provide a valid parameters.");
7168+
}
7169+
}
7170+
71177171
/**
71187172
* @method fetch
71197173
* @description fetch asset obhect of requested Asset uid of defined query if present.
@@ -7134,6 +7188,7 @@ var Assets = function () {
71347188
query: this._query
71357189
}
71367190
};
7191+
71377192
return Utils.sendRequest(this);
71387193
} else {
71397194
console.error("Kindly provide an asset uid. e.g. .Assets('bltsomething123')");

dist/react-native/contentstack.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ function Request(options) {
899899
return new Promise(function (resolve, reject) {
900900
var queryParams = void 0;
901901
var serialize = function serialize(obj, prefix) {
902+
902903
var str = [],
903904
p = void 0;
904905
if ((typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object" && obj.length !== undefined) {
@@ -909,7 +910,7 @@ function Request(options) {
909910
for (p in obj) {
910911
var k = prefix ? prefix + "[" + p + "]" : p,
911912
v = obj[p];
912-
str.push(v !== null && (typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && p !== 'query' ? serialize(v, k) : k + "=" + (p !== 'query' ? encodeURIComponent(v) : JSON.stringify(v)));
913+
str.push(v !== null && (typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && p !== 'query' ? serialize(v, k) : k + "=" + encodeURIComponent(p !== 'query' ? v : JSON.stringify(v)));
913914
}
914915
}
915916
return str.join("&");
@@ -1287,6 +1288,23 @@ var Entry = function () {
12871288
return this;
12881289
}
12891290

1291+
/**
1292+
* @method AddParam
1293+
* @description This method includes query parameter in query.
1294+
* @example blogQuery.addParam('include_count', 'true').fetch()
1295+
*/
1296+
1297+
}, {
1298+
key: "addParam",
1299+
value: function addParam(key, value) {
1300+
if (key && value && typeof key === 'string' && typeof value === 'string') {
1301+
this._query[key] = value;
1302+
return this;
1303+
} else {
1304+
console.error("Kindly provide valid parameters.");
1305+
}
1306+
}
1307+
12901308
/**
12911309
* @method fetch
12921310
* @description fetch entry of requested content_type of defined query if present.
@@ -1744,6 +1762,24 @@ var Query = function (_Entry) {
17441762
return this;
17451763
}
17461764

1765+
/**
1766+
* @method AddParam
1767+
* @description This method includes query parameter in query.
1768+
* @example blogQuery.addParam('include_count', 'true')
1769+
* @returns {Query}
1770+
*/
1771+
1772+
}, {
1773+
key: 'addParam',
1774+
value: function addParam(key, value) {
1775+
if (key && value && typeof key === 'string' && typeof value === 'string') {
1776+
this._query[key] = value;
1777+
return this;
1778+
} else {
1779+
console.error("Kindly provide valid parameters.");
1780+
}
1781+
}
1782+
17471783
/**
17481784
* @method getQuery
17491785
* @summary returns the raw query which can be used for futher calls(.and/.or).
@@ -2385,6 +2421,7 @@ var Assets = function () {
23852421
function Assets() {
23862422
_classCallCheck(this, Assets);
23872423

2424+
this._query = {};
23882425
/**
23892426
* @method only
23902427
* @description This method is use to show the selected fields of the assets in resultset.
@@ -2441,6 +2478,23 @@ var Assets = function () {
24412478
return this;
24422479
}
24432480

2481+
/**
2482+
* @method AddParam
2483+
* @description This method includes query parameter in query.
2484+
* @example Stack.Assets('bltsomething123').addParam('include_dimension', 'true').fetch()
2485+
*/
2486+
2487+
}, {
2488+
key: 'addParam',
2489+
value: function addParam(key, value) {
2490+
if (key && typeof key === 'string' && value && typeof value === 'string') {
2491+
this._query[key] = value;
2492+
return this;
2493+
} else {
2494+
console.error("Kindly provide a valid parameters.");
2495+
}
2496+
}
2497+
24442498
/**
24452499
* @method fetch
24462500
* @description fetch asset obhect of requested Asset uid of defined query if present.
@@ -2461,6 +2515,7 @@ var Assets = function () {
24612515
query: this._query
24622516
}
24632517
};
2518+
24642519
return Utils.sendRequest(this);
24652520
} else {
24662521
console.error("Kindly provide an asset uid. e.g. .Assets('bltsomething123')");

dist/web/contentstack.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node/contentstack-demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ContentstackDemo {
4444
* @return : Result {Promise}
4545
*/
4646
getAssets() {
47-
return this.Stack.Assets().Query().skip(1).limit(1).toJSON().find()
47+
return this.Stack.Assets().Query().addParam('include_dimension', 'true').toJSON().find()
4848
}
4949

5050
/**

0 commit comments

Comments
 (0)