Permalink
Browse files

extract session generator to new service FacebookSessionManager

  • Loading branch information...
chemix committed Jun 14, 2014
1 parent dce5d9b commit 1f6302dff1a140b2f39898560ad7ac8f170933bf
Showing with 41 additions and 5 deletions.
  1. +1 −0 app/config/config.neon
  2. +28 −0 app/model/FacebookSessionManager.php
  3. +12 −5 app/model/FacebookWallposts.php
View
@@ -26,3 +26,4 @@ services:
- App\RouterFactory
router: @App\RouterFactory::createRouter
- App\Model\FacebookWallposts
- App\Model\FacebookSessionManager(%facebook.appId%, %facebook.appSecret%)
@@ -0,0 +1,28 @@
<?php
/**
* @author Honza Cerny <hello@honzacerny.com>
*/
namespace App\Model;
use Facebook\FacebookSession;
class FacebookSessionManager {
protected $appId;
protected $appSecret;
function __construct($appId, $appSecret)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
}
public function getAppSession()
{
return FacebookSession::newAppSession();
}
}
@@ -9,7 +9,6 @@
use Nette\Database\Context;
use Nette\Object;
use Facebook\FacebookRequest;
use Facebook\FacebookSession;
class FacebookWallposts extends Object
{
@@ -19,9 +18,19 @@ class FacebookWallposts extends Object
*/
protected $database;
function __construct(Context $database)
/**
* @var \App\Model\FacebookSessionManager
*/
protected $facebookSessionManager;
/**
* @param Context $database
* @param FacebookSessionManager $facebook
*/
function __construct(Context $database, FacebookSessionManager $facebook)
{
$this->database = $database;
$this->facebookSessionManager = $facebook;
}
public function getLastPosts($count = 5)
@@ -35,9 +44,7 @@ public function getLastPosts($count = 5)
public function importPostFromFacebook()
{
FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
$session = FacebookSession::newAppSession();
$session = $this->facebookSessionManager->getAppSession();
try {
$request = new FacebookRequest($session, 'GET', '/nettefw/feed');

0 comments on commit 1f6302d

Please sign in to comment.