get() публичный Метод

Send GET request.
public get ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
Результат string
Пример #1
0
 /**
  * Requests a token of a particular type
  *
  * @param string $query
  * @return array parameters sent from the response body
  */
 public function token($type, array $options = array())
 {
     $defaults = array('params' => array('client_id', 'client_secret'));
     $options = array_merge_recursive($options, $defaults);
     $this->_parseParams($options);
     $url = $this->_config[$type];
     $result = parent::get($url, $options['params']);
     return $result;
 }
Пример #2
0
 public function testGetPath()
 {
     $http = new Service($this->_testConfig);
     $this->assertEqual('', $http->get('search.json'));
     $this->assertEqual('HTTP/1.1', $http->last->response->protocol);
     $this->assertEqual('200', $http->last->response->status['code']);
     $this->assertEqual('OK', $http->last->response->status['message']);
     $this->assertEqual('text/html', $http->last->response->type);
     $this->assertEqual('UTF-8', $http->last->response->encoding);
 }
 /**
  *
  * Retrieve Stackoverflow tags I am active on, equivalent to the users tags `me` endpoint.
  *
  * @param	int		$min	Stackoverflow `min`
  * @return	object	Returns an array user tags objects.
  */
 public static function me_tags($min = 5)
 {
     if ($cache = Cache::read('memcache', 'stackoverflow_me_tags')) {
         return $cache;
     }
     $service = new Service(array('scheme' => 'https', 'host' => 'api.stackexchange.com', 'timeout' => 2));
     // using `userid` instead of `me` so we don't need to auth
     $data = $service->get('/' . self::API_VERSION . '/users/' . self::USERID . '/tags?key=' . self::KEY . '&order=desc&min=' . $min . '&sort=popular&site=stackoverflow');
     $me_tags = self::response_to_object($data)->items;
     Cache::write('memcache', 'stackoverflow_me_tags', $me_tags, '+2 hours');
     return $me_tags;
 }
Пример #4
0
 /**
  * List users through API
  * Play around with changing the value of `q` to see
  * how the sent signature is unique for each combination of query paramters
  *
  * @param int $userId Id of user to make API call as
  * @param string $q Add a `q` argument to the URL to see it change
  */
 public function consume($userId = false, $q = '')
 {
     if (!$userId) {
         $this->error("Missing userId");
     }
     $user = Model::first($userId);
     $signature = $user->sign(array($this->path, 'q' => $q));
     $this->header("Generating different signatures for different urls");
     $this->columns(array(array('Path', 'Username', 'Signature'), array('/', $user->username, $user->sign(array('/', 'q' => $q))), array($this->path, $user->username, $signature)));
     $service = new Service(array('host' => $this->host));
     $resp = $service->get($this->path, compact('q'), array('type' => 'json', 'headers' => array('X_USERNAME' => $user->username, 'X_SIGNATURE' => $signature)));
     print_r($resp);
 }
Пример #5
0
 public function testDigestAuth()
 {
     $this->_testConfig += array('auth' => 'digest', 'username' => 'gwoo', 'password' => 'li3');
     $http = new Service($this->_testConfig);
     $response = $http->get('/http_auth/', array(), array('return' => 'response'));
     $this->assertEqual('success', $response->body());
 }
Пример #6
0
 public function testCurlGet()
 {
     $service = new Service(array('classes' => array('socket' => '\\lithium\\net\\socket\\Curl')));
     $this->assertPattern('/localhost/', $service->get());
 }