Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Feb 5, 2016
1 parent 5730405 commit ae59afd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ const getNextOptions = (options, mentions) =>
? options
: merge(options, { max_id: pipe(last, prop('id_str'), dec)(mentions) });

function accumulate(get, options, mentions) {
function accumulate(client, options, mentions) {
const nextOptions = getNextOptions(options, mentions);
return get(nextOptions).then(res => {
return client.get('statuses/mentions_timeline', nextOptions).then(res => {
const accumulatedMentions = concat(mentions, res);
return (isEmpty(res))
? accumulatedMentions
: accumulate(get, nextOptions, accumulatedMentions);
: accumulate(client, nextOptions, accumulatedMentions);
});
}

export default function getMentions(tokens, sinceId) {
const client = new Twitter(tokens);
const get = client.get.bind(client, 'statuses/mentions_timeline');
const options = { trim_user: true, count: 200, since_id: sinceId };
return accumulate(get, options, []);
return accumulate(client, options, []);
}
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import tokens from 'twitter-tokens';
import { last } from 'ramda';
import dec from 'bignum-dec';

test('twitterMentions', { timeout: 30000 }, ({ equal, end } = t) => {
test('twitterMentions', { timeout: 30000 }, ({ equal, end }) => {
twitterMentions(tokens, '424125604925956096').then(mentions => {
equal(mentions.length, 19, 'proper mention’s number');
end();
});
});

test('twitterMentions including since_id', { timeout: 30000 }, ({ equal, end } = t) => {
test('twitterMentions including since_id', { timeout: 30000 }, ({ equal, end }) => {
twitterMentions(tokens, dec('424125604925956096')).then(mentions => {
equal(mentions.length, 20, 'proper mention’s number');
equal(last(mentions).id_str, '424125604925956096', 'including since_id');
Expand Down

0 comments on commit ae59afd

Please sign in to comment.