本文整理汇总了PHP中Buzz\Browser类的典型用法代码示例。如果您正苦于以下问题:PHP Browser类的具体用法?PHP Browser怎么用?PHP Browser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Browser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
if (empty($remoteIp)) {
throw new CaptchaException('RemoteIp missing');
}
$headers = array('User-Agent' => 'solvemedia/PHP', 'Content-Type' => 'application/x-www-form-urlencoded', 'Connection' => 'close');
$content = array('privatekey' => $this->privateKey, 'remoteip' => $remoteIp, 'challenge' => $challenge, 'response' => $response);
$browser = new Browser();
try {
/** @var Response $resp */
$resp = $browser->post(self::ADCOPY_VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to check captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
/**
* 0: true|false
* 1: errorMessage (optional)
* 2: hash
*/
$answers = explode("\n", $resp->getContent());
$success = filter_var($answers[0], FILTER_VALIDATE_BOOLEAN);
if (!$success) {
return new CaptchaResponse($success, $answers[1]);
}
$hashMaterial = $answers[0] . $challenge . $this->hashKey;
$hash = sha1($hashMaterial);
if ($hash != $answers[2]) {
throw new CaptchaException('Hash verification error');
}
return new CaptchaResponse($success);
}
开发者ID:iamraghavgupta,项目名称:paytoshi-faucet,代码行数:43,代码来源:SolveMediaService.php
示例2: plugAction
/**
* @Route("/produit/{id}", name="product_plug")
* @Template()
*/
public function plugAction($id)
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/products/' . $id);
$product = $this->get('jms_serializer')->deserialize($response->getContent(), 'Kali\\Front\\CommandBundle\\Entity\\Product', 'json');
return array('product' => $product, 'site' => $this->container->getParameter("back_site"), 'caracteristics' => $product->getCaracteristics());
}
开发者ID:danielnunes,项目名称:projet-kali-front,代码行数:11,代码来源:ProductController.php
示例3: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
if (empty($remoteIp)) {
throw new CaptchaException('RemoteIp missing');
}
$headers = array('Connection' => 'close');
$content = array('secret' => $this->privateKey, 'remoteip' => $remoteIp, 'response' => $response);
$browser = new Browser();
$browser->getClient()->setVerifyPeer(false);
try {
/** @var Response $resp */
$resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to check captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
$answer = json_decode($resp->getContent());
if (!$answer) {
throw new CaptchaException('Error: Invalid captcha response');
}
$success = isset($answer->success) && filter_var($answer->success, FILTER_VALIDATE_BOOLEAN);
if (!$success) {
return new CaptchaResponse($success, 'Invalid captcha');
}
return new CaptchaResponse($success);
}
开发者ID:iamraghavgupta,项目名称:paytoshi-faucet,代码行数:37,代码来源:RecaptchaService.php
示例4: sendHeartbeat
public function sendHeartbeat()
{
$ip = null;
$localIps = $this->getLocalIp();
if (isset($localIps['eth0'])) {
$ip = $localIps['eth0'];
} elseif (isset($localIps['wlan0'])) {
$ip = $localIps['wlan0'];
}
if (null == $ip) {
throw new \Exception('No local IP available.');
}
$settings = $this->em->getRepository('AppBundle:Settings')->findAll();
if (count($settings) > 0) {
$settings = $settings[0];
} else {
throw new \Exception('No settings provided.');
}
$buzz = new Browser();
$response = $buzz->post($settings->getHeartbeatUrl(), array('Content-Type' => 'application/json'), json_encode(array('locale_ip' => $ip, 'printbox' => $settings->getPrintboxPid())));
if ($response->isSuccessful()) {
return $ip;
}
throw new \Exception('Heartbeat failed: ' . $settings->getHeartbeatUrl() . ' ' . $response->getStatusCode() . ' ' . $response->getContent());
}
开发者ID:sprain,项目名称:printbox,代码行数:25,代码来源:HeartbeatHandler.php
示例5: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
$headers = array('Connection' => 'close');
$content = array('private_key' => $this->privateKey, 'session_token' => $response, 'simple_mode' => 1);
$browser = new Browser();
$browser->getClient()->setVerifyPeer(false);
try {
/** @var Response $resp */
$resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to send captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
$answer = $resp->getContent();
if (!$answer) {
throw new CaptchaException('Error: Invalid captcha response');
}
$success = isset($answer) && filter_var($answer, FILTER_VALIDATE_INT);
if (!$success) {
return new CaptchaResponse($success, 'Invalid captcha');
}
return new CaptchaResponse($success);
}
开发者ID:iamraghavgupta,项目名称:paytoshi-faucet,代码行数:34,代码来源:FuncaptchaService.php
示例6: testYuml
/**
* @dataProvider fileProvider
*/
public function testYuml(BuilderInterface $builder, $fixture, $config)
{
$result = $builder->configure($config)->setPath($fixture)->build();
$this->assertInternalType('array', $result);
$this->assertGreaterThan(0, count($result));
$b = new Browser();
foreach ($result as $message) {
$url = explode(' ', $message);
$response = $b->get($url[1]);
$contentType = null;
switch ($url[0]) {
case '<info>PNG</info>':
$contentType = 'image/png';
break;
case '<info>PDF</info>':
$contentType = 'application/pdf';
break;
case '<info>URL</info>':
$contentType = 'text/html; charset=utf-8';
break;
case '<info>JSON</info>':
$contentType = 'application/json';
break;
case '<info>SVG</info>':
$contentType = 'image/svg+xml';
break;
}
$this->assertEquals($contentType, $response->getHeader('Content-Type'));
}
}
开发者ID:digitalkaoz,项目名称:yuml-php,代码行数:33,代码来源:YumlApiTest.php
示例7: listAction
/**
* @Route("/category/list", name="category_list")
* @Template()
*/
public function listAction()
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/all/category');
$categories = $this->get('jms_serializer')->deserialize($response->getContent(), 'Doctrine\\Common\\Collections\\ArrayCollection', 'json');
return array("categories" => $categories);
}
开发者ID:danielnunes,项目名称:projet-kali-front,代码行数:11,代码来源:CategoryController.php
示例8: sloganAction
/**
* @Route("/slogan", name="site_slogan")
* @Template()
*/
public function sloganAction()
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/parameters');
$paramater = $this->get('jms_serializer')->deserialize($response->getContent(), 'Kali\\Front\\SiteBundle\\Entity\\Parameter', 'json');
return array('slogan' => $paramater->getSlogan(), 'site' => $this->container->getParameter("back_site"));
}
开发者ID:danielnunes,项目名称:projet-kali-front,代码行数:11,代码来源:IndexController.php
示例9: send
/**
* Send request and generate response.
*
* @param Bool secure
*
* @throws UniversalAnalytics\Exception\InvalidRequestException
*
* @return Response
*/
public function send($secure = true)
{
$buzzBrowser = new Browser();
$buzzBrowser->setClient(new Curl());
$base = $secure ? $this->base_ssl : $this->base;
$buzzResponse = $buzzBrowser->submit($base, $this->attributes, RequestInterface::METHOD_POST, array());
return new Response($buzzResponse);
}
开发者ID:kapai69,项目名称:fl-ru-damp,代码行数:17,代码来源:Request.php
示例10: perform
public function perform($url)
{
$curl = new Curl();
$curl->setTimeout(30);
$curl->setProxy($this->proxy);
$browser = new Browser($curl);
return $this->serializer->decode($browser->post($url)->getContent(), 'xml');
}
开发者ID:meniam,项目名称:catalog-api,代码行数:8,代码来源:Request.php
示例11: it_can_search_with__query
public function it_can_search_with__query(Browser $client, Response $response)
{
$response->getContent()->shouldBeCalled();
$client->get(sprintf('%s/search?%s', 'http://endpoint', http_build_query(['q' => 'pilkington avenue, birmingham', 'format' => 'json'])), ['User-Agent' => 'Nomatim PHP Library (https://github.com/nixilla/nominatim-consumer); email: not set'])->shouldBeCalled()->willReturn($response);
$query = new Query();
$query->setQuery('pilkington avenue, birmingham');
$this->search($query)->shouldReturnAnInstanceOf('Nominatim\\Result\\Collection');
}
开发者ID:nixilla,项目名称:nominatim-consumer,代码行数:8,代码来源:ConsumerSpec.php
示例12: createBrowser
protected function createBrowser($user = null, $password = null)
{
$browser = new Buzz\Browser();
if ($user) {
$browser->addListener(new Buzz\Listener\BasicAuthListener($user, $password));
}
return $browser;
}
开发者ID:devster,项目名称:uauth,代码行数:8,代码来源:BasicTest.php
示例13: __construct
/**
* Mockable constructor.
* @param Browser $browser Buzz instance
* @param array $options
*/
public function __construct(Browser $browser, array $options)
{
if ($browser->getClient() instanceof FileGetContents) {
throw new \InvalidArgumentException('The FileGetContents client is known not to work with this library. Please instantiate the Browser with an instance of \\Buzz\\Client\\Curl');
}
$this->browser = $browser;
$this->options = $options;
}
开发者ID:JoeShiels1,项目名称:YouTrack,代码行数:13,代码来源:YouTrackCommunicator.php
示例14: getCrawler
protected function getCrawler()
{
if (null === $this->crawler) {
$client = new Browser();
$this->crawler = new Crawler($client->get($this->url)->getContent());
}
return $this->crawler;
}
开发者ID:redpanda,项目名称:php-imdb,代码行数:8,代码来源:MovieList.php
示例15: getDefaultAdapter
/**
* Configures the adapter for authentication against the RoboWhois API.
*/
protected function getDefaultAdapter()
{
$adapter = new Browser();
$client = new \Buzz\Client\Curl();
$client->setTimeout(5);
$adapter->setClient($client);
return $adapter;
}
开发者ID:robowhois,项目名称:robowhois-php,代码行数:11,代码来源:Client.php
示例16: it_returns_the_correct_historical_object_for_day_data
public function it_returns_the_correct_historical_object_for_day_data(Browser $browser)
{
$browser->get($this->baseUrl . '/V?d=3&f=j')->willReturn($this->createResponse($this->dayResponse));
$data = $this->getDataForDay(3);
$data->shouldHaveType('Wjzijderveld\\Youless\\Api\\Response\\History');
$data->getValuesInWatt()->shouldBeLike(array(90, 90, 70, 80, 100, 70, 90, 160, 270, 70, 90, 120, 120, 100, 80, 180, 140, 190, 110, 150, 160, 170, 160, 150));
$data->getMeasuredFrom()->shouldBeLike(new DateTime('2014-09-26T00:00:00'));
$data->getDeltaInSeconds()->shouldEqual(3600);
}
开发者ID:wjzijderveld,项目名称:youless-client,代码行数:9,代码来源:ClientSpec.php
示例17: execute
/**
* Executes a http request.
*
* @param Request $request The http request.
*
* @return Response The http response.
*/
public function execute(Request $request)
{
$method = $request->getMethod();
$endpoint = $request->getEndpoint();
$params = $request->getParams();
$headers = $request->getHeaders();
try {
if ($method === 'GET') {
$buzzResponse = $this->client->call($endpoint . '?' . http_build_query($params), $method, $headers, array());
} else {
$buzzRequest = new FormRequest();
$buzzRequest->fromUrl($endpoint);
$buzzRequest->setMethod($method);
$buzzRequest->setHeaders($headers);
foreach ($params as $key => $value) {
if ($value instanceof Image) {
$value = new FormUpload($value->getData());
}
$buzzRequest->setField($key, $value);
}
$buzzResponse = new BuzzResponse();
$this->client->send($buzzRequest, $buzzResponse);
}
} catch (RequestException $e) {
throw new Exception($e->getMessage());
}
return static::convertResponse($request, $buzzResponse);
}
开发者ID:hansott,项目名称:pinterest-php,代码行数:35,代码来源:BuzzClient.php
示例18: send
/**
* Sends the message via the GCM server.
*
* @param mixed $data
* @param array $registrationIds
* @param array $options
* @param string $payload_type
*
* @return bool
*/
public function send($data, array $registrationIds = array(), array $options = array(), $payload_type = 'data')
{
$this->responses = array();
if (!in_array($payload_type, ['data', 'notification'])) {
$payload_type = 'data';
}
$data = array_merge($options, array($payload_type => $data));
if (isset($options['to'])) {
$this->responses[] = $this->browser->post($this->apiUrl, $this->getHeaders(), json_encode($data));
} elseif (count($registrationIds) > 0) {
// Chunk number of registration ID's according to the maximum allowed by GCM
$chunks = array_chunk($registrationIds, $this->registrationIdMaxCount);
// Perform the calls (in parallel)
foreach ($chunks as $registrationIds) {
$data['registration_ids'] = $registrationIds;
$this->responses[] = $this->browser->post($this->apiUrl, $this->getHeaders(), json_encode($data));
}
}
$this->client->flush();
foreach ($this->responses as $response) {
$message = json_decode($response->getContent());
if ($message === null || $message->success == 0 || $message->failure > 0) {
return false;
}
}
return true;
}
开发者ID:faheem00,项目名称:Gcm,代码行数:37,代码来源:Client.php
示例19: getLatestResponseHeaders
/**
* {@inheritdoc}
*/
public function getLatestResponseHeaders()
{
if (null === ($response = $this->browser->getLastResponse())) {
return;
}
return ['reset' => (int) $response->getHeader('RateLimit-Reset'), 'remaining' => (int) $response->getHeader('RateLimit-Remaining'), 'limit' => (int) $response->getHeader('RateLimit-Limit')];
}
开发者ID:softr,项目名称:asaas-php-sdk,代码行数:10,代码来源:BuzzAdapter.php
示例20: getUserDetails
/**
* @param string $token
*
* @return ProviderMetadata
*/
public function getUserDetails($token)
{
try {
// Fetch user data
list($identifier, $secret) = explode('@', $token);
$tokenObject = new TokenCredentials();
$tokenObject->setIdentifier($identifier);
$tokenObject->setSecret($secret);
$url = 'https://api.bitbucket.org/2.0/user';
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$data = json_decode($response->getContent(), true);
if (empty($data) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
// Fetch email
$url = sprintf('https://api.bitbucket.org/1.0/users/%s/emails', $data['username']);
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$emails = json_decode($response->getContent(), true);
if (empty($emails) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
$emails = array_filter($emails, function ($emailData) {
return true === $emailData['primary'];
});
$data['email'] = empty($emails) ? '' : current($emails)['email'];
return new ProviderMetadata(['uid' => $data['uuid'], 'nickName' => $data['username'], 'realName' => $data['display_name'], 'email' => $data['email'], 'profilePicture' => $data['links']['avatar']['href'], 'homepage' => $data['links']['html']['href'], 'location' => $data['location']]);
} catch (\Exception $e) {
throw new \RuntimeException('cannot fetch account details', 0, $e);
}
}
开发者ID:Doanlmit,项目名称:pickleweb,代码行数:37,代码来源:BitbucketProvider.php
注:本文中的Buzz\Browser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论