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

Add OPML API #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/feedly.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@
});
};

Feedly.prototype._request2 = function(callback, path, method, body) {
var u;
if (method == null) {
method = 'GET';
}
if (body == null) {
body = null;
}
u = url.parse(this.options.base);
u.pathname = path;
return this._getAuth().then(function(auth) {
return utils.qrequest2({
method: method,
uri: url.format(u),
headers: {
Authorization: "OAuth " + auth
},
body: body,
callback: callback
});
});
};

Feedly.prototype._requestURL = function(callback, path, method, body) {
var u;
if (method == null) {
Expand Down Expand Up @@ -628,6 +651,17 @@
})(this));
};

Feedly.prototype.OPML = function(cb) {
return this._request(cb, '/v3/opml');
};

Feedly.prototype.importOPML = function(opml, cb) {
if ((opml == null) || (typeof opml === 'function')) {
throw new Error("opml required");
}
return this._request2(cb, '/v3/opml', 'POST', opml);
};

return Feedly;

})();
Expand Down
23 changes: 23 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@
return d.promise;
};

exports.qrequest2 = function(options) {
var cb, d;
if (options == null) {
throw new Error("options not optional");
}
d = q.defer();
cb = options.callback;
if (cb != null) {
delete options.callback;
d.promise.nodeify(cb);
}
request(options, function(er, res, body) {
if (er != null) {
return d.reject(er);
} else if (res.statusCode !== 200) {
return d.reject(new Error("HTTP error: " + res.statusCode + "\nFrom: " + options.uri + "\n" + (JSON.stringify(body))));
} else {
return d.resolve(body);
}
});
return d.promise;
};

if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, "find", {
enumerable: false,
Expand Down