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

Commit

Permalink
extended contents to support additional parameters, fixed issue in _q…
Browse files Browse the repository at this point in the history
…request 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
  • Loading branch information
baumhoto committed May 29, 2015
1 parent 2e1c281 commit 014e53a
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 8 deletions.
55 changes: 51 additions & 4 deletions lib/feedly.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
html_text: 'No HTML found',
slop: 3600000,
client_id: null,
client_secret: null
client_secret: null,
developer: false
}, options);
this.options.config_file = untildify(this.options.config_file);
this.options.html_file = untildify(this.options.html_file);
Expand Down Expand Up @@ -192,19 +193,31 @@
}
u = url.parse(this.options.base);
u.pathname = path;
return this._getAuth().then(function(auth) {
return this._getAuthForMode().then(function(auth) {
return utils.qrequest({
method: method,
uri: url.format(u),
headers: {
Authorization: "OAuth " + auth
},
body: body,
qs: body,
callback: callback
});
});
};

Feedly.prototype._getAuthForMode = function() {
var d;
if (this.options.developer) {
d = q.defer();
d.resolve(this.options.client_secret);
return d.promise;
} else {
return this._getAuth();
}
};

Feedly.prototype._requestURL = function(callback, path, method, body) {
var u;
if (method == null) {
Expand All @@ -216,7 +229,7 @@
u = url.parse(this.options.base);
u.pathname = path;
u.query = body;
return this._getAuth().then(function(auth) {
return this._getAuthForMode().then(function(auth) {
return utils.qrequest({
method: method,
uri: url.format(u),
Expand Down Expand Up @@ -371,6 +384,28 @@
});
};

Feedly.prototype.markEntrySaved = function(ids, cb) {
if (typeof ids === 'string') {
ids = [ids];
return this._request(cb, '/v3/markers', 'POST', {
entryIds: ids,
type: 'entries',
action: 'markAsSaved'
});
}
};

Feedly.prototype.markEntryUnsaved = function(ids, cb) {
if (typeof ids === 'string') {
ids = [ids];
}
return this._request(cb, '/v3/markers', 'POST', {
entryIds: ids,
type: 'entries',
action: 'markAsUnsaved'
});
};

Feedly.prototype.markFeedRead = function(ids, since, cb) {
var body, ref;
if (typeof ids === 'string') {
Expand Down Expand Up @@ -502,9 +537,21 @@
return this._request(cb, "/v3/streams/" + (encodeURIComponent(id)) + "/ids", 'GET', input);
};

Feedly.prototype.contents = function(id, continuation, cb) {
Feedly.prototype.contents = function(id, count, ranked, unreadOnly, newerThan, continuation, cb) {
var input;
input = {};
if (count != null) {
input.count = count;
}
if (ranked != null) {
input.ranked = ranked;
}
if (unreadOnly != null) {
input.unreadOnly = unreadOnly;
}
if (newerThan != null) {
input.newerThan = newerThan;
}
if (continuation != null) {
input.continuation = continuation;
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"name": "Joe Hildebrand",
"email": "joe-github@cursive.net"
},
"contributors": [{
"name": "Tobias Baumhöver",
"email": "baumhoto@gmail.com"
}],
"license": "MIT",
"bugs": {
"url": "https://github.com/hildjj/node-feedly/issues"
Expand Down
51 changes: 48 additions & 3 deletions src/feedly.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = class Feedly
# the token. (default: 3600000)
# @option options [String] client_id The API client ID. (REQUIRED)
# @option options [String] client_secret The API client Secret. (REQUIRED)
# @option options [bool] developer enable developer mode (default = false)
constructor: (options) ->
@options = utils.extend
port: 0
Expand All @@ -56,6 +57,7 @@ module.exports = class Feedly
slop: 3600000
client_id: null
client_secret: null
developer: false
, options
@options.config_file = untildify @options.config_file
@options.html_file = untildify @options.html_file
Expand Down Expand Up @@ -179,21 +181,32 @@ module.exports = class Feedly
_request: (callback, path, method='GET', body=null)->
u = url.parse @options.base
u.pathname = path
@_getAuth().then (auth)->

@_getAuthForMode().then (auth)->
utils.qrequest
method: method
uri: url.format(u)
headers:
Authorization: "OAuth #{auth}"
body: body
qs: body
callback: callback

# @nodoc
_getAuthForMode: ()->
if(@options.developer)
d = q.defer()
d.resolve @options.client_secret
return d.promise
else
return @_getAuth()

# @nodoc
_requestURL: (callback, path, method='GET', body=null)->
u = url.parse @options.base
u.pathname = path
u.query = body
@_getAuth().then (auth)->
@_getAuthForMode().then (auth)->
utils.qrequest
method: method
uri: url.format(u)
Expand Down Expand Up @@ -375,6 +388,30 @@ module.exports = class Feedly
type: 'entries'
action: 'keepUnread'

# Mark articles as saved.
#
# @param ids [Array(String)] article IDs to mark saved
# @param cb [function(error)] optional callback
markEntrySaved: (ids, cb) ->
if typeof(ids) == 'string'
ids = [ids]
@_request cb, '/v3/markers', 'POST',
entryIds: ids
type: 'entries'
action: 'markAsSaved'

# Mark articles as unsaved.
#
# @param ids [Array(String)] article IDs to mark unsaved
# @param cb [function(error)] optional callback
markEntryUnsaved: (ids, cb) ->
if typeof(ids) == 'string'
ids = [ids]
@_request cb, '/v3/markers', 'POST',
entryIds: ids
type: 'entries'
action: 'markAsUnsaved'

# Mark feed(s) as read.
#
# @param id [Array(String)] feed ID to mark read
Expand Down Expand Up @@ -533,8 +570,16 @@ 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) ->
contents: (id, count, ranked, unreadOnly, newerThan, continuation, cb) ->
input = {}
if count?
input.count = count
if ranked?
input.ranked = ranked
if unreadOnly?
input.unreadOnly = unreadOnly
if newerThan?
input.newerThan = newerThan
if continuation?
input.continuation = continuation
@_request cb, "/v3/streams/#{encodeURIComponent(id)}/contents", 'GET', input
Expand Down
33 changes: 32 additions & 1 deletion test/feedly.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ q = require 'q'
Feedly = require '../lib/feedly'

FEEDLY_SECRET = process.env.FEEDLY_SECRET
FEEDLY_DEVELOPER = process.env.FEEDLY_DEVELOPER
if !FEEDLY_SECRET?
throw new Error("Specify the client secret in the FEEDLY_SECRET environment variable")
if !FEEDLY_DEVELOPER?
throw new Error("Specify the developer token in the FEEDLY_DEVELOPER environment variable")

FEED_URL = 'http://blog.foodnetwork.com/fn-dish/feed/'
FEED = "feed/#{FEED_URL}"
Expand All @@ -17,6 +20,7 @@ module.exports =
f = new Feedly
client_id: 'sandbox'
client_secret: FEEDLY_SECRET
developer: false
base: 'http://sandbox.feedly.com'
port: 8080
config_file: CONFIG
Expand Down Expand Up @@ -85,6 +89,10 @@ module.exports =
f.markEntryRead id
.then ->
f.markEntryUnread id
.then ->
f.markEntrySaved id
.then ->
f.markEntryUnsaved id
.then ->
f.tagEntry id, 'test_tag_foo'
.then ->
Expand All @@ -108,10 +116,13 @@ module.exports =
.then (contents) ->
test.ok contents
test.ok Array.isArray(contents.items)
test.ok contents.items.length == 20
test.ok contents.continuation
f.contents FEED, contents.continuation
f.contents FEED, 10, 'oldest', true, null, contents.continuation
.then (contents) ->
test.ok contents
test.ok Array.isArray(contents.items)
test.ok contents.items.length == 10
f.markFeedRead FEED
.then ->
f.markCategoryRead 'testing_bar'
Expand Down Expand Up @@ -165,3 +176,23 @@ module.exports =
, (er) ->
console.log 'ERROR', er, er.stack
test.ifError er

feedsProd: (testprod)->
f = new Feedly
client_id: 'sandbox'
client_secret: FEEDLY_DEVELOPER
developer: true
base: 'https://cloud.feedly.com'
port: 8080
config_file: CONFIG

testprod.ok f
testprod.equals f.options.base, 'https://cloud.feedly.com'
f.categories()
.then (categories) ->
testprod.ok categories
.then ->
testprod.done()
, (er) ->
console.log 'ERROR', er, er.stack
testprod.ifError er

0 comments on commit 014e53a

Please sign in to comment.