Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var qs = require("querystring"), OAuth2 = require("oauth").OAuth2;
- function Feedly(config) {
- this.baseUrl = config.feedly.baseUrl;
- this.authenticateUrl = config.feedly.authenticateUrl;
- this.clientId = config.secrets.clientId;
- this.redirectUrl = config.secrets.redirectUrl;
- this.scope = config.feedly.scope;
- this.oauth = new OAuth2(config.secrets.clientId, config.secrets.clientSecret, config.feedly.baseUrl, config.feedly.authenticateUrl, config.feedly.accessTokenUrl, null);
- this.oauth.useAuthorizationHeaderforGET(true);
- this.oauth.setAuthMethod("OAuth");
- }
- Feedly.prototype.getAuthClientRedirectUrl = function() {
- return this.baseUrl + this.authenticateUrl + "?client_id=" + this.clientId + "&response_type=code&redirect_uri=" + this.redirectUrl + "&scope=" + this.scope;
- };
- Feedly.prototype.getAccessToken = function(code, params, callback) {
- var params = params || {};
- params.grant_type = "authorization_code";
- params.redirect_uri = this.redirectUrl;
- this.oauth.getOAuthAccessToken(code, params, function(err, access_token, refresh_token, results) {
- if (err) {
- callback(err, undefined);
- }
- try {
- console.log(results);
- callback(null, access_token);
- } catch (e) {
- callback(e);
- }
- });
- };
- Feedly.prototype.getProfile = function(params, error, success) {
- var path = "profile";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getPreferences = function(params, error, success) {
- var path = "preferences";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getCategories = function(params, error, success) {
- var path = "categories";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getSubscriptions = function(params, error, success) {
- var path = "subscriptions";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getTopics = function(params, error, success) {
- var path = "topics";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getTags = function(params, error, success) {
- var path = "tags";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getFeed = function(params, error, success) {
- var path = "feed/" + params.feedId;
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getStreamIds = function(params, error, success) {
- console.log(encodeURIComponent(params.streamId));
- var path = "streams/" + encodeURIComponent(params.streamId) + "/ids";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getStreamContents = function(params, error, success) {
- console.log(encodeURIComponent(params.streamId));
- var path = "streams/" + encodeURIComponent(params.streamId) + "/contents";
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.getEntry = function(params, error, success) {
- var path = "entries/" + params.entryId;
- var url = this.baseUrl + path;
- this.doRequest(url, error, success);
- };
- Feedly.prototype.doRequest = function(url, error, success) {
- this.oauth.get(url, this.accessToken, function(err, body, response) {
- if (!err && response.statusCode == 200) {
- success(body);
- } else {
- error(err, response, body);
- }
- });
- };
- if (!(typeof exports === "undefined")) {
- exports.Feedly = Feedly;
- }
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement