Пример #1
0
 public function execute($yql, $parameters = array(), $method = YahooCurl::GET)
 {
     $url = self::OAUTH_API_URL;
     $parameters = array_merge(array('q' => $yql, 'format' => 'json', 'env' => self::DATATABLES_URL), $parameters);
     $http = YahooCurl::fetch($url, $parameters, array(), $method, 'POST', array('debug' => true));
     return $http ? json_decode($http['response_body']) : false;
 }
Пример #2
0
 /**
  * Retrieve information from Twitter
  * @param string $hashtag
  * @return ArrayAccess
  */
 public function retrieve($hashtag, $rows)
 {
     $url = 'http://query.yahooapis.com/v1/public/yql';
     $query = 'select * from twitter.search where q="' . $hashtag . '" limit ' . (int) $rows . ';';
     try {
         $twittData = YahooCurl::fetch($url, array('q' => $query, 'env' => 'store://datatables.org/alltableswithkeys', 'format' => 'json'));
     } catch (Exception $e) {
         throw $e;
     }
     $object = json_decode($twittData['response_body'], true);
     $results = $object['query']['results']['results'];
     $knownusers = array();
     $retrieveInfos = array();
     foreach ($results as $twitter) {
         if (in_array($twitter['from_user'], $knownusers)) {
             continue;
         }
         $knownusers[] = $twitter['from_user'];
         $query = "select * from twitter.user.profile where id='" . $twitter['from_user'] . "' ";
         $userData = YahooCurl::fetch($url, array('q' => $query, 'env' => 'store://datatables.org/alltableswithkeys', 'format' => 'json'));
         $object = json_decode($userData['response_body'], true);
         $retrieveInfos[] = array(0 => $twitter['profile_image_url'], 1 => strtotime($twitter['created_at']), 2 => $twitter['from_user'], 3 => $twitter['text'], 4 => $object['query']['results']['item']['meta'][5]['content'], 5 => $object['query']['results']['item']['meta'][6]['content'], 6 => $twitter['from_user'] . '/status/' . $twitter['id'], 7 => 'http://twitter.com');
     }
     return new ArrayObject($retrieveInfos);
 }
Пример #3
0
 function request($request_method, array $headers, $url, $param_string)
 {
     //check for dependencies when request() is called so oauthpanda can catch the exception
     if (false === $this->include_path || false === is_file($this->include_path)) {
         $message = sprintf('<p>The <i>YahooCurl</i> client library is required. You can get it here:<br/>' . '<i><a href="http://github.com/yahoo/yos-social-php5/blob/master/lib/Yahoo/YahooCurl.class.php">' . 'http://github.com/yahoo/yos-social-php5/blob/master/lib/Yahoo/YahooCurl.class.php' . '</a></i><br/>' . 'Pass the location of the base file into the %s constructor, e.g.,<br/>' . '<i>\'oauth_client\' => new %s(\'path/to/YahooCurl.class.php\'),</i><br/>', __CLASS__, __CLASS__);
         throw new Exception($message);
     }
     require_once $this->include_path;
     //terse enforcement of types because we're not interfacing w/ user
     assert(is_string($url));
     assert(is_string($param_string) || is_null($param_string));
     //for now, only support get and post
     assert(is_string($request_method) && in_array($request_method, array('GET', 'POST')));
     switch ($request_method) {
         case 'GET':
             //append params to url, so they aren't encoded in a non-oauth-compliant way inside lib
             $url .= '?' . $param_string;
             $post_params = null;
             break;
         case 'POST':
             $post_params = $param_string;
             break;
         default:
             break;
     }
     //http://github.com/yahoo/yos-social-php5/blob/master/lib/Yahoo/YahooCurl.class.php
     require_once 'YahooCurl.class.php';
     $http = YahooCurl::fetch($url, null, $headers, $request_method, $post_params);
     return $http;
 }
