Instagram core update splitted to small functions

This commit is contained in:
tmshv committed 2016-03-26 01:44:36 +03:00
1 parent 6e2e279263
commit 9851f856e3
1 file changed
+19 -5
+19 -5
View File
@@ -10,16 +10,30 @@ var instagramClient;
export default async function update(id, data) {
const updateTimestamp = data.time;
let items = await fetch(updateTimestamp);
return await Promise.all(
items.map(post => push(post))
);
}
export async function fetch(updateTimestamp) {
const instagram = await client();
try {
let data = await instagram.user.mediaRecent(null, 1, updateTimestamp);
let items = data.medias.map(postFromInstagramMedia);
return await Promise.all(
items.map(post => service.feed.add(post))
);
return data.medias.map(postFromInstagramMedia);
} catch (e) {
console.log(e);
return [];
}
}
export async function push(data) {
try {
return await service.feed.add(data);
} catch (e) {
console.log('PUSHING ERROR');
console.log(e);
return null;
}
}