Skip to content

Commit fd5e6e2

Browse files
committed
Added file or URL support
1 parent 3750783 commit fd5e6e2

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/API.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
class API
66
{
7-
public static function createTask($type, $file_id, $options = [])
7+
public static function createTask($type, $options = [])
88
{
99
$data = [
1010
'type' => $type,
11-
'options' => array_merge(['file_id' => $file_id], $options)
11+
'options' => $options,
1212
];
1313
$result = Request::requestAPI('POST', ConversionClient::$baseUrl . '/tasks', json_encode($data));
1414
$json = json_decode($result, true);

src/ConversionClient.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
class ConversionClient
66
{
7-
const VERSION = '1.0.0';
7+
const VERSION = '1.0.1';
88

99
public static $userAgent = 'conversiontools-php';
10-
10+
1111
public static $baseUrl = 'https://api.conversiontools.io/v1';
1212

1313
public static $DEBUG = FALSE;
@@ -29,11 +29,19 @@ public static function getUserAgent()
2929
return self::$userAgent . '/' . self::VERSION;
3030
}
3131

32-
public function convert($type, $fileInput, $fileOutput, $options = NULL)
32+
public function convert($type, $fileOrUrlInput, $fileOutput, $options = [])
3333
{
34-
$file_id = API::uploadFile($fileInput);
35-
$task_id = API::createTask($type, $file_id, $options);
36-
while (TRUE) {
34+
if (isset($fileOrUrlInput)) {
35+
if (is_file($fileOrUrlInput)) {
36+
$file_id = API::uploadFile($fileOrUrlInput);
37+
$options = array_merge($options, ['file_id' => $file_id]);
38+
}
39+
if (parse_url($fileOrUrlInput)) {
40+
$options = array_merge($options, ['url' => $fileOrUrlInput]);
41+
}
42+
}
43+
$task_id = API::createTask($type, $options);
44+
while (isset($task_id)) {
3745
list($status, $file_id_result) = API::getTaskStatus($task_id);
3846
switch ($status) {
3947
case 'SUCCESS':

0 commit comments

Comments
 (0)