all files / api/toJSON/ social.js

100% Statements 9/9
100% Branches 4/4
100% Functions 2/2
100% Lines 9/9
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                                                                     
'use strict';
const R = require('ramda');
 
function createInstagram(type, data) {
    return {
        data: {
            type,
            id: data.instagramId,
            attributes: {
                //kept for compatability with the pulveriser.
                instagramId: data.instagramId,
                caption: data.caption,
                username: data.username,
                imageUrl: R.path(['image_url'], data),
                profileImageUrl: R.path(['profileImageUrl'], data)
            },
            links: {
                url: `${data.url}/embed`
            }
        }
    };
}
 
function createTweet(id, type, data) {
    return {
        data: {
            type: type,
            id: id,
            //kept for compatability with the pulveriser.
            attributes: R.merge({[`tweetId`]: id}, data)
        }
    };
}
 
module.exports = tuple => {
    const item = tuple[1];
 
    const meta = R.assoc("id", tuple[0].source_id || item.id, tuple[0]);
 
    return [meta, meta.type === 'tweet' ?
        createTweet(item.id, meta.type, item.data) :
        createInstagram(meta.type, item.data)];
};