Пример #4
0
 public function execute($yql, $parameters = array(), $method = YahooCurl::GET, $endpoint = "default")
 {
     $url = $endpoint == "oauth" ? self::OAUTH_API_URL : self::PUBLIC_API_URL;
     $parameters = array_merge(array('q' => $yql, 'format' => 'json', 'env' => self::DATATABLES_URL), $parameters);
     $http = YahooCurl::fetch($url, $parameters, array(), $method);
     return $http ? json_decode($http['response_body']) : false;
 }
 public function access_resource($oauth_request)
 {
     if ($oauth_request->get_normalized_http_method() == 'GET') {
         $http = YahooCurl::fetch($oauth_request->to_url(), array(), array(), $oauth_request->get_normalized_http_method());
     } else {
         $http = YahooCurl::fetch($oauth_request->to_url(), array(), array('Content-Type: application/x-www-form-urlencoded', 'Accept: *'), $oauth_request->get_normalized_http_method());
     }
     return $http['response_body'];
 }
 public function insertUpdate($params)
 {
     $guid = $this->token->yahoo_guid;
     $defaults = array('collectionID' => $guid, 'collectionType' => 'guid', 'class' => 'app', 'suid' => uniqid(mt_rand()), 'pubDate' => (string) time(), 'source' => 'APP.' . $this->application_id, 'type' => 'appActivity3', 'link' => '');
     $update = array_merge($defaults, $params);
     $body = array('updates' => array($update));
     $url = sprintf("http://social.yahooapis.com/v1/user/%s/updates/%s/%s", $update['collectionID'], $update['source'], $update['suid']);
     $oauth_request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, YahooCurl::PUT, $url);
     $oauth_request->sign_request($this->signature_method_hmac_sha1, $this->consumer, $this->token);
     $parameters = json_encode($body);
     $headers = array('Content-Type: application/json', 'Accept: application/json', $oauth_request->to_header());
     $http = YahooCurl::fetch($oauth_request->get_normalized_http_url(), array(), $headers, $oauth_request->get_normalized_http_method(), $parameters);
     return $http ? json_decode($http['response_body']) : false;
 }
Пример #7
0
 public function execute($yql, $parameters = array())
 {
     $http = YahooCurl::fetch(self::PUBLIC_API_URL, array_merge(array('q' => $yql, 'format' => 'json', 'env' => self::DATATABLES_URL), $parameters));
     return $http ? json_decode($http['response_body']) : false;
 }
 public function addContact($guid = null, $contact)
 {
     if ($guid == null && !is_null($this->token)) {
         $guid = $this->token->yahoo_guid;
     }
     $url = sprintf(YahooOAuthClient::SOCIAL_API_URL . '/user/%s/contacts', $guid);
     $parameters = array('format' => 'json');
     $data = array('contact' => $contact);
     $body = json_encode($data);
     $oauth_request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $url, $parameters);
     $oauth_request->sign_request($this->signature_method_hmac_sha1, $this->consumer, $this->token);
     $http = YahooCurl::fetch($oauth_request->to_url(), array(), array('Content-Type: application/json', 'Accept: *'), $oauth_request->get_normalized_http_method(), $body);
     return $http['response_body'];
 }
 public function insertUpdate($guid = null, $description, $title, $link)
 {
     if ($guid == null && !is_null($this->token)) {
         $guid = $this->token->yahoo_guid;
     }
     $source = 'APP.' . $this->application_id;
     $suid = 'ugc' . rand(0, 1000);
     $body = sprintf('
 { "updates": [ {
             "class": "app",
             "collectionType": "guid",
             "description": "%s",
             "suid": "%s",
             "link": "%s",
             "source": "%s",
             "pubDate": "%s",
             "title": "%s",
             "type": "appActivity",
             "collectionID": "%s"
         } ] }', $description, $suid, $link, $source, time(), $title, $guid);
     $url = sprintf('%s/user/%s/updates/%s/%s', YahooOAuthClient::SOCIAL_API_URL, $guid, $source, $suid);
     $parameters = array('format' => 'json');
     $oauth_request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'PUT', $url, $parameters);
     $oauth_request->sign_request($this->signature_method_hmac_sha1, $this->consumer, $this->token);
     $http = YahooCurl::fetch($oauth_request->to_url(), array(), array('Content-Type: application/x-www-form-urlencoded', 'Accept: *'), $oauth_request->get_normalized_http_method(), $body);
     return $http['response_body'];
 }