Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 014e53a

Browse files
committed
extended contents to support additional parameters, fixed issue in _qrequest related to additional parameters, modified unit-tests for contents
add support for feedly production developer mode added function markEntrySaved, markEntryUnsaved added test for developer-mode Added myself as contributor in package.json
1 parent 2e1c281 commit 014e53a

File tree

4 files changed

+135
-8
lines changed

4 files changed

+135
-8
lines changed

lib/feedly.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
html_text: 'No HTML found',
3737
slop: 3600000,
3838
client_id: null,
39-
client_secret: null
39+
client_secret: null,
40+
developer: false
4041
}, options);
4142
this.options.config_file = untildify(this.options.config_file);
4243
this.options.html_file = untildify(this.options.html_file);
@@ -192,19 +193,31 @@
192193
}
193194
u = url.parse(this.options.base);
194195
u.pathname = path;
195-
return this._getAuth().then(function(auth) {
196+
return this._getAuthForMode().then(function(auth) {
196197
return utils.qrequest({
197198
method: method,
198199
uri: url.format(u),
199200
headers: {
200201
Authorization: "OAuth " + auth
201202
},
202203
body: body,
204+
qs: body,
203205
callback: callback
204206
});
205207
});
206208
};
207209

210+
Feedly.prototype._getAuthForMode = function() {
211+
var d;
212+
if (this.options.developer) {
213+
d = q.defer();
214+
d.resolve(this.options.client_secret);
215+
return d.promise;
216+
} else {
217+
return this._getAuth();
218+
}
219+
};
220+
208221
Feedly.prototype._requestURL = function(callback, path, method, body) {
209222
var u;
210223
if (method == null) {
@@ -216,7 +229,7 @@
216229
u = url.parse(this.options.base);
217230
u.pathname = path;
218231
u.query = body;
219-
return this._getAuth().then(function(auth) {
232+
return this._getAuthForMode().then(function(auth) {
220233
return utils.qrequest({
221234
method: method,
222235
uri: url.format(u),
@@ -371,6 +384,28 @@
371384
});
372385
};
373386

387+
Feedly.prototype.markEntrySaved = function(ids, cb) {
388+
if (typeof ids === 'string') {
389+
ids = [ids];
390+
return this._request(cb, '/v3/markers', 'POST', {
391+
entryIds: ids,
392+
type: 'entries',
393+
action: 'markAsSaved'
394+
});
395+
}
396+
};
397+
398+
Feedly.prototype.markEntryUnsaved = function(ids, cb) {
399+
if (typeof ids === 'string') {
400+
ids = [ids];
401+
}
402+
return this._request(cb, '/v3/markers', 'POST', {
403+
entryIds: ids,
404+
type: 'entries',
405+
action: 'markAsUnsaved'
406+
});
407+
};
408+
374409
Feedly.prototype.markFeedRead = function(ids, since, cb) {
375410
var body, ref;
376411
if (typeof ids === 'string') {
@@ -502,9 +537,21 @@
502537
return this._request(cb, "/v3/streams/" + (encodeURIComponent(id)) + "/ids", 'GET', input);
503538
};
504539

505-
Feedly.prototype.contents = function(id, continuation, cb) {
540+
Feedly.prototype.contents = function(id, count, ranked, unreadOnly, newerThan, continuation, cb) {
506541
var input;
507542
input = {};
543+
if (count != null) {
544+
input.count = count;
545+
}
546+
if (ranked != null) {
547+
input.ranked = ranked;
548+
}
549+
if (unreadOnly != null) {
550+
input.unreadOnly = unreadOnly;
551+
}
552+
if (newerThan != null) {
553+
input.newerThan = newerThan;
554+
}
508555
if (continuation != null) {
509556
input.continuation = continuation;
510557
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"name": "Joe Hildebrand",
2222
"email": "[email protected]"
2323
},
24+
"contributors": [{
25+
"name": "Tobias Baumhöver",
26+
"email": "[email protected]"
27+
}],
2428
"license": "MIT",
2529
"bugs": {
2630
"url": "https://github.com/hildjj/node-feedly/issues"

src/feedly.coffee

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = class Feedly
4646
# the token. (default: 3600000)
4747
# @option options [String] client_id The API client ID. (REQUIRED)
4848
# @option options [String] client_secret The API client Secret. (REQUIRED)
49+
# @option options [bool] developer enable developer mode (default = false)
4950
constructor: (options) ->
5051
@options = utils.extend
5152
port: 0
@@ -56,6 +57,7 @@ module.exports = class Feedly
5657
slop: 3600000
5758
client_id: null
5859
client_secret: null
60+
developer: false
5961
, options
6062
@options.config_file = untildify @options.config_file
6163
@options.html_file = untildify @options.html_file
@@ -179,21 +181,32 @@ module.exports = class Feedly
179181
_request: (callback, path, method='GET', body=null)->
180182
u = url.parse @options.base
181183
u.pathname = path
182-
@_getAuth().then (auth)->
184+
185+
@_getAuthForMode().then (auth)->
183186
utils.qrequest
184187
method: method
185188
uri: url.format(u)
186189
headers:
187190
Authorization: "OAuth #{auth}"
188191
body: body
192+
qs: body
189193
callback: callback
190194

195+
# @nodoc
196+
_getAuthForMode: ()->
197+
if(@options.developer)
198+
d = q.defer()
199+
d.resolve @options.client_secret
200+
return d.promise
201+
else
202+
return @_getAuth()
203+
191204
# @nodoc
192205
_requestURL: (callback, path, method='GET', body=null)->
193206
u = url.parse @options.base
194207
u.pathname = path
195208
u.query = body
196-
@_getAuth().then (auth)->
209+
@_getAuthForMode().then (auth)->
197210
utils.qrequest
198211
method: method
199212
uri: url.format(u)
@@ -375,6 +388,30 @@ module.exports = class Feedly
375388
type: 'entries'
376389
action: 'keepUnread'
377390

391+
# Mark articles as saved.
392+
#
393+
# @param ids [Array(String)] article IDs to mark saved
394+
# @param cb [function(error)] optional callback
395+
markEntrySaved: (ids, cb) ->
396+
if typeof(ids) == 'string'
397+
ids = [ids]
398+
@_request cb, '/v3/markers', 'POST',
399+
entryIds: ids
400+
type: 'entries'
401+
action: 'markAsSaved'
402+
403+
# Mark articles as unsaved.
404+
#
405+
# @param ids [Array(String)] article IDs to mark unsaved
406+
# @param cb [function(error)] optional callback
407+
markEntryUnsaved: (ids, cb) ->
408+
if typeof(ids) == 'string'
409+
ids = [ids]
410+
@_request cb, '/v3/markers', 'POST',
411+
entryIds: ids
412+
type: 'entries'
413+
action: 'markAsUnsaved'
414+
378415
# Mark feed(s) as read.
379416
#
380417
# @param id [Array(String)] feed ID to mark read
@@ -533,8 +570,16 @@ module.exports = class Feedly
533570
# @param continuation [string] a continuation id is used to page
534571
# @param cb [function(error, Array(Page))] Optional callback
535572
# @return [promise(Array(Page))]
536-
contents: (id, continuation, cb) ->
573+
contents: (id, count, ranked, unreadOnly, newerThan, continuation, cb) ->
537574
input = {}
575+
if count?
576+
input.count = count
577+
if ranked?
578+
input.ranked = ranked
579+
if unreadOnly?
580+
input.unreadOnly = unreadOnly
581+
if newerThan?
582+
input.newerThan = newerThan
538583
if continuation?
539584
input.continuation = continuation
540585
@_request cb, "/v3/streams/#{encodeURIComponent(id)}/contents", 'GET', input

test/feedly.test.coffee

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ q = require 'q'
55
Feedly = require '../lib/feedly'
66

77
FEEDLY_SECRET = process.env.FEEDLY_SECRET
8+
FEEDLY_DEVELOPER = process.env.FEEDLY_DEVELOPER
89
if !FEEDLY_SECRET?
910
throw new Error("Specify the client secret in the FEEDLY_SECRET environment variable")
11+
if !FEEDLY_DEVELOPER?
12+
throw new Error("Specify the developer token in the FEEDLY_DEVELOPER environment variable")
1013

1114
FEED_URL = 'http://blog.foodnetwork.com/fn-dish/feed/'
1215
FEED = "feed/#{FEED_URL}"
@@ -17,6 +20,7 @@ module.exports =
1720
f = new Feedly
1821
client_id: 'sandbox'
1922
client_secret: FEEDLY_SECRET
23+
developer: false
2024
base: 'http://sandbox.feedly.com'
2125
port: 8080
2226
config_file: CONFIG
@@ -85,6 +89,10 @@ module.exports =
8589
f.markEntryRead id
8690
.then ->
8791
f.markEntryUnread id
92+
.then ->
93+
f.markEntrySaved id
94+
.then ->
95+
f.markEntryUnsaved id
8896
.then ->
8997
f.tagEntry id, 'test_tag_foo'
9098
.then ->
@@ -108,10 +116,13 @@ module.exports =
108116
.then (contents) ->
109117
test.ok contents
110118
test.ok Array.isArray(contents.items)
119+
test.ok contents.items.length == 20
111120
test.ok contents.continuation
112-
f.contents FEED, contents.continuation
121+
f.contents FEED, 10, 'oldest', true, null, contents.continuation
113122
.then (contents) ->
114123
test.ok contents
124+
test.ok Array.isArray(contents.items)
125+
test.ok contents.items.length == 10
115126
f.markFeedRead FEED
116127
.then ->
117128
f.markCategoryRead 'testing_bar'
@@ -165,3 +176,23 @@ module.exports =
165176
, (er) ->
166177
console.log 'ERROR', er, er.stack
167178
test.ifError er
179+
180+
feedsProd: (testprod)->
181+
f = new Feedly
182+
client_id: 'sandbox'
183+
client_secret: FEEDLY_DEVELOPER
184+
developer: true
185+
base: 'https://cloud.feedly.com'
186+
port: 8080
187+
config_file: CONFIG
188+
189+
testprod.ok f
190+
testprod.equals f.options.base, 'https://cloud.feedly.com'
191+
f.categories()
192+
.then (categories) ->
193+
testprod.ok categories
194+
.then ->
195+
testprod.done()
196+
, (er) ->
197+
console.log 'ERROR', er, er.stack
198+
testprod.ifError er

0 commit comments

Comments
 (0)