示例#1
0
 public function doGetCallback(Application $app, Request $request, $api_name)
 {
     $error_message = '';
     try {
         $api = \Bridge_Api::get_by_api_name($app, $api_name);
         $connector = $api->get_connector();
         $response = $connector->connect();
         $user_id = $connector->get_user_id();
         try {
             $account = \Bridge_Account::load_account_from_distant_id($app, $api, $app['authentication']->getUser(), $user_id);
         } catch (\Bridge_Exception_AccountNotFound $e) {
             $account = \Bridge_Account::create($app, $api, $app['authentication']->getUser(), $user_id, $connector->get_user_name());
         }
         $settings = $account->get_settings();
         if (isset($response['auth_token'])) {
             $settings->set('auth_token', $response['auth_token']);
         }
         if (isset($response['refresh_token'])) {
             $settings->set('refresh_token', $response['refresh_token']);
         }
         $connector->set_auth_settings($settings);
         $connector->reconnect();
     } catch (\Exception $e) {
         $error_message = $e->getMessage();
     }
     $params = ['error_message' => $error_message];
     return $app['twig']->render('prod/actions/Bridge/callback.html.twig', $params);
 }
示例#2
0
 public function setUp()
 {
     parent::setUp();
     try {
         self::$api = \Bridge_Api::get_by_api_name(self::$DI['app'], 'apitest');
     } catch (\Bridge_Exception_ApiNotFound $e) {
         self::$api = \Bridge_Api::create(self::$DI['app'], 'apitest');
     }
     try {
         self::$account = \Bridge_Account::load_account_from_distant_id(self::$DI['app'], self::$api, self::$DI['user'], 'kirikoo');
     } catch (\Bridge_Exception_AccountNotFound $e) {
         self::$account = \Bridge_Account::create(self::$DI['app'], self::$api, self::$DI['user'], 'kirikoo', 'coucou');
     }
 }
示例#3
0
 public function bootTestCase()
 {
     $application = self::$DI['app'];
     try {
         self::$api = Bridge_Api::get_by_api_name($application, 'apitest');
     } catch (Bridge_Exception_ApiNotFound $e) {
         self::$api = Bridge_Api::create($application, 'apitest');
     }
     try {
         self::$account = Bridge_Account::load_account_from_distant_id($application, self::$api, self::$DI['user'], 'kirikoo');
     } catch (Bridge_Exception_AccountNotFound $e) {
         self::$account = Bridge_Account::create($application, self::$api, self::$DI['user'], 'kirikoo', 'coucou');
     }
 }
示例#4
0
 public function bootTestCase()
 {
     self::$DI['user'];
     if (!self::$object) {
         $sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
         $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
         self::$api = Bridge_Api::create(self::$DI['app'], 'Apitest');
         self::$dist_id = 'EZ1565loPP';
         self::$named = 'Fête à pinpins';
         $account = Bridge_Account::create(self::$DI['app'], self::$api, self::$DI['user'], self::$dist_id, self::$named);
         self::$id = $account->get_id();
         self::$object = new Bridge_Account(self::$DI['app'], self::$api, self::$id);
     }
 }
 public function setUp()
 {
     parent::setUp();
     try {
         $sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
         $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
         $this->api = Bridge_Api::create(self::$DI['app'], 'Apitest');
         $this->dist_id = 'EZ1565loPP';
         $this->named = 'Fête à pinpins';
         $this->account = Bridge_Account::create(self::$DI['app'], $this->api, self::$DI['user'], $this->dist_id, $this->named);
         $this->object = new Bridge_AccountSettings(self::$DI['app']['phraseanet.appbox'], $this->account);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
示例#6
0
 public function setUp()
 {
     parent::setUp();
     $sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
     $stmt = self::$DI['app']->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $this->api = Bridge_Api::create(self::$DI['app'], 'Apitest');
     $this->dist_id = 'EZ1565loPP';
     $this->named = 'Fête à pinpins';
     $this->account = Bridge_Account::create(self::$DI['app'], $this->api, self::$DI['user'], $this->dist_id, $this->named);
     $this->title = 'GOGACKO';
     $this->status = 'Processing';
     $element = Bridge_Element::create(self::$DI['app'], $this->account, self::$DI['record_1'], $this->title, $this->status, $this->account->get_api()->get_connector()->get_default_element_type());
     $this->id = $element->get_id();
     $this->object = new Bridge_Element(self::$DI['app'], $this->account, $this->id);
 }
示例#7
0
 public function setUp()
 {
     parent::setUp();
     $this->auth = $this->getMock("Bridge_Api_Auth_Interface");
     $this->bridgeApi = $this->getMock('Bridge_Api_Abstract', ["is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"], [self::$DI['app']['url_generator'], self::$DI['app']['conf'], $this->auth, self::$DI['app']['translator']]);
     if (!self::$api) {
         $application = $this->getApplication();
         try {
             self::$api = Bridge_Api::get_by_api_name($application, 'apitest');
         } catch (Bridge_Exception_ApiNotFound $e) {
             self::$api = Bridge_Api::create($application, 'apitest');
         }
         try {
             self::$account = Bridge_Account::load_account_from_distant_id($application, self::$api, self::$DI['user'], 'kirikoo');
         } catch (Bridge_Exception_AccountNotFound $e) {
             self::$account = Bridge_Account::create($application, self::$api, self::$DI['user'], 'kirikoo', 'coucou');
         }
     }
 }
示例#8
0
 /**
  *
  * @return Bridge_Api_Dailymotion
  */
 protected function set_auth_params()
 {
     $this->_auth->set_parameters(['client_id' => $this->conf->get(['main', 'bridge', 'dailymotion', 'client_id']), 'client_secret' => $this->conf->get(['main', 'bridge', 'dailymotion', 'client_secret']), 'redirect_uri' => Bridge_Api::generate_callback_url($this->generator, $this->get_name()), 'scope' => '', 'response_type' => 'code', 'token_endpoint' => self::OAUTH2_TOKEN_ENDPOINT, 'auth_endpoint' => self::OAUTH2_AUTHORIZE_ENDPOINT]);
     return $this;
 }
示例#9
0
 /**
  *
  * @param Application $app
  * @param Bridge_Api  $api
  * @param User        $user
  * @param string      $dist_id
  * @param string      $name
  *
  * @return Bridge_Account
  */
 public static function create(Application $app, Bridge_Api $api, User $user, $dist_id, $name)
 {
     $sql = 'INSERT INTO bridge_accounts
         (id, api_id, dist_id, usr_id, name, created_on, updated_on)
         VALUES (null, :api_id, :dist_id, :usr_id, :name, NOW(), NOW())';
     $params = [':api_id' => $api->get_id(), ':dist_id' => $dist_id, ':usr_id' => $user->getId(), ':name' => $name];
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $account_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
     return new self($app, $api, $account_id);
 }
示例#10
0
 public function testGet_updated_on()
 {
     $this->assertInstanceOf('DateTime', $this->object->get_updated_on());
     $this->assertTrue($this->object->get_updated_on() <= new DateTime());
     $this->assertTrue($this->object->get_updated_on() >= $this->object->get_created_on());
 }