Exemplo n.º 1
0
 /**
  * Send the request.
  */
 public function send()
 {
     // prepare client
     $curl = new Curl();
     $curl->setTimeout(10);
     $curl->send($this->request, $this->response);
     $this->sent = true;
 }
Exemplo n.º 2
0
 /**
  * resolve curl configuration
  * @return Curl
  */
 private function prepareCurl()
 {
     $curl = new Curl();
     $curl->setOption(CURLOPT_USERAGENT, 'Taiga-PHP-SDK');
     $curl->setVerifyPeer(false);
     $curl->setTimeout(200);
     return $curl;
 }
Exemplo n.º 3
0
 /**
  * resolve curl configuration
  * @return Curl
  */
 private function prepareCurl()
 {
     $curl = new Curl();
     $curl->setOption(CURLOPT_USERAGENT, 'HypeMailchimp');
     $curl->setVerifyPeer(false);
     $curl->setTimeout($this->config['timeout']);
     return $curl;
 }
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('http.client', function ($app) {
         $client = new Curl();
         $client->setTimeout(120);
         return new Browser($client);
     });
 }
Exemplo n.º 5
0
 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');
 }
Exemplo n.º 6
0
 /**
  * Client constructor.
  *
  * @param array $options
  */
 public function __construct(array $options = [])
 {
     $this->verifyArray($options, ['scheme', 'host', 'secret']);
     $this->options = array_replace_recursive(['timeout' => 30], $options);
     $client = new Curl();
     $client->setTimeout($this->options['timeout']);
     $this->browser = new Browser($client);
 }
 /**
  * @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;
 }
 private function createClientHttp()
 {
     $httpClient = new Curl();
     $httpClient->setVerifyPeer(true);
     $httpClient->setTimeout(10);
     $httpClient->setMaxRedirects(5);
     $httpClient->setIgnoreErrors(true);
     return $httpClient;
 }
Exemplo n.º 9
0
 /**
  * Initialise
  */
 protected function init()
 {
     $client = new Curl();
     $client->setVerifyPeer(false);
     $client->setOption(CURLOPT_USERPWD, $this->options['key'] . ':');
     if (isset($this->options['timeout'])) {
         $client->setTimeout($this->options['timeout']);
     }
     $this->browser = new Browser($client);
 }
Exemplo n.º 10
0
 public function __construct(Response $response, Request $request, Curl $client)
 {
     $this->response = $response;
     $request->setProtocolVersion(1.1);
     $request->addHeader('Content-Type: application/json');
     $this->request = $request;
     $client->setTimeout(5);
     $client->setIgnoreErrors(true);
     $this->client = $client;
 }
Exemplo n.º 11
0
 /**
  * Constructs the client.
  *
  * @param string $url The base URL for WebDriver server
  *
  * @param Buzz\Client\ClientInterface $client The client to use for
  * requesting the WebDriver server
  */
 public function __construct($url, ClientInterface $client = null)
 {
     if (null === $client) {
         $client = new Curl();
         $client->setTimeout(self::DEFAULT_TIMEOUT);
         $client->setMaxRedirects(0);
     }
     $this->url = $url;
     $this->client = $client;
     $this->browsers = array();
 }
Exemplo n.º 12
0
 public function __construct($token, $roomId)
 {
     if (empty($token) || empty($roomId)) {
         throw \Exception('token or room id not configure');
     }
     $this->roomId = $roomId;
     $curl = new Curl();
     $curl->setTimeout(15);
     $this->client = new Client(new OAuth2($token), new Browser($curl));
     $this->roomApi = new RoomAPI($this->client);
 }
