Example #1
0
 public function getMessage($msg, ClientInterface $client)
 {
     if ($msg = 'Can you get my clothes laundered, please') {
         $this->laundry = $client->getClothes();
         $this->clientAddress = $client->getAddress();
         $this->getTaxi();
     }
     return $this->laundry;
 }
Example #2
0
 /**
  * If slave synchronous syncing is enabled (@see self::OPT_SLAVES_SYNC_ENABLED) then this method ensures
  * that @see self::OPT_SLAVES_SYNC_REQUIRED_COUNT number of slaves will acknowledge all issued commands
  * within @see self::OPT_SLAVES_SYNC_TIMEOUT. If syncing is enabled and slaves fail to acknowledge the issued
  * commands then an exception is thrown
  */
 protected function waitForSlaveSync()
 {
     if ($this->options[self::OPT_SLAVES_SYNC_ENABLED]) {
         $synced = $this->redis->wait($this->options[self::OPT_SLAVES_SYNC_REQUIRED_COUNT], $this->options[self::OPT_SLAVES_SYNC_TIMEOUT]);
         if ($synced < $this->options[self::OPT_SLAVES_SYNC_REQUIRED_COUNT]) {
             throw new Exception\NotEnoughSlavesSynced(sprintf('Required: %d, synced: %d', $this->options[self::OPT_SLAVES_SYNC_REQUIRED_COUNT], $synced));
         }
     }
 }
 /**
  * Prepare a guzzle http request
  *
  * @param  string $verb
  * @param  url    $url
  * @param  array  $data
  * @param  bool   $async
  * @return GuzzleHttp\Request
  */
 protected function prepareRequest($verb, $url, array $data, $async = false)
 {
     if (version_compare(ClientInterface::VERSION, '6') === 1) {
         $options = ['form_params' => $data];
     } else {
         $options = ['body' => $data];
     }
     $options['future'] = $async;
     return $this->client->createRequest($verb, $url, $options);
 }
Example #4
0
 protected function doPost($name, $content, $assoc = false)
 {
     $res = false;
     $this->code = 0;
     $this->respectRateLimit();
     try {
         $rtmp = $this->client->request("POST", sprintf('%s/%s?api_key=%s', $this->node, $name, $this->key), ['form_params' => $content, 'http_errors' => false]);
         $res = $this->getResult($rtmp, $assoc);
     } catch (\Exception $e) {
     }
     return $res;
 }
 /** @dataProvider provideStorage */
 public function testSaveClient(ClientInterface $storage)
 {
     if ($storage instanceof NullStorage) {
         $this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
         return;
     }
     $clientId = 'some-client-' . rand();
     // create a new client
     $success = $storage->setClientDetails($clientId, 'somesecret', 'http://test.com', 'client_credentials', 'clientscope1', '*****@*****.**');
     $this->assertTrue($success);
     // valid client_id
     $details = $storage->getClientDetails($clientId);
     $this->assertEquals($details['client_secret'], 'somesecret');
     $this->assertEquals($details['redirect_uri'], 'http://test.com');
     $this->assertEquals($details['grant_types'], 'client_credentials');
     $this->assertEquals($details['scope'], 'clientscope1');
     $this->assertEquals($details['user_id'], '*****@*****.**');
 }
 public function testGlobalErrorHandler()
 {
     $this->client->expects($this->once())->method('call')->with('system.multicall', array(array(array('methodName' => 'method1', 'params' => array('arg11', 'arg12')), array('methodName' => 'method2', 'params' => array('arg21', 'arg22')))))->will($this->returnValue(array('return1', array('faultCode' => 200))));
     $individualSuccessHandlerResults = array();
     $individualSuccessHandler = function ($result) use(&$individualSuccessHandlerResults) {
         $individualSuccessHandlerResults[] = $result;
     };
     $globalSuccessHandlerResults = array();
     $globalSuccessHandler = function ($result) use(&$globalSuccessHandlerResults) {
         $globalSuccessHandlerResults[] = $result;
     };
     $globalErrorHandlerResults = array();
     $globalErrorHandler = function ($result) use(&$globalErrorHandlerResults) {
         $globalErrorHandlerResults[] = $result;
     };
     $results = $this->multicall->addCall('method1', array('arg11', 'arg12'), $individualSuccessHandler)->addCall('method2', array('arg21', 'arg22'), $individualSuccessHandler)->onSuccess($globalSuccessHandler)->onError($globalErrorHandler)->execute();
     $this->assertSame(array('return1', array('faultCode' => 200)), $results);
     $this->assertSame($results, $individualSuccessHandlerResults);
     $this->assertSame(array('return1'), $globalSuccessHandlerResults);
     $this->assertSame(array(array('faultCode' => 200)), $globalErrorHandlerResults);
 }
