-
Notifications
You must be signed in to change notification settings - Fork 12
/
node_helper.js
62 lines (53 loc) · 2.04 KB
/
node_helper.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
/* Magic Mirror
* Module: MMM-Instagram
*
* By Jim Kapsalis https://github.com/kapsolas
* MIT Licensed.
*/
var NodeHelper = require("node_helper");
var request = require('request');
module.exports = NodeHelper.create({
// subclass start method.
start: function() {
console.log("Starting node_helper for module [" + this.name + "]");
},
// subclass socketNotificationReceived
socketNotificationReceived: function(notification, payload){
//console.log("=========== notification received: " + notification);
if (notification === 'INSTAGRAM_GET') {
this.getImagesFromJSON(payload);
}
},
getImagesFromJSON: function(api_url) {
//console.log('============ HERE =================');
var self = this;
request({url: api_url, method: 'GET'}, function(error, response, body)
{
if (!error && response.statusCode == 200)
{
// get our images out of the INSTAGRAM JSON response
var items = JSON.parse(body).data;
// create our model, a dictionary with
var images = {};
images.photo = new Array();
for (var i in items)
{
var type = items[i].type;
var media = items[i].images.low_resolution.url;
//console.log("type: " + type + "\nmedia: " + media);
// create a new array for each images object in the dictionary
images.photo.push( {
"type" : type,
"photolink" : media
});
}
//console.log("count: " + images.photo.length);
self.sendSocketNotification('INSTAGRAM_IMAGE_LIST', images);
}
else
{
console.log(" Error: " + response.statusCode);
}
});
}
});