Exemplo n.º 1
0
 public function queueStatus()
 {
     $config = $this->config('apiServer');
     $client = new Client(['host' => $config['host'], 'port' => 15672, 'auth' => ['username' => $config['user'], 'password' => $config['pass']]]);
     try {
         $queue_data = $client->get(sprintf('/api/queues/%s/%s', urlencode($config['path']), Configure::read('dj.service.name') . '-queue'), [], ['type' => 'json']);
     } catch (Exception $e) {
         return [];
     }
     $data = $queue_data->json;
     if (!isset($data['messages'])) {
         return null;
     }
     return ['messages' => $data['messages'], 'messages_ready' => $data['messages_ready'], 'messages_unacknowledged' => $data['messages_unacknowledged']];
 }
Exemplo n.º 2
0
 /**
  * Retrieve information about the authentication
  *
  * Will get the realm and other tokens by performing
  * another request without authentication to get authentication
  * challenge.
  *
  * @param \Cake\Http\Client\Request $request The request object.
  * @param array $credentials Authentication credentials.
  * @return array modified credentials.
  */
 protected function _getServerInfo(Request $request, $credentials)
 {
     $response = $this->_client->get($request->url(), [], ['auth' => []]);
     if (!$response->getHeader('WWW-Authenticate')) {
         return [];
     }
     preg_match_all('@(\\w+)=(?:(?:")([^"]+)"|([^\\s,$]+))@', $response->getHeaderLine('WWW-Authenticate'), $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $credentials[$match[1]] = $match[2];
     }
     if (!empty($credentials['qop']) && empty($credentials['nc'])) {
         $credentials['nc'] = 1;
     }
     return $credentials;
 }
 public function testUsingAuth()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function () {
         return new Response();
     }));
     $client = new Client(['auth' => ['type' => 'CvoTechnologies/Twitter.Twitter']]);
     $client->get('https://example.com');
 }