function __construct($config, $auth = NULL) { parent::__construct($config, $auth); osapiLogger::setLevel(osapiLogger::INFO); osapiLogger::setAppender(new osapiFileAppender("data/osapi.log")); $host = getConfig($config, 'conext_host', TRUE); $key = getConfig($config, 'conext_key', TRUE); $secret = getConfig($config, 'conext_secret', TRUE); $provider = new osapiProvider("https://{$host}/oauth/request_token", "https://{$host}/oauth/authorize", "https://{$host}/oauth/access_token", "https://{$host}/social/rest", "https://{$host}/social/rpc", 'SURFconext', TRUE, NULL); $auth = new osapiOAuth2Legged($key, $secret, $this->auth->getUserId()); $this->osapi = new osapi($provider, $auth); }
/** * configures and initializes the osapi object * * @return osapi object */ function initIWIWConnect($consumerKey, $consumerSecret, $iwiwBaseURL = "http://iwiw.hu", $iwiwBaseApiURL = "http://api.iwiw.hu") { // Log osapiLogger::setLevel(osapiLogger::INFO); osapiLogger::setAppender(new osapiFileAppender("/tmp/logs/osapi.log")); // Create an identifier for the local user's session session_start(); $localUserId = session_id(); //The persistent storage $storage = new osapiFileStorage('/tmp/osapistorage'); //$storage = new osapiMemcacheStorage('127.0.0.1','11211'); //the iwiw provider $provider = new osapiIwiwProvider($iwiwBaseURL, $iwiwBaseApiURL); $auth = osapiOAuth3Legged_10a_iwiw::performOAuthLogin($consumerKey, $consumerSecret, $storage, $provider, $localUserId); $osapi = new osapi($provider, $auth); return $osapi; }
<?php // Require the osapi library require_once "../src/osapi.php"; // Enable logger. osapiLogger::setLevel(osapiLogger::INFO); osapiLogger::setAppender(new osapiConsoleAppender()); $consumerKey = 'CONSUMER_KEY'; $consumerSecret = 'CONSUMER_SECRET'; $callbackUrl = 'CALLBACK_URL'; // needed to scope the access token storage $localUserId = ''; $storage = new osapiFileStorage('/tmp/osapi'); $provider = new osapiVzOAuth2Provider(osapiVzOAuth2Provider::STUDIVZ); if (isset($_GET['platform']) && $_GET['platform'] === 'schuelervz') { $provider = new osapiVzOAuth2Provider(osapiVzOAuth2Provider::SCHUELERVZ); } $auth = osapiOAuth2::performOAuthLogin($consumerKey, $consumerSecret, $storage, $provider, $callbackUrl, 'openid', array('gender', 'emails', 'thumbnailUrl'), 'my custom message', 'state', $localUserId); if ($auth->getAccessToken()->getplatform() === 'schuelervz') { $provider = new osapiVzOAuth2Provider(osapiVzOAuth2Provider::SCHUELERVZ); } $osapi = new osapi($provider, $auth); // Start a batch so that many requests may be made at once. $batch = $osapi->newBatch(); // Fetch the current user. $self_request_params = array('userId' => '@me', 'groupId' => '@self', 'fields' => array()); $batch->add($osapi->people->get($self_request_params), 'self'); $result = $batch->execute(); var_dump($result);
private function checkLogFunction($functionToTest, $levelToTest, $yesLevels, $noLevels) { $appender = new osapiDummyAppender(); osapiLogger::setAppender($appender); $message = "Hello world"; $logMessages = array("NONE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "ALL"); $oldLevel = osapiLogger::getLevel(); foreach ($yesLevels as $currentLevel) { $appender->lastLog = ""; osapiLogger::setLevel($currentLevel); osapiLogger::$functionToTest($message); $this->assertEquals($appender->lastLog, "[" . $logMessages[$levelToTest] . "][" . date(DATE_RFC822) . "] - {$message}\n"); } foreach ($noLevels as $currentLevel) { $appender->lastLog = ""; osapiLogger::setLevel($currentLevel); osapiLogger::$functionToTest($message); echo $appender->lastLog; $this->assertEquals($appender->lastLog, ""); } osapiLogger::setLevel($oldLevel); }