Esempio n. 1
0
 public function setHost($host)
 {
     $this->_host = $host;
     if ($this->_connection) {
         $this->_connection->setBaseUrl($host);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Creates a Salesforce REST API client that uses username-password authentication
  * @param AuthenticationInterface $authentication
  * @param Http\Client $guzzle
  * @param string $apiRegion The region to use for the Salesforce API.  i.e. na5 or cs30
  * @param string $apiVersion The version of the API to use.  i.e. v31.0
  * @param LoggerInterface $log
  */
 public function __construct(AuthenticationInterface $authentication, Http\Client $guzzle, $apiRegion, $apiVersion = 'v31.0', LoggerInterface $log = null)
 {
     $this->apiBaseUrl = str_replace(array('{region}', '{version}'), array($apiRegion, $apiVersion), static::SALESFORCE_API_URL_PATTERN);
     $this->log = $log ?: new NullLogger();
     $this->authentication = $authentication;
     $this->guzzle = $guzzle;
     $this->guzzle->setBaseUrl($this->apiBaseUrl);
 }
 public function __construct($clientId, $clientSecret, $username, $password, $securityToken, Http\Client $guzzle, LoggerInterface $log = null, $loginApiUrl = "https://login.salesforce.com/services/")
 {
     $this->log = $log ?: new NullLogger();
     $this->clientId = $clientId;
     $this->clientSecret = $clientSecret;
     $this->username = $username;
     $this->password = $password;
     $this->securityToken = $securityToken;
     $this->guzzle = $guzzle;
     $this->guzzle->setBaseUrl($loginApiUrl);
 }
 public function testClientReturnsValidBaseUrls()
 {
     $client = new Client('http://www.{foo}.{data}/', array('data' => '123', 'foo' => 'bar'));
     $this->assertEquals('http://www.bar.123/', $client->getBaseUrl());
     $client->setBaseUrl('http://www.google.com/');
     $this->assertEquals('http://www.google.com/', $client->getBaseUrl());
 }
 /**
  * Constructor requires final url endpoint to send request to as
  * first parameter. Optional second argument is a client object of type
  * Guzzle\Http\Client.
  *
  *
  * @param string $baseUrl Host to make requests to e.g. https://www.lush.co.uk
  * @param \Guzzle\Http\Client $client Instance of Guzzle client object to use.
  * @param bool $debug If set to true then debug messages will be emitted by the underlying Guzzle client
  */
 public function __construct($baseUrl, \Guzzle\Http\Client $client, $debug = false)
 {
     $this->baseUrl = $baseUrl;
     $client->setBaseUrl($this->baseUrl);
     $this->client = $client;
     $this->debug = (bool) $debug;
 }
Esempio n. 6
0
 /**
  * Returns the response body using the PHP cURL Extension
  * @param Config $config
  * @param string $request_path Request Path/URI
  * @throws HttpException Unable to query server
  */
 public function call(Config $config, $request_path)
 {
     // Setup
     $this->guzzle->setBaseUrl('http://' . $config->getCloudHost());
     $options = array('auth' => explode(':', $config->api_key, 2), 'timeout' => $this->timeout_ms / 1000, 'connect_timeout' => $this->timeout_ms / 1000, 'proxy' => $this->proxy);
     // Compression
     if ($this->use_compression === true) {
         $this->request_headers['Accept-Encoding'] = 'gzip';
     }
     // Execute
     try {
         $request = $this->guzzle->get($request_path, $this->request_headers, $options);
         $response = $request->send();
     } catch (BadResponseException $e) {
         return $this->processGuzzleResponse($e->getResponse());
     } catch (\Exception $e) {
         throw new HttpException("Unable to contact server: Guzzle Error: " . $e->getMessage(), null, $e);
     }
     return $this->processGuzzleResponse($response);
 }
 /**
  * Inject Guzzle in this test class
  * And set up the given client for use on
  * Damn Vulnerable Web Application... A vulnerable application
  * without API...
  * Difficulty resided in finding the way of using
  * cookies and correct documentation for all methods.
  */
 public function __construct()
 {
     parent::__construct();
     //prepare a cookie jar
     $jar = new ArrayCookieJar();
     $cookiePlugin = new CookiePlugin($jar);
     //get a guzzle instance
     $this->_dvwa_guzzle = new Client();
     $this->_dvwa_guzzle->setBaseUrl($this->DVWA_URL);
     $this->_dvwa_guzzle->setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
     $this->_dvwa_guzzle->addSubscriber($cookiePlugin);
     //first request/response exchange to get CSRF token
     $request = $this->_dvwa_guzzle->get('login.php', null, ["allow_redirects" => false]);
     $response = $request->send();
     $str = $response->getBody();
     preg_match($this->USER_TOKEN_REGEX, $str, $matches);
     $user_token = $matches[1];
     //second exchange to login
     $request = $this->_dvwa_guzzle->createRequest('POST', 'login.php', null, ['username' => 'admin', 'password' => 'password', 'Login' => 'Login', 'user_token' => $user_token], ["allow_redirects" => true]);
     $request->send();
 }
Esempio n. 8
0
 /**
  * Function to create a Guzzle HTTP request
  *
  * @param  string $baseUri         The protocol + host
  * @param  string $path            The URI path after the host
  * @param  string $httpMethod      The HTTP method to use for the request (GET, PUT, POST, DELTE etc.)
  * @param  array  $requestHeaders  Any additional headers for the request
  * @param  string $httpMethodParam Post parameter to set with a string that
  *                                 contains the HTTP method type sent with a POST
  * @return RequestManager
  */
 public function createRequest($baseUri, $path, $httpMethod = 'GET', $requestHeaders = array(), $httpMethodParam = null)
 {
     $this->client->setBaseUrl($baseUri);
     if (!in_array(strtolower($httpMethod), array('get', 'put', 'post', 'patch', 'delete', 'head'))) {
         throw new Exception("Invalid HTTP method");
     }
     $method = strtolower($httpMethod);
     $method = $method == 'patch' ? 'put' : $method;
     //override patch calls with put
     if ($httpMethodParam != null && in_array($method, array('put', 'post', 'patch', 'delete'))) {
         $this->request = $this->client->post($path);
         $this->request->setPostField($httpMethodParam, strtoupper($method));
     } else {
         $this->request = $this->client->{$method}($path);
     }
     //set any additional headers on the request
     $this->setHeaders($requestHeaders);
     //setup how we get data back (xml, json etc)
     $this->setTransportLanguage();
     return $this->request;
 }
Esempio n. 9
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('neo4j.curl', function ($app) {
         $curl = new Client();
         $curl->setBaseUrl($app['config']->get('neo4j.base_url'));
         return $curl;
     });
     $this->registerCypher();
     $this->registerIndex();
     $this->app->singleton('neo4j', function ($app) {
         return new Neo4jClient($app['neo4j.cypher'], $app['neo4j.index']);
     });
 }
Esempio n. 10
0
 /**
  * @param string $baseUrl
  * @param ConsumerCredentials $consumerCredentials
  * @param TokenCredentials $tokenCredentials
  *
  * @return Client
  */
 public function createClient($baseUrl, ConsumerCredentials $consumerCredentials, TokenCredentials $tokenCredentials = null)
 {
     $oAuthConfig = array('consumer_key' => $consumerCredentials->getKey(), 'consumer_secret' => $consumerCredentials->getSecret());
     if ($tokenCredentials instanceof TokenCredentials) {
         $oAuthConfig += array('token' => $tokenCredentials->getToken(), 'token_secret' => $tokenCredentials->getSecret());
     }
     $oAuth = new OAuth($oAuthConfig);
     $requestFactory = new JavaHttpRequestFactory();
     $client = new Client();
     $client->setBaseUrl($baseUrl)->addSubscriber($oAuth)->setRequestFactory($requestFactory);
     foreach ($this->subscribers as $subscriber) {
         $client->addSubscriber($subscriber);
     }
     return $client;
 }
 /**
  * @param string $queryString
  * @param AbstractEntity $entity
  * @return \Guzzle\http\Message\Response
  * @throws \Searchperience\Common\Http\Exception\EntityNotFoundException
  * @throws \Searchperience\Common\Http\Exception\MethodNotAllowedException
  * @throws \Searchperience\Common\Http\Exception\ForbiddenException
  * @throws \Searchperience\Common\Http\Exception\ClientErrorResponseException
  * @throws \Searchperience\Common\Exception\RuntimeException
  * @throws \Searchperience\Common\Http\Exception\ServerErrorResponseException
  * @throws \Searchperience\Common\Http\Exception\UnauthorizedException
  * @throws \Searchperience\Common\Http\Exception\InternalServerErrorException
  * @throws \Searchperience\Common\Http\Exception\RequestEntityTooLargeException
  */
 protected function getDeleteResponseFromEndpoint($queryString = '', $entity = NULL)
 {
     try {
         $postArray = $entity !== NULL ? $this->buildRequestArray($entity) : array();
         /** @var $response \Guzzle\http\Message\Response */
         $response = $this->restClient->setBaseUrl($this->baseUrl)->delete('/{customerKey}/' . $this->endpoint . $queryString, NULL, $postArray)->setAuth($this->username, $this->password)->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $exception) {
         $this->transformStatusCodeToClientErrorResponseException($exception);
     } catch (\Guzzle\Http\Exception\ServerErrorResponseException $exception) {
         $this->transformStatusCodeToServerErrorResponseException($exception);
     } catch (\Exception $exception) {
         throw new \Searchperience\Common\Exception\RuntimeException('Unknown error occurred; Please check parent exception for more details.', 1353579284, $exception);
     }
     return $response;
 }
Esempio n. 12
0
 /**
  * @return SearchResultDto
  * @throws \Guzzle\Http\Exception\BadResponseException
  */
 public function search()
 {
     $searchUrl = $this->prepareSearchUrl();
     $response = $this->guzzleClient->setBaseUrl($this->prepareSearchUrl())->get()->send();
     $responseBody = substr($response->getBody(true), 62, -2);
     if (!($responseDecoded = json_decode($responseBody))) {
         throw new BadResponseException('Status code ' . $response->getStatusCode() . ': ' . strip_tags($response->getBody(true)));
     }
     if ($responseDecoded->status == 'error') {
         $errorMessage = [];
         foreach ($responseDecoded->errors as $error) {
             $errorMessage[] = $error->reason . '. ' . $error->message . '. ' . $error->detailed_message;
         }
         throw new BadResponseException(implode(PHP_EOL, $errorMessage));
     }
     return $this->createDto($responseDecoded, $searchUrl);
 }
 public function __construct($guzzleClientSvc, $accessToken)
 {
     $this->guzzleClient = $guzzleClientSvc;
     $this->accessToken = $accessToken;
     $this->guzzleClient->setBaseUrl(self::CONTENTFUL_BASE_URL);
 }
Esempio n. 14
0
 /**
  * Restores the base URL in $client after a cal to setBaseUrl().
  */
 protected function restoreBaseUrl()
 {
     $this->client->setBaseUrl($this->cachedBaseUrl);
 }
Esempio n. 15
0
 /**
  * @param \Piece\Questetra\Core\RequestContext $requestContext
  */
 public function setRequestContext(RequestContext $requestContext)
 {
     $this->requestContext = $requestContext;
     $this->httpClient->setBaseUrl($this->requestContext->getContextRoot());
 }
 /**
  * Constructor
  *
  * [
  *     'base_url' => 'http://api.example.com/1.0/coverage',
  *     'auth'     => [
  *                       'user'     => 'user name',
  *                       'password' => 'password',
  *                   ],
  *     'create'   => [
  *                       'method' => 'POST',
  *                       'path'   => '/',
  *                   ],
  *     'read'     => [
  *                       'method' => 'GET',
  *                       'path'   => '/',
  *                   ],
  *     'delete'   => [
  *                       'method' => 'DELETE',
  *                       'path'   => '/',
  *                   ],
  * ]
  *
  * @param array               $config Configuration
  * @param \Guzzle\Http\Client $client HTTP client
  */
 public function __construct(array $config, Client $client)
 {
     $this->config = $config;
     $this->client = $client;
     $this->client->setBaseUrl($config['base_url']);
 }
Esempio n. 17
0
 public function setBaseUri($baseUri)
 {
     $this->client->setBaseUrl($baseUri);
 }
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
use StarterKit\MyClient as Client;
use Guzzle\Http\Client as HttpClient;
use PhraseanetSDK\HttpAdapter\Guzzle as HttpAdapter;
use Symfony\Component\HttpFoundation\Request;
$CONF = (require __DIR__ . "/../../conf/configuration.php");
$request = Request::createFromGlobals();
foreach ($CONF as $value) {
    if ('' === $value) {
        header(sprintf('Location: %s', 'configuration.php'));
    }
}
$httpClient = new HttpClient();
$httpClient->setBaseUrl($CONF['instance-url']);
$HttpAdapter = new HttpAdapter($httpClient);
$client = new Client($CONF['api-key'], $CONF['api-secret'], $HttpAdapter);
return $client;
Esempio n. 19
0
 public function __construct($url, HttpClient $http = null)
 {
     $this->http = $http ?: new HttpClient();
     $this->http->setBaseUrl($url);
 }
Esempio n. 20
0
 /**
  * @param Client $client
  */
 public function setClient($apiBaseUrl, Client $client)
 {
     $this->client = $client;
     $this->client->setBaseUrl($apiBaseUrl);
 }
 /**
  * @return void
  */
 public function setRestClientBaseUrl()
 {
     $this->restClient->setBaseUrl($this->getBaseUrl());
 }
 /**
  * @param string $url
  */
 public function setBaseUrl($url)
 {
     $this->client->setBaseUrl($url);
 }
Esempio n. 23
0
 /**
  * @param string $api
  * @param Client $client
  */
 public function __construct($api, Client $client)
 {
     $this->client = $client->setBaseUrl($api);
 }