/** * @param Logger $logger * @param $client * @param $method * @param $host * @param $resource * @param string|null $login * @param string|null $password * @param bool|false $useCookie */ function __construct(Logger $logger, $client, $method, $host, $resource, $login = null, $password = null, $useCookie = false) { $this->logger = $logger; $this->client = $client; $this->method = $method; $this->host = $host; $this->resource = $resource; $this->login = $login; $this->password = $password; $this->useCookie = $useCookie; $this->client->getClient()->setOption(CURLINFO_HEADER_OUT, true); if ($this->login) { $listener = new BasicAuthListener($this->login, $this->password); if (!$this->hasListener($this->client, $listener)) { $this->logger->addDebug('BasicAuthListener: ' . $this->login . ' ' . substr($this->password, 3, 7)); $this->client->addListener($listener); } } if ($this->useCookie) { $listener = new \Avtonom\WebGateBundle\Listener\CookieListener(); if (!$this->hasListener($this->client, $listener)) { $this->logger->addDebug('CookieListener'); $this->client->addListener($listener); } } }
/** * @param string $accessToken * @param Browser $browser (optional) * @param ListenerInterface $listener (optional) * @param ExceptionInterface $exception (optional) */ public function __construct($accessToken, Browser $browser = null, ListenerInterface $listener = null, ExceptionInterface $exception = null) { $curl = new Curl(); $curl->setTimeout(10); // 10 seconds $this->browser = $browser ?: new Browser($curl); $this->browser->addListener($listener ?: new BuzzOAuthListener($accessToken)); $this->exception = $exception; }
public function __construct(Browser $browser, $clientId, $clientSecret, $accessToken = null) { $this->browser = $browser; $this->clientId = $clientId; $this->clientSecret = $clientSecret; // todo retrieve accessToken from cache if ($accessToken === null) { $accessToken = $this->getAccessToken(); } $this->browser->addListener(new BearerAuthListener($accessToken)); }
/** * Instantiated a new http client * * @param array $options Http client options * @param null|Browser $browser Buzz client */ public function __construct(array $options = array(), Browser $browser = null) { $this->options = array_merge($this->options, $options); $this->browser = $browser ?: new Browser(new Curl()); $this->browser->getClient()->setTimeout($this->options['timeout']); $this->browser->getClient()->setVerifyPeer(false); if (null !== $this->options['login'] || null !== $this->options['token']) { if (null !== $this->options['token']) { $options = array($this->options['token']); } else { $options = array($this->options['login'], $this->options['password']); } $this->browser->addListener(new AuthListener($this->options['auth_method'], $options)); } }
/** * Tapfiliate constructor. * * @param string $key */ public function __construct($key) { Assertion::string($key); // @see https://github.com/kriswallsmith/Buzz/pull/186 $listener = new Buzz\Listener\CallbackListener(function (Buzz\Message\RequestInterface $request, $response = null) use($key) { if ($response) { // postSend } else { // preSend $request->addHeader(sprintf('Api-Key: %s', $key)); } }); $this->browser = new Buzz\Browser(new Buzz\Client\Curl()); $this->browser->addListener($listener); }
protected function createBrowser($user = null, $password = null) { $browser = new Buzz\Browser(); if ($user) { $browser->addListener(new Buzz\Listener\BasicAuthListener($user, $password)); } return $browser; }
/** * Fetch from the API * @param string $endpoint Fetch from the endpoint * @param array $params Any parameters * @return \stdClass|\stdClass[] */ public static function fetch($endpoint, array $params = []) { $client = self::getClient(); $browser = new Browser($client); $method = Request::METHOD_GET; foreach (self::$postEndpoints as $check) { if (preg_match("/^{$check}\$/", $endpoint)) { $method = Request::METHOD_POST; } } $request = new FormRequest($method, $endpoint, self::BASE_URL); $request->setFields($params); $response = new Response(); $listener = new JsonListener(); $browser->addListener($listener); $response = $browser->send($request, $response); return $response->getContent(); }
/** * Does the actual sending * * @param \RMS\PushNotificationsBundle\Message\BlackberryMessage $message * @return bool */ protected function doSend(BlackberryMessage $message) { $separator = "mPsbVQo0a68eIL3OAxnm"; $body = $this->constructMessageBody($message, $separator); $browser = new Browser(new Curl()); $listener = new BasicAuthListener($this->appID, $this->password); $browser->addListener($listener); $url = "https://pushapi.na.blackberry.com/mss/PD_pushRequest"; if ($this->evaluation) { $url = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest"; } $headers = array(); $headers[] = "Content-Type: multipart/related; boundary={$separator}; type=application/xml"; $headers[] = "Accept: text/html, *"; $headers[] = "Connection: Keep-Alive"; $response = $browser->post($url, $headers, $body); return $this->parseResponse($response); }
<?php require '../vendor/autoload.php'; use Buzz\Browser; use Buzz\Client\Curl; use Buzz\Listener\DigestAuthListener; $username = '******'; $password = '******'; // // This URL will Authenticate usernames user1 through user9, password is the same as the username. // $url = 'http://test.webdav.org/auth-digest/'; // Create Curl Client $curl = new Curl(); $browser = new Browser(); $browser->setClient($curl); // Create DigestAuthListener $browser->addListener(new DigestAuthListener($username, $password)); // // This URL will Authenticate any username and password that matches those in the URL. // It requires the Browser/Client to respond with the same Cookie in order to Authenticate. // // $url = 'http://httpbin.org/digest-auth/auth-int/' . $username . '/' . $password; $response = $browser->get($url); echo $response; $statusCode = $response->getStatusCode(); if ($statusCode == 401) { $response = $browser->get($url); } echo $response;
/** * * This code is copied from Ctsmedia\Phpbb\BridgeBundle\PhpBB\Connector * @return Browser */ protected function initContaoRequest() { // Init Request $client = new Curl(); $client->setMaxRedirects(0); $browser = new Browser(); $browser->setClient($client); $cookieListener = new CookieListener(); $browser->addListener($cookieListener); return $browser; }
/** * @return Browser */ protected function initForumRequest($force = false) { // Init Request $client = new Curl(); $client->setMaxRedirects(0); $browser = new Browser(); $browser->setClient($client); $cookieListener = new CookieListener(); $browser->addListener($cookieListener); // We need to make sure that the if the original Request is already coming from the forum, we then are not // allowed to send a request to the forum so we create a login loop for example. if ($force === false && System::getContainer()->get('request_stack')->getCurrentRequest() && System::getContainer()->get('request_stack')->getCurrentRequest()->headers->get('x-requested-with') == 'ContaoPhpbbBridge') { System::log('Bridge Request Recursion detected', __METHOD__, TL_ERROR); throw new TooManyRequestsHttpException(null, 'Internal recursion Bridge requests detected'); } return $browser; }
/** * Constructor * * @param string $token Access Token * @param Browser|null $browser (optional) Browser Instance */ public function __construct($token, Browser $browser = null) { $this->browser = $browser ?: new Browser(function_exists('curl_exec') ? new Curl() : new FileGetContents()); $this->browser->addListener(new BuzzAsaasAuthListener($token)); }
/** * @param string $accessToken * @param Browser $browser (optional) * @param ListenerInterface $listener (optional) * @param ExceptionInterface $exception (optional) */ public function __construct($accessToken, Browser $browser = null, ListenerInterface $listener = null, ExceptionInterface $exception = null) { $this->browser = $browser ?: new Browser(new Curl()); $this->browser->addListener($listener ?: new BuzzOAuthListener($accessToken)); $this->exception = $exception; }
<?php require '../vendor/autoload.php'; use Buzz\Browser; use Buzz\Client\Curl; use Buzz\Listener\CookieListener; $browser = new Browser(); $client = new Curl(); $client->setMaxRedirects(0); $browser->setClient($client); // Create CookieListener $listener = new CookieListener(); $browser->addListener($listener); // This URL set two Cookies, k1=v1 and k2=v2 $response = $browser->get('http://httpbin.org/cookies/set?k1=v1&k2=v2'); // This URL will return the two set Cookies $response = $browser->get('http://httpbin.org/cookies'); echo $response; // Should output /* { "cookies": { "k1": "v1", "k2": "v2" } } */ // The Cookies are able to be retrieved and set using getCookies and setCookies on the Listener. print_r($listener->getCookies());
/** * Creates the HTTP abstraction object hierarchy. * For this purpose we use an external library called "Buzz". * * For $instanceConfig documentation see self::getDataService. * * @param array $instanceConfig * @return Browser */ protected static function getHTTPClientInstance(array $instanceConfig) { $username = isset($instanceConfig['Instance']['user']) === true ? $instanceConfig['Instance']['user'] : ''; $password = isset($instanceConfig['Instance']['pass']) === true ? $instanceConfig['Instance']['pass'] : ''; // Bootstrap the REST client $curlClient = new Curl(); $curlClient->setVerifyPeer(false); $restClient = new Browser($curlClient); if ($username && $password) { $authListener = new BasicAuthListener($username, $password); $restClient->addListener($authListener); } return $restClient; }
public function __construct(Browser $browser, $config) { $browser->addListener(new YammerListener($config['api_base_url'], $config['token'])); $this->browser = $browser; $this->defaultGroupId = $config['default_group_id']; }