Skip to content

Commit e4214ab

Browse files
Merge pull request #16 from contentstack/contenttype-methods
Api implementation for contenttype information
2 parents fb19018 + 7c4a110 commit e4214ab

File tree

5 files changed

+76
-80
lines changed

5 files changed

+76
-80
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules/*
44
.idea/*
55
reports/*
66
apidocs-templates/*
7-
test/smtpconfig.js
8-
test/config.js
9-
test/sync_config.js
7+
test/smtpconfig.js/*
8+
test/config.js/*
9+
test/sync_config.js/*
10+
test/report.json/*

examples/node/contentstack-demo.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ class ContentstackDemo {
4444
* @params : contentTypeUid {string} - Content-Type from which entries to be retrieved
4545
* @return : Result {Promise}
4646
*/
47-
getAllContentType() {
47+
getContentTypedemo() {
4848
//contentTypeUid = contentTypeUid || 'source'
49-
return this.Stack.getAllContentTypes()
49+
return this.Stack.ContentType('conference').fetch()
50+
// return this.Stack.ContentType('event_list').Entry('blt5d40c608567844d4').toJSON().fetch()
5051
}
5152

5253
/**

examples/node/index.js

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,21 @@
33
const ContentstackDemo = require('./contentstack-demo.js')
44

55
//const Demo = new ContentstackDemo({ 'api_key': "blt292960b854e5170e", 'access_token': "blt468d2af41a0f061c", 'environment': "development"})
6-
const Demo = new ContentstackDemo({ 'api_key': "blta18f3e7d09cb530c", 'access_token': "blt5260e2a69bb91bc6", 'environment': "development"})
7-
8-
9-
// Demo
10-
// .getEntries('source')
11-
// .then(function(result) {
12-
// // result object with entry
13-
// console.info("Result2 : ", result)
14-
15-
// //console.info("Result2 : ", JSON.stringify(result))
16-
17-
// })
18-
// .catch(function(err) {
19-
// // error of get entry
20-
// console.error("Fetch Error :", err)
21-
// })
22-
6+
const Demo = new ContentstackDemo({ 'api_key': "blt477ba55f9a67bcdf", 'access_token': "cs7731f03a2feef7713546fde5", 'environment': "web"})
237

248

259
//get all the entries
26-
Demo.getContentType("header")
27-
.then(function(err, result) {
10+
Demo.getContentTypedemo()
11+
.then(function(result, err) {
12+
// console.log("Result>>>>>>>>>>>>>>>")
2813
try {
2914
if (err || !result) {
15+
console.log("Result>>>>>>>>>>>>>>>")
3016
console.log(err)
3117
} else {
32-
console.info("Result: ", JSON.stringify(result))
18+
19+
console.log("Result: ", JSON.stringify(result, null, 1))
20+
//console.info("Result: ", JSON.stringify(result))
3321
}
3422
} catch (e) {
3523
return reject(e);
@@ -39,57 +27,3 @@ Demo.getContentType("header")
3927
// error of get all entries
4028
console.error("Find Error :", err)
4129
})
42-
43-
// // get single asset
44-
// Demo
45-
// .getAsset('bltsomething123')
46-
// .then(function(result) {
47-
// // result object with entry
48-
// console.info("Result2 : ", result)
49-
// })
50-
// .catch(function(err) {
51-
// // error of get entry
52-
// console.error("Fetch Error :", err)
53-
// })
54-
55-
56-
57-
// // get all assets
58-
// Demo
59-
// .getAssets()
60-
// .spread(function(result) {
61-
// // result object with entry
62-
// console.info("Result2 : ", result)
63-
// for (let i = 0, _i = result.length; i < _i; i++) {
64-
// // Image optimization
65-
// const imgUrl = Demo.Stack.imageTransform(result[i]['url'], {
66-
// quality: 50,
67-
// format: 'jpg'
68-
// })
69-
// console.log("Image URL : ", imgUrl)
70-
// }
71-
// })
72-
// .catch(function(err) {
73-
// // error of get entry
74-
// console.error("getAssets Fetch Error :", err)
75-
// })
76-
77-
78-
79-
// get all assets
80-
// Demo
81-
// .getSyncApi({"sync_token": "blt123something"})
82-
// .then(function(result) {
83-
84-
// console.log("result", JSON.stringify(result))
85-
86-
// })
87-
// .catch(function(err) {
88-
// // error of get entry
89-
// console.error("getSync Fetch Error :", err)
90-
// })
91-
92-
93-
94-
95-

src/core/modules/entry.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,4 @@ export default class Entry {
289289
console.error("Kindly provide an entry uid. e.g. .Entry('bltsomething123')");
290290
}
291291
}
292-
293292
}

src/core/stack.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,35 @@ export default class Stack {
249249
return Utils.merge(entry, this);
250250
}
251251

252+
/**
253+
* @method fetch
254+
* @memberOf Stack
255+
* @description This method will returns information of a specific content type. It returns the content type schema.
256+
* @example
257+
* let single_contenttype = Stack.ContentType(content_type_uid).fetch()
258+
* single_contenttype
259+
* .then(function(result) {
260+
* // 'result' is a single contentType information.
261+
* }).catch((error) => {
262+
* console.log(error)
263+
* });
264+
* @returns {ContentType}
265+
* @instance
266+
*/
267+
fetch() {
268+
let result = {
269+
method: 'POST',
270+
headers: this.headers,
271+
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.content_types + this.content_type_uid,
272+
body: {
273+
_method: 'GET',
274+
environment: this.environment
275+
}
276+
};
277+
return Request(result);
278+
279+
}
280+
252281
/**
253282
* @method Assets
254283
* @memberOf Stack
@@ -309,6 +338,38 @@ export default class Stack {
309338
return Request(query);
310339
}
311340

341+
/**
342+
* @method getContentTypes
343+
* @memberOf Stack
344+
* @description getContentTypes method returns comprehensive information of all the content types available in a particular stack in your account.
345+
* @example Stack.getContentTypes()
346+
* @example
347+
* let data = Stack.getContentTypes()
348+
* data
349+
* .then(function(result) {
350+
* // 'result' is list of contentTypes.
351+
* }, function(error) {
352+
* // error function
353+
* })
354+
* @returns {Stack}
355+
* @instance
356+
*/
357+
getContentTypes() {
358+
let query = {
359+
method: 'POST',
360+
headers: this.headers,
361+
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.content_types,
362+
body: {
363+
_method: 'GET',
364+
environment: this.environment
365+
}
366+
};
367+
return Request(query);
368+
}
369+
370+
371+
372+
312373

313374
/**
314375
* @method sync

0 commit comments

Comments
 (0)