-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.js
executable file
·64 lines (57 loc) · 1.3 KB
/
objects.js
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
"use strict";
/**
* gets instance of the cosmicjs api
* @private
* @return {object} cosmicApi
*/
const cosmic = require("cosmicjs")(); //
// TO DO : MOVE TO CONFIG
const _slug = { name : "duas-americas-backend-content"};
/**
* gets bucket from cosmicjs
* @private
* @return {object} bucket
*/
const _bucket = () => {
return cosmic.bucket({slug: _slug.name});
};
/**
* creates the response and calls back
* @private
* @constructor
* @param {list} apiResponse - A list of objects
* @return {object} res = http response
*/
const _fmt = (apiResponse) => {
console.log(apiResponse.objects[3]);
// TO DO: create formatters for each object
return {
statusCode: 200,
body: apiResponse.objects[3]
};
};
/**
* creates the response and calls back
* @private
* @constructor
* @return {object} fmt - http resp
*/
const _process = function() {
_bucket()
.getObjects()
.then(_fmt)
.catch(console.log);
};
/*
* parses the api response and gives the user a reply.
* @public
* @constructor
* @param {object} evt - an aws event
* @param {object} ctx aws event context
* @param {function} cb
* @returns {Promise}
*/
exports.handler = (evt,ctx,cb) => {
cb(null,_process());
};
_process();