示例#1
0
 /**
  * @param string $postalCode
  * @param string $houseNumber
  * @return array
  */
 public function lookupAddress($postalCode, $houseNumber)
 {
     $this->client->setConfig(['curl.options' => ['CURLOPT_CONNECTTIMEOUT_MS' => '2000', 'CURLOPT_RETURNTRANSFER' => true]]);
     $url = sprintf($this->baseUrl . '/%s/%s', $postalCode, $houseNumber);
     $request = $this->client->get($url)->setAuth($this->apiKey, $this->apiSecret);
     return $request->send()->json();
 }
 /**
  *
  * @param array $p
  * @return bool|TokenResponse
  */
 protected function accessTokenRequest(array $p)
 {
     $this->c->setConfig(array(\Guzzle\Http\Client::REQUEST_OPTIONS => array('allow_redirects' => false, 'exceptions' => false, 'verify' => false)));
     if ($this->clientConfig->getCredentialsInRequestBody()) {
         // provide credentials in the POST body
         $p['client_id'] = $this->clientConfig->getClientId();
         $p['client_secret'] = $this->clientConfig->getClientSecret();
     } else {
         // use basic authentication
         $curlAuth = new \Guzzle\Plugin\CurlAuth\CurlAuthPlugin($this->clientConfig->getClientId(), $this->clientConfig->getClientSecret());
         $this->c->addSubscriber($curlAuth);
     }
     try {
         $request = $this->c->post($this->clientConfig->getTokenEndpoint());
         $request->addPostFields($p);
         $request->addHeader('Accept', 'application/json');
         $responseData = $request->send()->json();
         // some servers do not provide token_type, so we allow for setting
         // a default
         // issue: https://github.com/fkooman/php-oauth-client/issues/13
         if (null !== $this->clientConfig->getDefaultTokenType()) {
             if (is_array($responseData) && !isset($responseData['token_type'])) {
                 $responseData['token_type'] = $this->clientConfig->getDefaultTokenType();
             }
         }
         // if the field "expires_in" has the value null, remove it
         // issue: https://github.com/fkooman/php-oauth-client/issues/17
         if ($this->clientConfig->getAllowNullExpiresIn()) {
             if (is_array($responseData) && array_key_exists("expires_in", $responseData)) {
                 if (null === $responseData['expires_in']) {
                     unset($responseData['expires_in']);
                 }
             }
         }
         // if the field "scope" is empty string a default can be set
         // through the client configuration
         // issue: https://github.com/fkooman/php-oauth-client/issues/20
         if (null !== $this->clientConfig->getDefaultServerScope()) {
             if (is_array($responseData) && isset($responseData['scope']) && '' === $responseData['scope']) {
                 $responseData['scope'] = $this->clientConfig->getDefaultServerScope();
             }
         }
         return new TokenResponse($responseData);
     } catch (\Guzzle\Common\Exception\RuntimeException $e) {
         return false;
     }
 }
 public function testAllowsConfigsToBeChangedAndInjectedInBaseUrl()
 {
     $client = new Client('http://{a}/{b}');
     $this->assertEquals('http:///', $client->getBaseUrl());
     $this->assertEquals('http://{a}/{b}', $client->getBaseUrl(false));
     $client->setConfig(array('a' => 'test.com', 'b' => 'index.html'));
     $this->assertEquals('http://test.com/index.html', $client->getBaseUrl());
 }
 /**
  * Makes http request to remote host.
  *
  * @param string $url
  * @param mixed  $data
  * @param array $options
  *
  * @throws \ErrorException|\Exception
  * @return mixed
  */
 protected function sendRequest($url, $data, $options = null)
 {
     $client = new HttpClient();
     $client->setConfig(array('curl.options' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
     $request = $client->post($url, null, $data);
     try {
         return $request->send()->getBody();
     } catch (RequestException $e) {
         throw new CommunicationError('Communication failed: ' . $url);
     }
 }
示例#5
0
 /**
  * @param array|\Guzzle\Common\Collection $config
  * @return Client $this
  */
 public function setGuzzleConfig($config)
 {
     $this->client->setConfig($config);
     return $this;
 }
    $configuration['database'] = $processor->processConfiguration(new DatabaseConfiguration(), array($database));
    $configuration['mailer'] = $processor->processConfiguration(new MailerConfiguration(), array($mailer));
    $configuration['leboncoin'] = $processor->processConfiguration(new LeboncoinConfiguration(), array($leboncoin));
    return $configuration;
};
$app['db'] = function ($app) {
    $config = $app['configuration']['database']['connection'];
    if (isset($config['path'])) {
        $config['path'] = substr($config['path'], 0, 1) == '/' ? $config['path'] : __DIR__ . '/../' . $config['path'];
    }
    return DriverManager::getConnection($config, new Configuration());
};
$app['guzzle'] = function ($app) {
    $guzzle = new GuzzleClient($app['configuration']['leboncoin']['url']);
    if (null !== ($proxy = $app['configuration']['leboncoin']['proxy'])) {
        $guzzle->setConfig(array('request.options' => array('proxy' => $proxy)));
    }
    return $guzzle;
};
$app['client'] = function ($app) {
    return new LeboncoinClient($app['guzzle']);
};
$app['bid.manager'] = function ($app) {
    return new BidManager($app['db']);
};
$app['alert.manager'] = function ($app) {
    return new AlertManager($app['db']);
};
$app['twig'] = function ($app) {
    $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../templates');
    return new \Twig_Environment($loader);
 /**
  * Instantiate a Guzzle HTTP client object
  *
  * @return Client
  */
 public function getClient()
 {
     if (is_null($this->client)) {
         $this->client = new Client(sprintf('%s://%s', Config::GRAPH_USE_SSL === true ? 'https' : 'http', Config::GRAPH_BASE_URL));
         $this->client->setConfig(array('exceptions' => true));
     }
     return $this->client;
 }
 /**
  * {@inheritdoc}
  */
 public function setTimeout($timeout)
 {
     $guzzleConfig = array(Client::CURL_OPTIONS => array(CURLOPT_TIMEOUT => $timeout, CURLOPT_CONNECTTIMEOUT => $timeout));
     $this->client->setConfig($guzzleConfig);
 }
示例#9
0
 /**
  *
  */
 public function __construct()
 {
     $this->guzzleClient = new Guzzle\Http\Client(static::$baseUrl);
     $this->guzzleClient->setConfig(array('defaults' => array('headers' => array('Content-Type' => 'application/json', 'Authorization' => sprintf('Bearer %s', $this->accessToken)))));
 }