From 4f235ea82f1ff331bdc1c974e0191219788eba0f Mon Sep 17 00:00:00 2001 From: Grigor Yeghiazaryan Date: Sat, 7 Nov 2015 21:18:11 -0800 Subject: [PATCH 1/3] Add options to contents function --- lib/feedly.js | 29 +++++++++++++++++++++-------- src/feedly.coffee | 17 ++++++++++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/feedly.js b/lib/feedly.js index c5d286c..79858f2 100644 --- a/lib/feedly.js +++ b/lib/feedly.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.10.0 (function() { var Feedly, _normalizeTag, fs, http, open, path, q, request, untildify, url, utils; @@ -55,14 +56,15 @@ return function(data) { var er, s; return _this.state = (function() { + var error; try { s = JSON.parse(data); if (s.expires != null) { s.expires = new Date(s.expires); } return s; - } catch (_error) { - er = _error; + } catch (error) { + er = error; return this.state = {}; } }).call(_this); @@ -510,13 +512,24 @@ return this._requestURL(cb, "/v3/streams/" + (encodeURIComponent(id)) + "/ids", 'GET', input); }; - Feedly.prototype.contents = function(id, continuation, cb) { + Feedly.prototype.contents = function(id, options, cb) { var input; - input = {}; - if (continuation != null) { - input.continuation = continuation; - } - return this._request(cb, "/v3/streams/" + (encodeURIComponent(id)) + "/contents", 'GET', input); + input = (function() { + switch (typeof options) { + case 'function': + cb = options; + return {}; + case 'string': + return { + continuation: options + }; + case 'object': + return options; + default: + return {}; + } + })(); + return this._requestURL(cb, "/v3/streams/" + (encodeURIComponent(id)) + "/contents", 'GET', input); }; Feedly.prototype.subscriptions = function(cb) { diff --git a/src/feedly.coffee b/src/feedly.coffee index 063b313..38de27b 100644 --- a/src/feedly.coffee +++ b/src/feedly.coffee @@ -539,11 +539,18 @@ module.exports = class Feedly # @param continuation [string] a continuation id is used to page # @param cb [function(error, Array(Page))] Optional callback # @return [promise(Array(Page))] - contents: (id, continuation, cb) -> - input = {} - if continuation? - input.continuation = continuation - @_request cb, "/v3/streams/#{encodeURIComponent(id)}/contents", 'GET', input + contents: (id, options, cb) -> + input = switch typeof(options) + when 'function' + cb = options + {} + when 'string' + continuation: options + when 'object' + options + else + {} + @_requestURL cb, "/v3/streams/#{encodeURIComponent(id)}/contents", 'GET', input # Get the user’s subscriptions # From dffb695360f2552af2896cdd0e3dd3d6ef480e0f Mon Sep 17 00:00:00 2001 From: Grigor Yeghiazaryan Date: Tue, 24 Nov 2015 17:27:49 -0800 Subject: [PATCH 2/3] Update docs --- src/feedly.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/feedly.coffee b/src/feedly.coffee index 38de27b..46c4c96 100644 --- a/src/feedly.coffee +++ b/src/feedly.coffee @@ -536,7 +536,8 @@ module.exports = class Feedly # Get the content of a stream # # @param id [string] the id of the stream - # @param continuation [string] a continuation id is used to page + # @param options [string|object] a continuation id is used to page + # or an object with stream request parameters # @param cb [function(error, Array(Page))] Optional callback # @return [promise(Array(Page))] contents: (id, options, cb) -> From 7c6e66d0214f2a5e92fe281a2d4a60186e4d45d8 Mon Sep 17 00:00:00 2001 From: Grigor Yeghiazaryan Date: Tue, 24 Nov 2015 17:28:34 -0800 Subject: [PATCH 3/3] Try to add test for contents new argument --- test/feedly.test.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/feedly.test.coffee b/test/feedly.test.coffee index a12c344..6c4556c 100644 --- a/test/feedly.test.coffee +++ b/test/feedly.test.coffee @@ -113,6 +113,10 @@ module.exports = test.ok Array.isArray(contents.items) test.ok contents.continuation f.contents FEED, contents.continuation + .then (contents) -> + test.ok contents + test.ok Array.isArray(contents.items) + f.contents FEED, {unreadOnly:true} .then (contents) -> test.ok contents f.markFeedRead FEED