-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
btidwell
committed
Apr 10, 2015
1 parent
c77727e
commit 3721152
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module.exports = function FeedControllerModule(pb){ | ||
var util = pb.util; | ||
var PluginService = pb.PluginService; | ||
var OauthService = pb.PluginService.getService("oauthService", "pencilblue_facebook"); | ||
var PostsService = pb.PluginService.getService("postsService", "pencilblue_facebook"); | ||
var FB = require('fb'); | ||
|
||
function FeedController(){}; | ||
|
||
util.inherits(FeedController, pb.BaseController); | ||
|
||
FeedController.prototype.getPagePosts = function(cb){ | ||
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' | ||
} | ||
]; | ||
cb(null, routes); | ||
}; | ||
|
||
return FeedController; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"uid": "pencilblue_facebook", | ||
"name": "Facebook Plugin", | ||
"description": "Facebook feed plugin for Pencilblue", | ||
"pb_version": "0.4.x", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "CareerBuilder CMS Team", | ||
"email": "talentengagementcloud@careerbuilder.com", | ||
"website": "http://careerbuilder.com", | ||
"contributors": [ | ||
{ | ||
"name": "Christina Chatham", | ||
"email": "christina.chatham@careerbuilder.com" | ||
}, | ||
{ | ||
"name": "Ben Tidwell", | ||
"email": "ben.tidwell@careerbuilder.com" | ||
}, | ||
{ | ||
"name": "Corrine Olson", | ||
"email": "corrine.olson@careerbuilder.com" | ||
}, | ||
{ | ||
"name": "Evan Adams", | ||
"email": "Evan.Adams@careerbuilder.com" | ||
} | ||
] | ||
}, | ||
"settings": [ | ||
{ | ||
"name": "app_id", | ||
"value": "" | ||
}, | ||
{ | ||
"name": "app_secret", | ||
"value": "" | ||
}, | ||
{ | ||
"name": "facebook_page_id", | ||
"value": "" | ||
} | ||
], | ||
"permissions": { | ||
"ACCESS_USER": [], | ||
"ACCESS_WRITER": [], | ||
"ACCESS_EDITOR": [], | ||
"ACCESS_MANAGING_EDITOR": [] | ||
}, | ||
"main_module": { | ||
"path": "facebook.js" | ||
}, | ||
"dependencies": { | ||
"fb": "0.7.0" | ||
}, | ||
"theme": { | ||
"settings": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = function FacebookPluginModule(pb) { | ||
function Facebook(){} | ||
|
||
/** | ||
* Called when the application is being installed for the first time. | ||
* | ||
* @param cb A callback that must be called upon completion. cb(Error, Boolean). | ||
* The result should be TRUE on success and FALSE on failure | ||
*/ | ||
Facebook.onInstall = function(cb) { | ||
pb.log.info("Facebook Plugin Installed"); | ||
cb(null, true); | ||
}; | ||
|
||
/** | ||
* Called when the application is uninstalling this plugin. The plugin should | ||
* make every effort to clean up any plugin-specific DB items or any in function | ||
* overrides it makes. | ||
* | ||
* @param cb A callback that must be called upon completion. cb(Error, Boolean). | ||
* The result should be TRUE on success and FALSE on failure | ||
*/ | ||
Facebook.onUninstall = function(cb) { | ||
pb.log.info("Facebook Job Plugin Uninstalled"); | ||
cb(null, true); | ||
}; | ||
|
||
/** | ||
* Called when the application is starting up. The function is also called at | ||
* the end of a successful install. It is guaranteed that all core PB services | ||
* will be available including access to the core DB. | ||
* | ||
* @param cb A callback that must be called upon completion. cb(Error, Boolean). | ||
* The result should be TRUE on success and FALSE on failure | ||
*/ | ||
Facebook.onStartup = function(cb) { | ||
cb(null, true); | ||
}; | ||
|
||
/** | ||
* Called when the application is gracefully shutting down. No guarantees are | ||
* provided for how much time will be provided the plugin to shut down. | ||
* | ||
* @param cb A callback that must be called upon completion. cb(Error, Boolean). | ||
* The result should be TRUE on success and FALSE on failure | ||
*/ | ||
Facebook.onShutdown = function(cb) { | ||
cb(null, true); | ||
}; | ||
|
||
return Facebook; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = function OauthServiceModule(pb){ | ||
var PluginService = pb.PluginService; | ||
var FB = require('fb'); | ||
|
||
function OauthService(){} | ||
|
||
OauthService.init = function(cb){ | ||
pb.log.debug("OauthService: Initialized"); | ||
cb(null, true); | ||
}; | ||
|
||
OauthService.getName = function(){ | ||
return "oauthService"; | ||
}; | ||
|
||
OauthService.getAccessToken = function(cb){ | ||
var pluginService = new PluginService(); | ||
pluginService.getSettingsKV('pencilblue_facebook', function(err, settings){ | ||
FB.api('oauth/access_token', { | ||
client_id: settings.app_id, | ||
client_secret: settings.app_secret, | ||
grant_type: 'client_credentials' | ||
}, function (res) { | ||
if(!res || res.error) { | ||
console.log(!res ? 'error occurred' : res.error); | ||
throw res.error; | ||
} | ||
var accessToken = res.access_token; | ||
FB.setAccessToken(accessToken); | ||
if(cb){ | ||
cb(accessToken); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
return OauthService; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = function PostsServiceModule(pb){ | ||
var PluginService = pb.PluginService; | ||
var FB = require('fb'); | ||
|
||
function PostsService(){} | ||
|
||
PostsService.init = function(cb){ | ||
pb.log.debug("PostsService: Initialized"); | ||
cb(null, true); | ||
}; | ||
|
||
PostsService.getName = function(){ | ||
return "postsService"; | ||
}; | ||
|
||
PostsService.getPagePosts = function(accessToken, cb){ | ||
var pluginService = new PluginService(); | ||
pluginService.getSettingsKV('pencilblue_facebook', function(err, settings){ | ||
FB.api('/v2.3/' + settings.facebook_page_id + '/posts', {"access_token":accessToken},function(response){ | ||
cb({ | ||
status:200, | ||
content:JSON.stringify(response) | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
return PostsService; | ||
}; |