Exemplo n.º 13
0
 /**
  * Class constructor.
  *
  * @param string $consumerKey
  * @param string $consumerSecret
  * @param string|null $accessToken
  * @param string|null $accessTokenSecret
  * @param string|null $apiUrl
  * @param string|null $proxy
  * @param int|null $timeout
  */
 public function __construct($consumerKey, $consumerSecret, $accessToken = null, $accessTokenSecret = null, $apiUrl = null, $proxy = null, $timeout = null)
 {
     $this->consumerKey = $consumerKey;
     $this->consumerSecret = $consumerSecret;
     $this->accessToken = $accessToken;
     $this->accessTokenSecret = $accessTokenSecret;
     $this->apiUrl = $apiUrl ?: self::BASE_URL . '/1.1/';
     $curl = new Curl();
     $curl->setTimeout($timeout);
     $curl->setProxy($proxy);
     $this->browser = new Browser($curl);
 }
Exemplo n.º 14
0
 /**
  * @param array $transformed
  *
  * @throws \AntiMattr\ETL\Exception\LoadException
  */
 public function load(array $transformed = [])
 {
     if (empty($transformed)) {
         throw new LoadException("Error - No data to load");
     }
     $messageFactory = $this->createMessageFactory();
     $dataContext = $this->task->getDataContext();
     $content = ['POST' => ["/action" => array_values($transformed)]];
     $resource = '/v2/batch';
     $request = $messageFactory->createRequest('POST', $resource, $this->host);
     $request->addHeader('Content-Type: application/json');
     $request->setContent(json_encode($content));
     $response = $messageFactory->createResponse();
     $options = [CURLOPT_USERPWD => sprintf("%s:%s", $this->apiKey, $this->apiSecret)];
     try {
         $this->buzz->send($request, $response, $options);
         $this->buzz->setTimeout($this->timeout);
     } catch (ClientException $e) {
         throw new LoadException($e->getMessage());
     }
     $dataContext->setLoadedCount(count($transformed));
 }
 protected function setUp()
 {
     $client = new Curl();
     $client->setTimeout(30);
     $this->browser = new Browser($client);
     $clientId = $this->getEnvironmentVariable('MICROSOFT_OAUTH_CLIENT_ID');
     $clientSecret = $this->getEnvironmentVariable('MICROSOFT_OAUTH_CLIENT_SECRET');
     $cache = new ArrayCache();
     $accessTokenCache = new AccessTokenCache($cache);
     $accessTokenProvider = new AccessTokenProvider($this->browser, $clientId, $clientSecret);
     $accessTokenProvider->setCache($accessTokenCache);
     $this->translator = new MicrosoftTranslator($this->browser, $accessTokenProvider);
 }
Exemplo n.º 16
0
 /**
  * Initializes context with parameters from behat.yml.
  *
  * @param array $parameters
  */
 public function __construct(array $parameters)
 {
     $this->parameters = $parameters;
     $curlBuzzClient = new Curl();
     $curlBuzzClient->setTimeout(30);
     $curlBuzzClient->setOption(CURLOPT_SSL_VERIFYHOST, 0);
     $curlBuzzClient->setOption(CURLOPT_SSL_VERIFYPEER, 0);
     $this->browser = new Browser($curlBuzzClient);
     $this->useContext('secure', new SecureContext());
     $this->useContext('activity', new ActivityContext());
     $this->useContext('group', new GroupContext());
     $this->useContext('poll', new PollContext());
 }
 public static function setUpBeforeClass()
 {
     if (false == isset($GLOBALS['AKAMAI_CLIENT_TOKEN'])) {
         throw new \PHPUnit_Framework_SkippedTestError('These tests require AKAMAI_CLIENT_TOKEN to be set in phpunit.xml');
     }
     if (false == isset($GLOBALS['AKAMAI_ACCESS_TOKEN'])) {
         throw new \PHPUnit_Framework_SkippedTestError('These tests require AKAMAI_ACCESS_TOKEN to be set in phpunit.xml');
     }
     if (false == isset($GLOBALS['AKAMAI_CLIENT_SECRET'])) {
         throw new \PHPUnit_Framework_SkippedTestError('These tests require AKAMAI_CLIENT_SECRET to be set in phpunit.xml');
     }
     if (false == isset($GLOBALS['AKAMAI_BASEURL'])) {
         throw new \PHPUnit_Framework_SkippedTestError('These tests require AKAMAI_BASEURL to be set in phpunit.xml');
     }
     $curl = new Curl();
     $curl->setTimeout(10);
     self::$client = new Client($curl, $GLOBALS['AKAMAI_CLIENT_TOKEN'], $GLOBALS['AKAMAI_CLIENT_SECRET'], $GLOBALS['AKAMAI_ACCESS_TOKEN'], $GLOBALS['AKAMAI_BASEURL']);
 }
