-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodule.js
More file actions
132 lines (101 loc) · 3.55 KB
/
Copy pathmodule.js
File metadata and controls
132 lines (101 loc) · 3.55 KB
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
"use strict";
var _module = require('../module');
var _module2 = _interopRequireDefault(_module);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var stats = _module2.default.all('http://www.vogue.com/13368193/jennifer-lawrence-december-2015-cover-hunger-games/');
stats.then(function (d) {
console.log(d);
});
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _requestPromise = require('request-promise');
var _requestPromise2 = _interopRequireDefault(_requestPromise);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var sources = _fs2.default.readdirSync('./sources');
var Social = (function () {
function Social() {
_classCallCheck(this, Social);
}
_createClass(Social, null, [{
key: 'all',
value: function all(url) {
var self = this;
var output = sources.map(function (source) {
return self.get(source, url);
});
return Promise.all(output);
}
}, {
key: 'get',
value: function get(source, url) {
source = require('./sources/' + source);
var getResponse = function getResponse(response) {
return response.body;
};
return _requestPromise2.default.get(source.url.replace('%%URL%%', url)).then(function (response) {
response = source.map(response);
response.service = source.source;
return new Promise(function (respond, reject) {
respond(response);
});
});
}
}]);
return Social;
})();
exports.default = Social;
'use strict';
module.exports = {
source: 'facebook',
url: 'https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json',
map: function map(response) {
response = JSON.parse(response);
response = response[0];
return {
likes: response.like_count,
shares: response.share_count,
clicks: response.click_count,
comments: response.comment_count
};
}
};
'use strict';
module.exports = {
source: 'linkedin',
url: 'http://www.linkedin.com/countserv/count/share?url=%%URL%%&format=json',
map: function map(response) {
response = JSON.parse(response);
return {
shares: response.count
};
}
};
'use strict';
module.exports = {
source: 'pinterest',
url: 'http://widgets.pinterest.com/v1/urls/count.json?source=6&url=%%URL%%',
map: function map(response) {
var r = response.replace('receiveCount(', '').replace('})', '}');
r = JSON.parse(r);
return {
shares: r.count
};
}
};
'use strict';
module.exports = {
source: 'twitter',
url: 'http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%',
map: function map(response) {
response = JSON.parse(response);
return {
shares: response.count
};
}
};