Skip to content

Commit

Permalink
Merge pull request #15 from careerbuilder/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
gjacobrobertson authored Nov 14, 2017
2 parents 1ac595a + dc596a2 commit 5768884
Show file tree
Hide file tree
Showing 9 changed files with 1,377 additions and 150 deletions.
62 changes: 29 additions & 33 deletions controllers/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,33 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

module.exports = function FeedControllerModule(pb){
var util = pb.util;


function FeedController(){}

util.inherits(FeedController, pb.BaseController);

FeedController.prototype.getPagePosts = function(cb){
var OauthService = pb.PluginService.getService("oauthService", "pencilblue_facebook", this.site);
var PostsService = pb.PluginService.getService("postsService", "pencilblue_facebook", this.site);
var oauthService = new OauthService({"site":this.site});
var postsService = new PostsService({"site":this.site});
oauthService.getAccessToken(function(accessToken){
postsService.getPagePosts(accessToken, cb);
});
};

FeedController.getRoutes = function(cb){
var routes = [
{
method: 'get',
path: '/action/facebook/posts',
auth_required: false,
content_type: 'application/json',
handler: 'getPagePosts',
localization: true
}
];
cb(null, routes);
};

return FeedController;
module.exports = function FeedControllerModule(pb) {

class FeedController extends pb.BaseController {
getPagePosts(cb) {
const oauthService = new (pb.PluginService.getService('oauthService', 'pencilblue_facebook', this.site))({site: this.site});
const postService = new (pb.PluginService.getService('postsService', 'pencilblue_facebook', this.site))({site: this.site});
let pluginService = new pb.PluginService({site: this.site});
pluginService.getSettingsKV('pencilblue_facebook', (err, settings = {}) => {
oauthService.getAccessToken(settings, (accessToken) => {
postService.getPagePosts(accessToken, settings, cb);
});
});
}

static getRoutes(cb) {
cb(null, [
{
method: 'get',
path: '/action/facebook/posts',
auth_required: false,
content_type: 'application/json',
handler: 'getPagePosts',
localization: true
}
]);
}
}

return FeedController;
};
Loading

0 comments on commit 5768884

Please sign in to comment.