Exemplo n.º 18
0
 /**
  * Returns flash converted to html5
  *
  * @param  string         $filename
  * @return boolean|string
  */
 public function convert($filename, $jsonOnly = false)
 {
     $content = file_get_contents($filename);
     if (false === $content) {
         return false;
     }
     $request = json_encode(array("apiVersion" => $this->apiVersion, "method" => "swiffy.convertToHtml", "params" => array("client" => $this->userAgent, "input" => $this->base64safe_encode($content))));
     $browser = new Browser();
     $client = new Curl();
     $client->setTimeout(self::TIMEOUT);
     $browser->setClient($client);
     $response = $browser->post($this->apiUrl, array("Content-Type" => "application/json"), $request);
     $response = json_decode($response->getContent(), true);
     if (array_key_exists("error", $response)) {
         return false;
     }
     $result = $this->base64safe_decode($response["result"]["response"]["output"]);
     if ($jsonOnly) {
         $result = $this->getJson($result);
     }
     return $result;
 }
Exemplo n.º 19
0
 /**
  * @param $id
  * @return mixed|null
  */
 public function getGroupByID($id)
 {
     $token = $this->getAccessToken();
     if ($token == "") {
         return null;
     }
     $client = new Curl();
     $req = new Request(Request::METHOD_GET, "/" . $this->tenant . "/groups?api-version=1.6", "https://graph.windows.net");
     $req->addHeader("authorization: Bearer " . $token);
     $res = new Response();
     $client->setTimeout(20000);
     $client->send($req, $res);
     if ($res->getStatusCode() < 299) {
         return json_decode($res->getContent());
     }
     if ($res->getStatusCode() == 401) {
         $this->refreshToken($this->token->getToken()->getUser());
         return $this->getGroupByID($id);
     }
     return null;
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     // First, check if it's an Azure User
     if (get_class($response->getResourceOwner()) != "HWI\\Bundle\\OAuthBundle\\OAuth\\ResourceOwner\\AzureResourceOwner") {
         throw new UnsupportedUserException("Can not load a user by " . get_class($response->getResourceOwner()) . ".");
     }
     // Check if this user exists
     $user = $this->userManager->findUserByEmail($response->getEmail());
     // Load groups ids
     $groups = $this->entityManager->createQueryBuilder()->select("azureRole.azureGid")->from("BdEMainBundle:AzureRole", 'azureRole')->getQuery()->getArrayResult();
     $request = ['groupIds' => []];
     foreach ($groups as $group) {
         $request['groupIds'][] = $group['azureGid'];
     }
     // Load groups for this user
     $client = new Curl();
     $client->setTimeout(20000);
     $client = new Browser($client);
     $uid = $response->getResponse()['oid'];
     $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/checkMemberGroups?api-version=1.6";
     $r = $client->post($uri, array("Authorization: Bearer " . $response->getAccessToken() . "", "Content-Type: application/json", "Accept: application/json"), json_encode($request));
     $r = json_decode($r->getContent());
     $groups = $r->value;
     $roleRepo = $this->entityManager->getRepository("BdEMainBundle:AzureRole");
     /** @var AzureRole[] $azureRoles */
     $azureRoles = $roleRepo->createQueryBuilder('azureRole')->where('azureRole.azureGid IN (?1)')->setParameter(1, $groups)->getQuery()->getResult();
     /** @var Role[] $roles */
     $roles = array();
     foreach ($azureRoles as $azureRole) {
         $roles = array_merge($roles, $azureRole->getRoles());
     }
     $roles = array_unique($roles);
     if (sizeof($roles) == 0) {
         // Try to get if it's a SuperAdmin
         $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/memberOf?api-version=1.6";
         $r = $client->get($uri, array("authorization: Bearer " . $response->getAccessToken()));
         $userRoles = json_decode($r->getContent());
         if (!property_exists($userRoles, 'value')) {
             throw new UsernameNotFoundException(sprintf("Impossible to log you !", $response->getRealName()));
         }
         $userRoles = $userRoles->value;
         foreach ($userRoles as $userRole) {
             if ($userRole->objectType == 'Role') {
                 if ($userRole->displayName == "Company Administrator" && strpos($response->getEmail(), $this->tenant) !== false) {
                     // We found an Admin !
                     $roles[] = new Role("ROLE_SUPER_ADMIN");
                     break;
                 }
             }
         }
         if (count($roles) == 0) {
             $this->flashBag->add("error", $response->getEmail() . " ne peut pas se connecter à cette application");
             throw new UsernameNotFoundException(sprintf("User '%s' has no power here!", $response->getRealName()));
         }
     }
     /** @var User $user */
     if ($user == null) {
         $user = $this->userManager->createUser();
     }
     $user->setRoles($roles);
     $user->setEmail($response->getEmail());
     $user->setEmailCanonical($response->getEmail());
     $user->setEnabled(true);
     $user->setUsername($response->getEmail());
     $user->setPlainPassword($response->getAccessToken());
     $user->setAzureAccessToken($response->getAccessToken());
     $user->setAzureRenewAccessToken($response->getRefreshToken());
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 21
0
    /**
     * Make request to postmark api
     *
     * @param string Path to post to
     * @param mixed $data
     */
    public function sendRequest($path, $data)
    {
        $url = sprintf(
            "%s://api.postmarkapp.com/%s",
            $this->ssl ? 'https' : 'http',
            $path
        );

        $curl = new Curl();
        $curl->setTimeout($this->timeout);

        $browser = new Browser($curl);
        $response = $browser->post($url, $this->httpHeaders, $data);

        return $response->getContent();
    }
Exemplo n.º 22
0
 protected function request($url, $data = array(), $method = 'POST', array $headers = array())
 {
     if ($data instanceof Form) {
         $data = $data->toArray();
     }
     $client = new Curl();
     $client->setTimeout(100);
     $client->setVerifyPeer(FALSE);
     $browser = new Browser($client);
     $response = $browser->submit($url, $data, $method, $headers);
     return $response->getContent();
 }
Exemplo n.º 23
0
 public function __construct()
 {
     $curl = new Curl();
     $curl->setTimeout(60);
     $this->browser = new Browser($curl);
 }
 /**
  * @param AntiMattr\Common\Address\AddressInterface $address
  *
  * @return AntiMattr\AddressVerifier\Event\VerificationEvent $event
  *
  * @throws AntiMattr\AddressVerifier\Exception\Connection\ConnectionException
  * @throws AntiMattr\AddressVerifier\Exception\Connection\TimeoutException
  * @throws AntiMattr\AddressVerifier\Exception\IntegrationException
  * @throws AntiMattr\AddressVerifier\Exception\Location\CorrectionException
  * @throws AntiMattr\AddressVerifier\Exception\Location\StreetAddressException     
  */
 public function verifyLocation(AddressInterface $address)
 {
     if (!($streetAddressLine1 = $address->getStreetAddressLine1())) {
         throw new IntegrationException('Verify address missing street address line 1');
     }
     if (!($locality = $address->getLocality())) {
         throw new IntegrationException('Verify address missing locality');
     }
     if (!($region = $address->getRegion())) {
         throw new IntegrationException('Verify address missing region');
     }
     if (!($postalCode = $address->getPostalCode())) {
         throw new IntegrationException('Verify address missing postal code');
     }
     $streetAddressLine2 = $address->getStreetAddressLine2() ?: '';
     $params = array('address[street]' => $streetAddressLine1, 'address[unit]' => $streetAddressLine2, 'address[city]' => $locality, 'address[state]' => $region, 'address[zip]' => $postalCode, 'apikey' => $this->apiKey);
     $query = http_build_query($params);
     $resource = sprintf("/addresses.json?%s", $query);
     $request = $this->messageFactory->createRequest('GET', $resource, 'https://bpi.briteverify.com');
     $response = $this->messageFactory->createResponse();
     $event = $this->eventFactory->createEvent($address);
     $this->buzz->setTimeout($this->timeout);
     $this->log($request);
     try {
         $this->buzz->send($request, $response);
         $this->log($response);
         $statusCode = $response->getStatusCode();
         if ($statusCode !== 200) {
             $message = $response->getReasonPhrase();
             throw new IntegrationException($message);
         }
         $content = json_decode($response->getContent());
         if ($content->status === 'invalid') {
             $message = $content->error;
             throw new StreetAddressException($message);
         }
         if ($content->corrected === true) {
             $newAddress = new GenericAddress();
             if (isset($content->street)) {
                 $newAddress->setStreetAddressLine1($content->street);
             }
             if (isset($content->unit)) {
                 $newAddress->setStreetAddressLine2($content->unit);
             }
             if (isset($content->city)) {
                 $newAddress->setLocality($content->city);
             }
             if (isset($content->state_code)) {
                 $newAddress->setRegion($content->state_code);
             }
             if (isset($content->zip)) {
                 $postalCode = isset($content->plus4) ? $content->zip . '-' . $content->plus4 : $content->zip;
                 $newAddress->setPostalCode($postalCode);
             }
             if (isset($content->country_code)) {
                 $newAddress->setCountry($content->country_code);
             }
             throw new CorrectionException($newAddress);
         }
     } catch (ClientException $e) {
         $subject = $e->getMessage();
         if (0 !== preg_match('/timed out/', $subject)) {
             throw new TimeoutException($subject);
         }
         throw new ConnectionException($subject);
     }
     return $event;
 }
Exemplo n.º 25
0
 /**
  * Resolve curl configuration.
  *
  * @return Curl
  */
 private function prepareCurl()
 {
     $curl = new Curl();
     $curl->setOption(CURLOPT_USERAGENT, 'B2BackblazeClient');
     $curl->setVerifyPeer(false);
     $curl->setTimeout($this->timeout);
     return $curl;
 }
Exemplo n.º 26
0
 public function __construct($accessToken = NULL)
 {
     $this->accessToken = $accessToken;
     $this->buzz = new Buzz();
     $this->buzz->setTimeout(15000);
 }
 public function connect(Application $app)
 {
     $this->setEntityManager($app['orm.em']);
     $controllers = $app['controllers_factory'];
     $controllers->get('/{user}/{item}/{redirectUrl}/{coupon}', function (Application $app, $user, $item, $redirectUrl, $coupon, Request $request) {
         //get user
         $user = $this->em->getRepository($this->getBuyerClass())->find($user);
         if (!$user) {
             throw new Exception("User not found", 1);
         }
         //get item
         $item = $this->em->getRepository($this->getItemClass())->find($item);
         if (!$item) {
             throw new Exception("Item not found", 1);
         }
         if ($coupon) {
             //get coupon
             $coupon = $this->em->getRepository($this->getCouponClass())->find($coupon);
             if (!$coupon) {
                 throw new Exception("Coupon not found", 1);
             }
         }
         //save a transaction to get the id to use in reference
         $className = $this->getTransactionClass();
         $transaction = new $className();
         $transaction->setBuyer($user);
         $transaction->setItem($item);
         $transaction->setCoupon($coupon);
         $transaction->setStatus(TransactionStatus::AWAITING);
         $this->em->persist($transaction);
         $this->em->flush();
         if (!$redirectUrl) {
             $redirectUrl = $item->getRedirectUrl();
         } else {
             $redirectUrl = base64_decode($redirectUrl);
         }
         $parameters = array('email' => $this->getEmail(), 'token' => $this->getToken(), 'redirectURL' => $redirectUrl, 'currency' => 'BRL', 'itemId1' => $item->getId(), 'itemDescription1' => $item->getName(), 'itemAmount1' => number_format($item->getValue(), 2, '.', ''), 'itemQuantity1' => '1', 'itemWeight1' => '0', 'reference' => $transaction->getId());
         if ($coupon) {
             $parameters['extraAmount'] = number_format(-1 * $coupon()->getValue(), 2);
         }
         $client = new Curl();
         $client->setTimeout(30);
         $browser = new Browser($client);
         $response = $browser->post($this->config[$this::CHECKOUT], array('Content-Type' => 'application/x-www-form-urlencoded; charset=ISO-8859-1'), http_build_query($parameters));
         try {
             $responseXML = new SimpleXMLElement($response->getContent());
         } catch (Exception $e) {
             if ($this->getLog()) {
                 $this->getLog()->addError($e->getMessage());
             }
             throw new Exception("Ocorreu um erro na conexão com o servidor do PagSeguro.", 1);
         }
         if (count($responseXML->xpath('/errors')) > 0) {
             if ($this->getLog()) {
                 $this->getLog()->addError($responseXML->asXml());
             }
             throw new Exception("Ocorreu um erro na conexão com o servidor do PagSeguro: " . $responseXML->asXml(), 1);
         }
         $code = $responseXML->code;
         return $app->redirect($this->config[$this::PAYMENT] . '?code=' . $code);
     })->value('redirectUrl', null)->value('coupon', null);
     /**
      * This URL will be called by PagSeguro to update the transaction
      */
     $controllers->post('/notification', function (Application $app, Request $request) {
         $code = $request->get('notificationCode');
         $type = $request->get('notificationType');
         if ($code && $type == 'transaction') {
             $client = new Curl();
             $client->setTimeout(30);
             $browser = new Browser($client);
             $url = $this->config[$this::NOTIFICATION] . $code;
             $url .= strpos($url, '?') === false ? '?' : '&';
             $response = $browser->get($url . 'email=' . $this->getEmail() . '&token=' . $this->getToken());
             $xmlContent = $response->getContent();
             $responseXML = new SimpleXMLElement($xmlContent);
             $array = array($responseXML);
             $reference = $array[0]->reference;
             if (!$reference) {
                 throw new Exception("Invalid response", 1);
             }
             $description = $array[0]->items->item->description;
             if (!$description) {
                 throw new Exception("Invalid response", 1);
             }
             $transaction = $this->em->getRepository($this->getTransactionClass())->find($reference);
             if ($transaction) {
                 $transactionCode = $array[0]->code;
                 $transaction->setCode($transactionCode);
                 $transactionStatus = $array[0]->status;
                 $transaction->setStatus($transactionStatus);
                 $this->em->persist($transaction);
                 $this->em->flush();
             }
         }
         return new Response('OK', 200);
     });
     return $controllers;
 }
Exemplo n.º 28
0
 /**
  * @return ClientInterface
  */
 protected function createClient()
 {
     $curl = new Curl();
     $curl->setTimeout(300);
     return $curl;
 }
Exemplo n.º 29
0
 /**
  * Make an API request.
  *
  * @param  \Tev\Bs\Contracts\EndpointInterface $endpoint Requesting endpoint
  * @return \Tev\Bs\Contracts\ResponseInterface           Response
  *
  * @throws \Exception
  * @throws \Tev\Bs\Exception\ErrorResponseException
  */
 public function request(EndpointInterface $endpoint)
 {
     if ($this->customerId !== null) {
         $endpoint->setParam('customer_id', $this->customerId);
     }
     // Request
     $request = new Request($endpoint->getMethod(), $endpoint->getUrl(), $this->host);
     $request->setContent($endpoint->getContent());
     // Response
     $response = new Response();
     // Authorisation
     $listener = new BasicAuthListener($this->clientId, $this->clientSecret);
     $listener->preSend($request);
     // Send
     $client = new Curl();
     $client->setTimeout(30);
     $client->send($request, $response);
     // Parse
     $parser = new Parser($response, $endpoint);
     return $parser->getResponse();
 }