Example #7
0
 /**
  * @param string $url
  * @param array  $options
  *
  * @return array
  */
 protected function makeRequest($url, array $options = [])
 {
     if ($this->client === null) {
         $this->client = new HttpClient();
         $adapter = new \Zend\Http\Client\Adapter\Curl();
         $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $this->client->setAdapter($adapter);
     }
     $key = $this->getRequestKey($url, $options);
     if ($this->cache->hasItem($key) === true) {
         return $this->cache->getItem($key);
         //            $options = array_replace_recursive($options, [
         //                'headers' => [
         //                    'If-Modified-Since' => $this->cache->getMetadata($key)['mtime'],
         //                ],
         //            ]);
     }
     $options = array_replace_recursive($options, ['headers' => ['Accept' => 'application/json', 'User-Agent' => $this->getUserAgent()], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()]]);
     $request = new Request();
     $request->setUri($url);
     foreach ($options['query'] as $param => $value) {
         $request->getQuery()->{$param} = $value;
     }
     $request->getHeaders()->addHeaders($options['headers']);
     $request->setMethod(Request::METHOD_GET);
     try {
         $response = $this->client->dispatch($request);
     } catch (ClientException $exception) {
         if ($exception->getCode() === 404) {
             return null;
         }
         throw new BattleNetException($exception->getResponse()->json()['detail'], $exception->getCode());
     }
     //return json_decode($response->getBody(), true);
     return $this->handleSuccessfulResponse($response, $key);
 }
 /**
  * 绑定第三方账号
  * @param  ClientInterface $client
  * @return \yii\web\Response
  */
 public function connect(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     $provider = $client->getId();
     $clientId = $attributes['id'];
     $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId);
     if ($account === null) {
         $account = Yii::createObject(['class' => UserAccount::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'user_id' => Yii::$app->user->id, 'created_at' => time()]);
         $account->save(false);
         Yii::$app->session->setFlash('success', '账号绑定成功');
     } else {
         Yii::$app->session->setFlash('error', '绑定失败,此账号已经绑定过了');
     }
     $this->action->successUrl = Url::to(['/user/setting/networks']);
 }
Example #9
0
 /** {@inheritdoc} */
 public function multicall()
 {
     return $this->wrapped->multicall();
 }
Example #10
0
 /**
  * Set client instance
  * @param ClientInterface $client
  * @return Rtm
  */
 public function setClient(ClientInterface $client)
 {
     $client->setRtm($this);
     $this->client = $client;
     return $this;
 }
Example #11
0
 /**
  * Invokes remote command
  *
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function __call($method, array $parameters)
 {
     return $this->client->call($this->prependNamespace($method), $parameters);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function isValid(ClientInterface $client, $redirectUri)
 {
     $pattern = sprintf('/^https?:\\/\\/.*%s(?:\\/.*)?$/', preg_replace('/\\./', '\\.', $client->getDomain()));
     return $client->isActive() && preg_match($pattern, $redirectUri);
 }
Example #13
0
 /**
  * Perform a batch request.
  *
  * @param  array $requests
  * @return mix
  */
 public function batch(array $requests = [])
 {
     $request = new \Zimbra\Soap\Request\Batch($requests);
     return $this->_client->doRequest($request);
 }
 /**
  * Updates the given client in the underlying data layer.
  *
  * @param ClientInterface $client
  * @return void
  */
 public function updateClient(ClientInterface $client)
 {
     if (isset($this->clients[$client->getAccessToken()])) {
         $this->clients[$client->getAccessToken()] = $client;
     }
 }
Example #15
0
 protected function sendStream($data)
 {
     $this->client->write($data);
 }