Esempio n. 1
0
 /**
  * Register the necessary callbacks
  *
  * @since 1.6
  * @see curl_before_send
  * @see fsockopen_remote_socket
  * @see fsockopen_remote_host_path
  * @see fsockopen_header
  * @param Requests_Hooks $hooks Hook system
  */
 public function register(Requests_Hooks &$hooks)
 {
     $hooks->register('curl.before_send', array(&$this, 'curl_before_send'));
     $hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket'));
     $hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path'));
     if ($this->use_authentication) {
         $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
     }
 }
Esempio n. 2
0
 /**
  * Get the Zip File from Server & return back the downloaded file location
  */
 public static function zipFile($url, $zipFile)
 {
     if (!extension_loaded('zip')) {
         self::log("Dependency Missing, Please install PHP Zip Extension");
         echo ser("PHP Zip Extension", "I can't find the Zip PHP Extension. Please Install It & Try again");
     }
     self::log("Started Downloading Zip File from {$url} to {$zipFile}");
     $userAgent = 'LobbyBot/0.1 (' . L_SERVER . ')';
     /**
      * Get The Zip From Server
      */
     $hooks = new \Requests_Hooks();
     if (self::$progress != null) {
         $progress = self::$progress;
         $hooks->register('curl.before_send', function ($ch) use($progress) {
             curl_setopt($ch, CURLOPT_NOPROGRESS, false);
             curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $progress);
         });
     }
     try {
         \Requests::get($url, array("User-Agent" => $userAgent), array('filename' => $zipFile, 'hooks' => $hooks, 'timeout' => time()));
     } catch (\Requests_Exception $error) {
         self::log("HTTP Requests Error ({$url}) : {$error}");
         echo ser("Error", "HTTP Requests Error : " . $error);
         return false;
     }
     self::log("Downloaded Zip File from {$url} to {$zipFile}");
     return $zipFile;
 }
Esempio n. 3
0
 public function register(\Requests_Hooks &$hooks)
 {
     $hooks->register('requests.before_request', array(&$this, 'before_request'));
 }
Esempio n. 4
0
 /**
  * Register the necessary callbacks
  *
  * @see curl_before_send
  * @see fsockopen_header
  * @param Requests_Hooks $hooks Hook system
  */
 public function register(Requests_Hooks &$hooks)
 {
     $hooks->register('curl.before_send', array(&$this, 'curl_before_send'));
     $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
 }
Esempio n. 5
0
 public function testProgressCallback()
 {
     $mock = $this->getMockBuilder('stdClass')->setMethods(array('progress'))->getMock();
     $mock->expects($this->atLeastOnce())->method('progress');
     $hooks = new Requests_Hooks();
     $hooks->register('request.progress', array($mock, 'progress'));
     $options = array('hooks' => $hooks);
     $options = $this->getOptions($options);
     $response = Requests::get(httpbin('/get'), array(), $options);
 }
Esempio n. 6
0
    /**
     * POST a file to VWflow's items-hmac endpoint.
     *
     * If the request is valid, a new item will be created.
     *
     * @param string $local_path Local path to the file that needs to be uploaded.
     * @param string $account_id ID of your VWflow account.
     * @param string $wprofile_id ID of your VWflow workflow profile.
     * @param string $auth_secret Shared secret attached to your workflow profile.
     * @param int $hmac_valid_seconds Number of seconds during which the HMAC will be considered as valid by VWflow (default = 30).
     * @param string $client_data Client specific data in JSON format (should be valid json, use json_encode() to generate it !!),
     *          which can be retrieved later as part of a notification or as the result of polling the job resource (optional).
     * @return JSON object containing the URL(s) required to retrieve the item's data through the VWflow items API, or containing an error
     */
    function createItemWithHmacAuth($local_path, $account_id, $wprofile_id, $auth_secret, $hmac_valid_seconds = 30, $client_data = "")
    {
        $a_item = array("src" => "@{$local_path}");
        $url = $this->uri . "items-hmac/{$account_id}/{$wprofile_id}/";
        $msg_data = uniqid(rand(), true);
        # generate unique id
        date_default_timezone_set('Europe/Brussels');
        $msg_timestamp = time() + $hmac_valid_seconds;
        # requests using this page will be valid during three hours
        $vwflow_hmac = md5($auth_secret . $msg_timestamp . $msg_data);
        $vwflow_info = <<<EOT
{"msg_data":"{$msg_data}","msg_timestamp":"{$msg_timestamp}","client_data":"{$client_data}"}
EOT;
        $headers = array('Content-Type' => 'multipart/form-data', 'x-vwflow-info' => $vwflow_info, "x-vwflow-hmac" => $vwflow_hmac);
        $hooks = new Requests_Hooks();
        $hooks->register('curl.before_send', function ($fp, $data = array()) use($a_item) {
            curl_setopt($fp, CURLOPT_POSTFIELDS, $a_item);
            curl_setopt($fp, CURLOPT_TIMEOUT, $this->upload_timeout);
        });
        $options = $this->request_options;
        $options['hooks'] = $hooks;
        $response = Requests::post($url, $headers, array(), $options);
        $this->_checkErrorResponse($response);
        return json_decode($response->body);
    }
Esempio n. 7
0
 protected function _startDownloads()
 {
     $this->log('start downloads');
     $hooks = new \Requests_Hooks();
     $hooks->register('curl.before_send', array($this, 'setCurlCallbackFunction'));
     foreach ($this->_downloadList as $id => $url) {
         $this->log('download %s', $url);
         $targetFile = $this->_getTargetFilePath($id, $url);
         $options = array('filename' => $targetFile, 'hooks' => $hooks, 'timeout' => pow(2, 64));
         $this->_currentDownloadId = $id;
         \Requests::get($url, array(), $options);
         $this->log('finished downloading %s', $url);
     }
     $this->log('finished all downloading going to die now');
 }
Esempio n. 8
0
 public function testAfterRequestCallback()
 {
     $mock = $this->getMockBuilder('stdClass')->setMethods(array('after_request'))->getMock();
     $mock->expects($this->atLeastOnce())->method('after_request')->with($this->isType('string'), $this->logicalAnd($this->isType('array'), $this->logicalNot($this->isEmpty())));
     $hooks = new Requests_Hooks();
     $hooks->register('curl.after_request', array($mock, 'after_request'));
     $hooks->register('fsockopen.after_request', array($mock, 'after_request'));
     $options = array('hooks' => $hooks);
     $options = $this->getOptions($options);
     $response = Requests::get(httpbin('/get'), array(), $options);
 }
 /**
  * @param \Requests_Hooks $hooks
  */
 public function register(\Requests_Hooks &$hooks)
 {
     $hooks->register('requests.before_request', [&$this, 'before_request']);
     $hooks->register('requests.after_request', [&$this, 'after_request']);
 }
Esempio n. 10
0
 public function register(Requests_Hooks &$hooks)
 {
     $hooks->register('requests.before_request', array($this, 'add_headers'), 1000);
 }