public-instagram
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -38,8 +38,12 @@ 'use strict'; | ||
* @param {String} _username | ||
* @param {Number} _limit | ||
* @return {Array} posts - All the posts that belong to the user with given username | ||
*/ | ||
posts: async (_username) => { | ||
posts: async (_username, _limit) => { | ||
var _query_id = await utils.query.user(_username); | ||
var _info = await self.info(_username); | ||
var limit = (typeof _limit === 'undefined') ? _info.posts.count : _limit; | ||
try { | ||
@@ -59,6 +63,5 @@ | ||
var posts = await utils.parser.timeline(response.data); | ||
var token = null; | ||
while (response.data.data.user.edge_owner_to_timeline_media.page_info.has_next_page) { | ||
while (response.data.data.user.edge_owner_to_timeline_media.page_info.has_next_page && posts.length < limit) { | ||
@@ -82,2 +85,6 @@ token = response.data.data.user.edge_owner_to_timeline_media.page_info.end_cursor; | ||
if (posts.length > limit) { | ||
posts.splice(limit, posts.length); | ||
} | ||
return posts; | ||
@@ -84,0 +91,0 @@ |
@@ -66,3 +66,3 @@ var | ||
describe('Posts(_username)', () => { | ||
describe('Posts(_username, [_limit])', () => { | ||
it('Testing schema of return object', async () => { | ||
@@ -104,4 +104,43 @@ const posts = await Instagram.users.posts('instagram'); | ||
}); | ||
it('Testing schema and length of limited return object', async () => { | ||
const posts = await Instagram.users.posts('instagram', 100); | ||
Expect(posts).to.be.an('array'); | ||
Expect(posts).to.have.length(100); | ||
Expect(posts).to.be.jsonSchema({ | ||
type: 'array', | ||
required: ['id', 'caption', 'shortcode', 'image', 'dimensions', 'likes', 'comments', 'owner', 'timestamp'], | ||
properties: { | ||
id: { | ||
type: 'string' | ||
}, | ||
caption: { | ||
type: 'string' | ||
}, | ||
shortcode: { | ||
type: 'string' | ||
}, | ||
image: { | ||
type: 'string' | ||
}, | ||
dimensions: { | ||
type: 'object' | ||
}, | ||
likes: { | ||
type: 'object' | ||
}, | ||
comments: { | ||
type: 'object' | ||
}, | ||
owner: { | ||
type: 'object' | ||
}, | ||
timestamp: { | ||
type: 'number' | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "public-instagram", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Tool to fetch Instagram's public content.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,3 +61,3 @@ # public-instagram | ||
// Get posts from a public user | ||
// Get all posts from a public user | ||
const posts = await instagram.users.posts('instagram'); | ||
@@ -64,0 +64,0 @@ console.log(posts.length); |
68189
854