Comparing version
{ | ||
"name": "pickpocket", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Automatically archives unread items matching specific (configurable) criteria from the user's list to retain a slim list.", | ||
@@ -13,3 +13,4 @@ "main": "pickpocketApi.js", | ||
"dotenv": "^2.0.0", | ||
"eslint-config-janiskra": "^1.3.3", | ||
"eslint": "^3.14.0", | ||
"eslint-config-janiskra": "^2.0.0", | ||
"is-generator": "^1.0.3" | ||
@@ -39,3 +40,6 @@ }, | ||
"articles.js" | ||
] | ||
], | ||
"engines": { | ||
"node": ">6.0.0" | ||
} | ||
} |
@@ -7,11 +7,7 @@ /* @flow weak */ | ||
const PICKPOCKET_CONSUMER_KEY = '30843-dc2a59fc91f1549e81c9101d'; | ||
const REDIRECT_URI = 'http://janis-kra.github.io/Pickpocket'; | ||
const ERR_MODULE_NOT_INITIALIZED = 'module not initialized correctly ' + | ||
'(pass your consumer key as a parameter)'; | ||
const REDIRECT_URI = 'http://janis-kra.github.io/pickpocket/'; | ||
const ERR_NO_REQUEST_TOKEN = 'no (valid) request token given - get one ' + | ||
'by calling obtainRequestToken'; | ||
const pocket = (config) => new GetPocket(config); | ||
const createConfig = (options) => Object.assign( | ||
const createConfig = options => Object.assign( | ||
{}, | ||
@@ -22,2 +18,4 @@ { consumer_key: PICKPOCKET_CONSUMER_KEY, redirect_uri: REDIRECT_URI }, | ||
const pocket = config => new GetPocket(config || createConfig()); | ||
/** | ||
@@ -37,4 +35,3 @@ * Get all articles that comply with the given filtering options. The articles will by default only | ||
const params = Object.assign({ | ||
detailType: 'simple', | ||
access_token: token | ||
detailType: 'simple' | ||
}, options); | ||
@@ -69,3 +66,3 @@ pocket(config).get(params, (err, res) => { | ||
}; | ||
return getAllArticles({ token: token }, options).then((a) => { | ||
return getAllArticles(token, options).then((a) => { | ||
const deletionThreshold = new Date(); | ||
@@ -89,7 +86,12 @@ deletionThreshold.setMonth(deletionThreshold.getMonth() - maxMonths); | ||
action: 'tags_add', | ||
item_id: item.item_id | ||
item_id: item.item_id, | ||
tags: 'deleted by pickpocket' | ||
})) | ||
}; | ||
return new Promise((resolve, reject) => { | ||
if (items.length === 0) { | ||
resolve(true); | ||
} | ||
const config = createConfig({ access_token: token }); | ||
console.log(`token: ${token}, params: ${JSON.stringify(params)}`); | ||
pocket(config).send(params, (err, res) => { | ||
@@ -118,17 +120,24 @@ if (res) { | ||
} = {}) { | ||
const archivedArticles = []; | ||
getOverdueArticles({ | ||
return getOverdueArticles(token, { | ||
includeFavorites: includeFavorites, | ||
maxMonths: maxMonths | ||
}).then((overdueArticles) => { | ||
const archivedArticles = []; | ||
const config = createConfig({ access_token: token }); | ||
const p = pocket(config); | ||
for (const article of overdueArticles) { | ||
for (let article of overdueArticles) { | ||
p.archive({ item_id: article.item_id }, (err) => { | ||
if (!err) { | ||
archivedArticles.push(article); | ||
if (err) { | ||
console.error(`error deleting article ${JSON.stringify(article)}`); | ||
} | ||
}); | ||
archivedArticles.push(article); | ||
} | ||
}).then(() => addArchivedTag(token, archivedArticles)); | ||
return archivedArticles; | ||
}).then( | ||
(archivedArticles) => { | ||
addArchivedTag(token, archivedArticles); | ||
return archivedArticles; | ||
} | ||
); | ||
}; | ||
@@ -169,3 +178,4 @@ | ||
} | ||
return pocket().getAuthorizeURL(createConfig({ request_token: requestToken })); | ||
const config = createConfig({ request_token: requestToken }); | ||
return pocket().getAuthorizeURL(config); | ||
}; | ||
@@ -172,0 +182,0 @@ |
@@ -13,3 +13,4 @@ const p = require('./pickpocket'); | ||
url: p.getAuthorizationURL({ requestToken: t }) | ||
})) | ||
})), | ||
getAccessToken: (requestToken = '') => p.obtainAccessToken({ requestToken: requestToken }) | ||
}; |
12303
3.32%235
4.91%5
25%