-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kiril Kirkov
authored and
Kiril Kirkov
committed
Nov 24, 2024
0 parents
commit 739f212
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "tigerra/convert", | ||
"description": "High-Performance File Conversion API for Developers & Businesses.", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"Tigerra\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Tigerra" | ||
} | ||
], | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Tigerra; | ||
|
||
class BaseApiClient | ||
{ | ||
protected $apiUrl = "https://convert.tigerra.com"; | ||
protected $authToken; | ||
|
||
public function __construct($authToken) | ||
{ | ||
$this->authToken = $authToken; | ||
} | ||
|
||
protected function sendRequest($method, $endpoint, $params = [], $filePath = null) | ||
{ | ||
$url = $this->apiUrl . $endpoint; | ||
$headers = [ | ||
"Authorization: Bearer {$this->authToken}" | ||
]; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
|
||
if ($method === 'POST' && $filePath) { | ||
$file = new \CURLFile($filePath); | ||
$params['file'] = $file; | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); | ||
} | ||
|
||
$response = curl_exec($ch); | ||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
curl_close($ch); | ||
|
||
if ($httpCode >= 400) { | ||
throw new \Exception("HTTP Error: {$httpCode} - Response: {$response}"); | ||
} | ||
|
||
return json_decode($response, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Tigerra; | ||
|
||
class ConversionStatusChecker extends BaseApiClient | ||
{ | ||
public function checkStatus($pid) | ||
{ | ||
$endpoint = "/get-status/{$pid}"; | ||
return $this->sendRequest('GET', $endpoint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Tigerra; | ||
|
||
class Converter extends BaseApiClient | ||
{ | ||
public function convert($conversionType, $filePath) | ||
{ | ||
$endpoint = "/do-convert/{$conversionType}"; | ||
return $this->sendRequest('POST', $endpoint, [], $filePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Tigerra; | ||
|
||
|
||
class ConverterFileDownloader extends BaseApiClient | ||
{ | ||
public function downloadFile($downloadUrl, $outputPath) | ||
{ | ||
$ch = curl_init($downloadUrl); | ||
$headers = [ | ||
"Authorization: Bearer {$this->authToken}" | ||
]; | ||
|
||
$file = fopen($outputPath, 'w'); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
curl_setopt($ch, CURLOPT_FILE, $file); | ||
|
||
$success = curl_exec($ch); | ||
curl_close($ch); | ||
fclose($file); | ||
|
||
if (!$success) { | ||
throw new \Exception("Failed to download file."); | ||
} | ||
|
||
return $outputPath; | ||
} | ||
} |