Skip to content

Commit

Permalink
better remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Nov 16, 2017
1 parent 1852bb4 commit a33cd6d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
16 changes: 10 additions & 6 deletions samples/get_remaining_files.php
Expand Up @@ -9,14 +9,18 @@

// you can call task class directly
// to get your key pair, please visit https://developer.ilovepdf.com/user/projects
$ilovepdf = new Task('project_public_id', 'project_secret_key');
$ilovepdf = new Ilovepdf('project_public_id', 'project_secret_key');


//start the task
$myTask = $ilovepdf->newTask('merge');

//get remaining files
$remainingFiles = $myTask->getRemainingFiles();
$remainingFiles = $ilovepdf->getRemainingFiles();


//print your remaining files
echo $remainingFiles;
echo $remainingFiles;

//only start new process if you have enough files
if($remainingFiles>0) {
//start the task
$myTask = $ilovepdf->newTask('merge');
}
33 changes: 32 additions & 1 deletion src/Ilovepdf.php
Expand Up @@ -9,6 +9,7 @@
use Ilovepdf\Exceptions\StartException;
use Ilovepdf\Exceptions\AuthException;
use Ilovepdf\IlovepdfTool;
use Ilovepdf\Request\Body;

/**
* Class Ilovepdf
Expand All @@ -31,7 +32,7 @@ class Ilovepdf
// @var string|null The version of the Ilovepdf API to use for requests.
public static $apiVersion = 'v1';

const VERSION = 'php.1.1.7';
const VERSION = 'php.1.1.8';

public $token = null;

Expand All @@ -48,6 +49,8 @@ class Ilovepdf
public $timeout = 10;
public $timeoutLarge = null;

public $info = null;


public function __construct($publicKey = null, $secretKey = null)
{
Expand Down Expand Up @@ -312,4 +315,32 @@ public function verifySsl($verify){
Request::verifyPeer($verify);
Request::verifyHost($verify);
}

private function getUpdatedInfo(){
$data = array('v' => self::VERSION);
$body = Body::Form($data);
$response = self::sendRequest('get', 'info', $body);
$this->info = $response->body;
return $this->info;
}



/**
* @return object
*/
public function getInfo()
{
$info = $this->getUpdatedInfo();
return $info;
}

/**
* @return integer
*/
public function getRemainingFiles()
{
$info = $this->getUpdatedInfo();
return $info->remaining_files;
}
}
37 changes: 0 additions & 37 deletions src/Task.php
Expand Up @@ -52,7 +52,6 @@ class Task extends Ilovepdf
public $outputFileName;
public $outputFileType;

public $info = null;

/**
* Task constructor.
Expand Down Expand Up @@ -520,40 +519,4 @@ public function setWebhook($webhook)
$this->webhook = $webhook;
return $this;
}

private function getUpdatedInfo(){
$data = array('v' => self::VERSION);
$body = Body::Form($data);
$response = parent::sendRequest('get', 'info', $body);
$this->info = $response->body;
return $this->info;
}



/**
* @return object
*/
public function getInfo()
{
$info = $this->getUpdatedInfo();
return $info;
}

/**
* @return integer
*/
public function getRemainingFiles()
{
$info = $this->getUpdatedInfo();
return $info->remaining_files;
}

/**
* @param null $remainingFiles
*/
private function setRemainingFiles($remainingFiles)
{
$this->remainingFiles = $remainingFiles;
}
}

0 comments on commit a33cd6d

Please sign in to comment.