Exemplo n.º 1
0
 public function test_fetchRemoteFile()
 {
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     $methods = array('curl', 'fopen', 'socket');
     $this->assertTrue(in_array(Piwik_Http::getTransportMethod(), $methods));
     foreach ($methods as $method) {
         $version = '';
         try {
             $version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5);
         } catch (Exception $e) {
             var_dump($e->getMessage());
         }
         $this->assertTrue(preg_match('/^([0-9.]+)$/', $version), $method);
     }
     $destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST';
     try {
         Piwik_Http::fetchRemoteFile('http://api.piwik.org/1.0/getLatestVersion/', $destinationPath, 3);
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
     $this->assertTrue(filesize($destinationPath) > 0);
     $destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip';
     try {
         Piwik_Http::fetchRemoteFile('http://piwik.org/latest.zip', $destinationPath, 3);
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
     $this->assertTrue(filesize($destinationPath) > 0);
 }
Exemplo n.º 2
0
 private function issueApiCall($apiKey, $resource, $additionalParameters = array())
 {
     $accountParameters = array('Key' => $apiKey);
     $parameters = array_merge($accountParameters, $additionalParameters);
     $url = self::BASE_API_URL . $resource . '?' . http_build_query($parameters, '', '&');
     $timeout = self::SOCKET_TIMEOUT;
     $result = Piwik_Http::sendHttpRequestBy(Piwik_Http::getTransportMethod(), $url, $timeout, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = true);
     if (strpos($result, self::ERROR_STRING) !== false) {
         throw new Piwik_MobileMessaging_APIException('Clockwork API returned the following error message : ' . $result);
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Issues a request to $url
  */
 protected function request($url)
 {
     $url = $this->piwikUrl . $url . $this->requestPrepend;
     //$this->log($url);
     try {
         $response = Piwik_Http::sendHttpRequestBy('curl', $url, $timeout = 300, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSSLCertificate = $this->acceptInvalidSSLCertificate);
     } catch (Exception $e) {
         return $this->logNetworkError($url, $e->getMessage());
     }
     if ($this->checkResponse($response, $url)) {
         return $response;
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * @group Core
  * @group Http
  * @dataProvider getMethodsToTest
  */
 public function testFetchRemoteFile($method)
 {
     $this->assertNotNull(Piwik_Http::getTransportMethod());
     $version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5);
     $this->assertTrue((bool) preg_match('/^([0-9.]+)$/', $version));
 }