From 1c68e18b7c8e14f135b264552834eb50519fb132 Mon Sep 17 00:00:00 2001 From: Nick Felker Date: Thu, 10 Jan 2019 16:26:39 -0800 Subject: [PATCH] Adds options for tokens in constructor Fixes #13 --- lib/feedly.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/feedly.js b/lib/feedly.js index ac96828..2d6540e 100644 --- a/lib/feedly.js +++ b/lib/feedly.js @@ -80,8 +80,15 @@ class Feedly { * @param {String} [options.base] - The root URL of the API. * (default: 'http://cloud.feedly.com') * @param {String} [options.config_file] - File in which state information such - * as the access token and refresh tokens are stored. Tildes are expanded - * as needed. (default: '~/.feedly') + * as the access token and refresh tokens are stored. Tildes are expanded + * as needed. Tokens can also be provided manually as options. + * (default: '~/.feedly') + * @param {String} [options.refresh_token] - User account refresh token. + * (default: undefined) + * @param {String} [options.access_token] - User account access token. + * (default: undefined) + * @param {String} [options.access_token_expires] - Time when the user account + * access token expires in milliseconds. (default: 0) * @param {String} [options.html_file] - File that contains the HTML to give to * the web browser after it is redirected to the one-shot web server that * we'll be running. (default: '../html/index.html') @@ -98,6 +105,9 @@ class Feedly { port: 0, base: 'http://cloud.feedly.com', config_file: '~/.feedly', + refresh_token: undefined, + access_token: undefined, + access_token_expires: 0, html_file: path.join(__dirname, '../html/index.html'), html_text: 'No HTML found', slop: 3600000, @@ -110,6 +120,13 @@ class Feedly { throw new Error('client_id and client_secret required') } this.state = {} + if (this.options.refresh_token && this.options.access_token && this.options.access_token_expires) { + this.state = { + refresh_token: this.options.refresh_token, + access_token: this.options.access_token, + expires: this.options.access_token_expires + } + } // allSettled ignores errors this.ready = Promise.all([this._loadConfig(), this._loadHTML()])