/** * Sends a request using the supplied parameters. * * @param string $url the requested URL * @param string $method the HTTP verb to use * @param string $postBody the optional POST body to send in the request * @param boolean $headers whether or not to return header information * @param string $ua the user agent to send in the request * @return array the returned data, parsed response headers, and status code */ public function send($url, $method, $postBody = false, $headers = false, $ua = self::USER_AGENT) { $this->request = array('url' => $url, 'method' => $method, 'body' => $postBody, 'headers' => $headers); osapiLogger::info("HTTP Request"); osapiLogger::info($this->request); $response = array_shift($this->responses); osapiLogger::info("HTTP Response"); osapiLogger::info($response); return $response; }
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; }
/** * Sends a request using the supplied parameters. * * @param string $url the requested URL * @param string $method the HTTP verb to use * @param string $postBody the optional POST body to send in the request * @param boolean $headers whether or not to return header information * @param string $ua the user agent to send in the request * @return array the returned data, parsed headers, and status code */ public function send($url, $method, $postBody = false, $headers = false, $ua = self::USER_AGENT) { $ch = curl_init(); $request = array('url' => $url, 'method' => $method, 'body' => $postBody, 'headers' => $headers); osapiLogger::info("HTTP Request"); osapiLogger::info($request); curl_setopt($ch, CURLOPT_URL, $url); if ($postBody) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody); } // We need to set method even when we don't have a $postBody 'DELETE' curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $ua); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_HEADER, true); if ($headers && is_array($headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $data = @curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $errno = @curl_errno($ch); $error = @curl_error($ch); @curl_close($ch); if ($errno != CURLE_OK) { throw new osapiException("HTTP Error: " . $error); } list($raw_response_headers, $response_body) = explode("\r\n\r\n", $data, 2); $response_header_lines = explode("\r\n", $raw_response_headers); array_shift($response_header_lines); $response_headers = array(); foreach ($response_header_lines as $header_line) { list($header, $value) = explode(': ', $header_line, 2); if (isset($response_header_array[$header])) { $response_header_array[$header] .= "\n" . $value; } else { $response_header_array[$header] = $value; } } $response = array('http_code' => $http_code, 'data' => $response_body, 'headers' => $response_header_array); osapiLogger::info("HTTP Response"); osapiLogger::info($response); return $response; }
<?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);
public static function setAppender($logAppender) { self::$logAppender = $logAppender; }
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); }
/** * Returns the base string of this request * * The base string defined as the method, the url * and the parameters (normalized), each urlencoded * and the concated with &. */ public function get_signature_base_string() { $parts = array($this->get_normalized_http_method(), $this->get_normalized_http_url(), $this->get_signable_parameters()); $parts = OAuthUtil::urlencode_rfc3986($parts); $baseString = implode('&', $parts); osapiLogger::info('oauth base string ' . $baseString); return $baseString; }
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. **/ require_once dirname(__FILE__) . '/../common.inc.php'; /** * Yahoo! Open Social Rest End Point: http://appstore.apps.yahooapis.com/social/rest */ // get current session id $session_id = session_id(); // enable osapi logging to file osapiLogger::setLevel(osapiLogger::INFO); osapiLogger::setAppender(new osapiFileAppender(sys_get_temp_dir() . '/opensocial.log')); // create yahoo open social provider $provider = new osapiYahooProvider(); // create file system storage using system temp directory $storage = new osapiFileStorage(sys_get_temp_dir()); // if this is a YAP application, the access token and secret // will be provided. if (isset($_POST['yap_viewer_access_token']) && isset($_POST['yap_viewer_access_token_secret']) && isset($_POST['yap_viewer_guid'])) { $oauth = new osapiOAuth3Legged(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $storage, $provider, $_POST['yap_viewer_guid'], $_POST['yap_viewer_guid'], $_POST['yap_viewer_access_token'], $_POST['yap_viewer_access_token_secret']); } else { $oauth = osapiOAuth3Legged::performOAuthLogin(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $storage, $provider, $session_id); } // create open social instance from yahoo provider + oauth credentials $opensocial = new osapi($provider, $oauth); // The number of friends to fetch. $friend_count = 10;
<?php /** * Copyright 2009 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Report everything ini_set('error_reporting', E_ALL | E_STRICT); // Use a default timezone or else strtotime will raise errors date_default_timezone_set('America/Los_Angeles'); // Include paths to the library and test folder set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__)) . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../src')); require_once 'osapi.php'; // Enable logger. osapiLogger::setLevel(osapiLogger::INFO); osapiLogger::setAppender(new osapiFileAppender("/tmp/logs/osapi.log"));