/**
  * Get Country User
  *
  * @param EventObserver $observer
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->_customerSession->getLocated()) {
         //$clientIP = $this->_request->getClientIp();
         /*
          * Set static Ip to test
          *
          * DE : 194.55.30.46
          * VN : 123.30.215.27
          * PL : 212.77.98.9
          * SG : 202.157.143.72
          *
          **/
         $clientIP = '123.30.215.27';
         $uri = 'http://freegeoip.net/json/' . $clientIP;
         $httpClient = new \Zend\Http\Client();
         $httpClient->setUri($uri);
         $httpClient->setOptions(array('timeout' => 30));
         try {
             $response = \Zend\Json\Decoder::decode($httpClient->send()->getBody());
             $this->_customerSession->setLocationData($response);
             $this->_customerSession->setLocated(true);
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
 }
Example #2
0
 public function __construct($apiKey)
 {
     $this->setApiKey($apiKey);
     $client = new \Zend\Http\Client();
     $client->setOptions(array('strictredirects' => true, 'adapter' => 'Zend\\Http\\Client\\Adapter\\Curl'));
     $this->setHttpClient($client);
 }
 /**
  * Returns request handler
  *
  * @return \Zend\Http\Client
  */
 public function getRequestHandler()
 {
     if (!isset($this->requestHandler)) {
         $requestHandler = new \Zend\Http\Client();
         $requestHandler->setOptions(array('timeout' => 60));
         $this->setRequestHandler($requestHandler);
     }
     return $this->requestHandler;
 }
Example #4
0
 /**
  * @param IL10N $l10n
  * @param IConfig $config
  * @param IClientService $clientService
  */
 public function __construct(IL10N $l10n, IConfig $config, IClientService $clientService)
 {
     parent::__construct($l10n, $config, $clientService);
     $this->scriptLocation = __DIR__ . '/../../scripts/pagekite/pagekite.py';
     // TODO: DI
     $this->xmlRpcClient = new \Zend\XmlRpc\Client($this->rpcUrl);
     $client = new \Zend\Http\Client();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Proxy');
     $client->setOptions(['sslcafile' => \OC::$SERVERROOT . '/config/ca-bundle.crt']);
     $this->xmlRpcClient->setHttpClient($client);
 }
 /**
  * @param Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $clientIP = "115.78.167.37";
     //		$clientIP = $this->_request->getClientIp();
     $httpClient = new \Zend\Http\Client();
     $uri = 'http://freegeoip.net/json/' . $clientIP;
     $httpClient->setUri($uri);
     $httpClient->setOptions(array('timeout' => 30));
     try {
         $response = \Zend\Json\Decoder::decode($httpClient->send()->getBody());
         $this->_customerSession->setLocationData($response);
         $this->_customerSession->setLocated(true);
     } catch (\Exception $e) {
         $this->_logger->critical($e);
     }
     return $this;
 }
Example #6
0
 /**
  * Return a new HTTP client.
  *
  * @param string $url     Target URL
  * @param string $method  Request method
  * @param float  $timeout Request timeout in seconds
  *
  * @return \Zend\Http\Client
  */
 public function createClient($url = null, $method = \Zend\Http\Request::METHOD_GET, $timeout = null)
 {
     $client = new \Zend\Http\Client();
     $client->setMethod($method);
     if (!empty($this->defaults)) {
         $client->setOptions($this->defaults);
     }
     if (null !== $this->defaultAdapter) {
         $client->setAdapter($this->defaultAdapter);
     }
     if (null !== $url) {
         $client->setUri($url);
     }
     if ($timeout) {
         $client->setOptions(array('timeout' => $timeout));
     }
     $this->proxify($client);
     return $client;
 }
Example #7
0
/**
 * 构造POST和GET组合的请求 返回相应请求
 *
 * @param string $url            
 * @param array $get            
 * @param array $post            
 * @param boolean $returnObj            
 * @return Zend_Http_Response false
 */
function doRequest($url, $get = array(), $post = array(), $returnObj = false)
{
    try {
        $url = trim($url);
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            throw new Exception('Invalid URL');
            return false;
        }
        $client = new Zend\Http\Client();
        $client->setUri($url);
        if (count($get) > 0 && is_array($get)) {
            $client->setParameterGet($get);
        }
        if (count($post) > 0 && is_array($post)) {
            $client->setParameterPost($post);
        }
        $client->setEncType(Zend\Http\Client::ENC_URLENCODED);
        $client->setOptions(array('maxredirects' => 5, 'strictredirects' => false, 'useragent' => 'Zend\\Http\\Client', 'timeout' => 10, 'adapter' => 'Zend\\Http\\Client\\Adapter\\Socket', 'httpversion' => Request::VERSION_11, 'storeresponse' => true, 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, 'argseparator' => null, 'rfc3986strict' => false));
        if (!empty($post)) {
            $client->setMethod(Request::METHOD_POST);
        } else {
            $client->setMethod(Request::METHOD_GET);
        }
        $response = $client->send();
        return $returnObj ? $response : $response->getBody();
    } catch (Exception $e) {
        fb(exceptionMsg($e), \FirePHP::LOG);
        return false;
    }
}
if (!(isset($autoloader) && $autoloader)) {
    file_put_contents('php://stderr', "Failed to discover autoloader; please install dependencies and/or install via Composer.\n");
    exit(1);
}
// Get configuration
$config = getConfig();
$token = $config['token'];
// Github API token
$user = $config['user'];
// Your user or organization
$repo = $config['repo'];
// The repository you're getting the changelog for
$milestone = $config['milestone'];
// The milestone ID
$client = new Zend\Http\Client();
$client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl'));
$request = $client->getRequest();
$headers = $request->getHeaders();
$headers->addHeaderLine("Authorization", "token {$token}");
$client->setUri("https://api.github.com/repos/{$user}/{$repo}/milestones/{$milestone}");
$milestoneResponseBody = $client->send()->getBody();
$milestonePayload = json_decode($milestoneResponseBody, true);
if (!isset($milestonePayload['title'])) {
    file_put_contents('php://stderr', sprintf("Provided milestone ID [%s] does not exist: %s\n", $milestone, $milestoneResponseBody));
}
$client->setUri('https://api.github.com/search/issues?q=' . urlencode('milestone:' . $milestonePayload['title'] . ' repo:' . $user . '/' . $repo . ' state:closed'));
$client->setMethod('GET');
$issues = array();
$error = false;
do {
    $response = $client->send();