Skip to content

Commit

Permalink
add version, clean
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Mar 29, 2017
1 parent 7a9ea1b commit 4332f34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ private function setFilename($filename, $filenameNew){
$fileInfoNew = pathinfo($filenameNew);

if($fileInfo['extension']!=$fileInfoNew['extension']){
var_dump($fileInfo);
var_dump($fileInfoNew);
throw new \InvalidArgumentException('Invalid file extension');
}
return $filenameNew;
Expand Down
4 changes: 1 addition & 3 deletions src/Ilovepdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Ilovepdf
// @var string|null Disable Exceptions if needed.
public static $exceptions = true;

const VERSION = '0.0.1';
const VERSION = 'php.1.0.5';

public $token = null;

Expand Down Expand Up @@ -169,8 +169,6 @@ public function sendRequest($method, $endpoint, $body=null)
), $body);
if ($response->code != '200' && $response->code != '201') {
if ($response->code == 401) {
var_dump($to_server);
var_dump($response);
throw new AuthException($response->body->error->message, $response->code, null, $response);
}
elseif ($response->code == 401) {
Expand Down
20 changes: 10 additions & 10 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Task extends Ilovepdf
const STATUS_DELETED = 'TaskDeleted';
const STATUS_NOTFOUND = 'TaskNotFound';


/**
* Task constructor.
* @param null $publicKey
Expand All @@ -38,8 +37,9 @@ class Task extends Ilovepdf
function __construct($publicKey, $secretKey)
{
parent::__construct($publicKey, $secretKey);

$response = parent::sendRequest('get', 'start/' . $this->tool, null);
$data = array('v'=> self::VERSION);
$body = Request\Body::Form($data);
$response = parent::sendRequest('get', 'start/' . $this->tool, $body);
if (empty($response->body->server)) {
throw new StartException('no server assigned on start');
};
Expand Down Expand Up @@ -109,7 +109,7 @@ public function addFileFromUrl($url)
*/
public function uploadFile($task, $filepath)
{
$data = array('task' => $task);
$data = array('task' => $task, 'v'=> self::VERSION);
$files = array('file' => $filepath);
$body = Request\Body::multipart($data, $files);

Expand Down Expand Up @@ -138,7 +138,7 @@ public function delete()
*/
public function uploadUrl($task, $url)
{
$data = array('task' => $task, 'cloud_file' => $url);
$data = array('task' => $task, 'cloud_file' => $url, 'v'=> self::VERSION);
$body = Request\Body::Form($data);
$response = parent::sendRequest('post', 'upload', $body);
return new File($response->body->server_filename, basename($url));
Expand All @@ -165,8 +165,9 @@ public function download($path = null, $file = null)
*/
public function downloadFile($task, $path = null)
{
$response = parent::sendRequest('get', 'download/' . $task, null);

$data = array('v'=> self::VERSION);
$body = Request\Body::Form($data);
$response = parent::sendRequest('get', 'download/' . $task, $body);

if(preg_match("/filename\*\=utf-8\'\'([\W\w]+)/", $response->headers['Content-Disposition'], $matchesUtf)){
$filename = urldecode(str_replace('"', '', $matchesUtf[1]));
Expand Down Expand Up @@ -199,7 +200,6 @@ public function getEncrypted($value)
return self::$encrypted;
}


/**
* @return mixed
* @throws Exceptions\AuthException
Expand All @@ -214,7 +214,7 @@ public function execute()

$data = array_merge(
get_object_vars($this),
array('task' => $this->task, 'files' => $this->files));
array('task' => $this->task, 'files' => $this->files, 'v'=> self::VERSION));
$body = Request\Body::multipart($data);

$response = parent::sendRequest('post', 'process', urldecode(http_build_query($body)));
Expand Down Expand Up @@ -256,7 +256,7 @@ public function ignorePassword($value)

public function deleteFile($file){
if (($key = array_search($file, $this->files)) !== false) {
$body = Request\Body::multipart(['task'=>$this->getTaskId(), 'server_filename'=>$file->server_filename]);
$body = Request\Body::multipart(['task'=>$this->getTaskId(), 'server_filename'=>$file->server_filename, 'v'=> self::VERSION]);
$this->sendRequest('post', 'upload/delete', $body);
unset($this->files[$key]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Class Ilovepdf
*
* @todo Add params as needed, beacuse we don't want this class extends Task. Currently not used
* @todo Add params as needed, because we don't want this class extends Task. Currently not used
*
* @package Ilovepdf
*/
Expand Down

0 comments on commit 4332f34

Please sign in to comment.