UNPKG

795 BJavaScriptView Raw
1/*eslint no-unused-vars:0 */
2'use strict';
3
4const capiV2 = require('./utils/capi-v2');
5const models = {
6 'content': (data) => data.content
7 .map(a => a.apiUrl.replace('http://api.ft.com/content/', '')),
8 'annotations': (data, count) => data.annotations.map(a => a.label)
9};
10
11module.exports = (opts) => {
12 const count = opts.count || 10;
13 const model = opts.model || 'content';
14 const queryString = '?' + ['industry', 'position', 'sector', 'country']
15 .filter(o => opts[o])
16 .map(o => `user-${o}=${opts[o]}`)
17 .join('&');
18
19 return capiV2({
20 path: `/hui/${model}/${opts.period || 'last-1-day'}${queryString}`,
21 type: 'hui'
22 })
23 .then(data => models[model](data).slice(0, count))
24 .then(articles => {
25 articles.indexCount = articles.length;
26 return articles;
27 });
28};