From 8699697635d0913100ccd294fc900ea771f82fd6 Mon Sep 17 00:00:00 2001 From: laurynas-baltsoft <38224044+laurynas-baltsoft@users.noreply.github.com> Date: Sat, 6 Feb 2021 19:02:22 +0200 Subject: [PATCH 01/10] Adjust variable name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb6b24c..5e3674e 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ $result = ConvertApi::convert('pdf', ['File' => '/path/to/my_file.docx']); $result->getFile()->save('/path/to/save/file.pdf'); # get file contents (without saving the file locally) -$content = $result->getFile()->getContents(); +$contents = $result->getFile()->getContents(); ``` Other result operations: From d173f6d5c25e3097008a80f933fb6a23e1ea341c Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Mon, 30 Aug 2021 23:24:04 +0300 Subject: [PATCH 02/10] Add error handling example --- examples/error_handling.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/error_handling.php diff --git a/examples/error_handling.php b/examples/error_handling.php new file mode 100644 index 0000000..1cbda86 --- /dev/null +++ b/examples/error_handling.php @@ -0,0 +1,15 @@ + 'files/test.docx', 'converter' => 'DUMMY']); +} catch (\ConvertApi\Error\Api $error) { + echo "Got API error code: " . $error->getCode() . "\n"; + echo $error->getMessage(); +} + From 9ce25230963846694bfbf755890ca94de6b0d895 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 31 Mar 2022 15:48:38 +0200 Subject: [PATCH 03/10] :sparkles: add get + set for apiBase --- lib/ConvertApi/ConvertApi.php | 18 ++++++++++++++++++ tests/ConvertApi/ConvertApiTest.php | 3 +++ 2 files changed, 21 insertions(+) diff --git a/lib/ConvertApi/ConvertApi.php b/lib/ConvertApi/ConvertApi.php index 0cb770b..3451184 100644 --- a/lib/ConvertApi/ConvertApi.php +++ b/lib/ConvertApi/ConvertApi.php @@ -57,6 +57,24 @@ public static function setApiSecret($apiSecret) self::$apiSecret = $apiSecret; } + /** + * @return string The API base used for requests. + */ + public static function getApiBase() + { + return self::$apiBase; + } + + /** + * Sets API base used for requests. + * + * @param string $apiBase + */ + public static function setApiBase($apiBase) + { + self::$apiBase = $apiBase; + } + /** * Perform conversion * diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 91e36a2..6896f8e 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -28,6 +28,9 @@ public function testConfigurationAccessors() { ConvertApi::setApiSecret('test-secret'); $this->assertEquals('test-secret', ConvertApi::getApiSecret()); + + ConvertApi::setApiSecret('https://foo.bar'); + $this->assertEquals('https://foo.bar', ConvertApi::getApiBase()); } public function testClient() From a13ba06e3c13077fc90b925924d31ceaeda6c5ad Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 21:20:38 +0300 Subject: [PATCH 04/10] Fix specs by specifying formats --- examples/conversions_chaining.php | 2 +- tests/ConvertApi/ConvertApiTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/conversions_chaining.php b/examples/conversions_chaining.php index c9af123..2e724d6 100644 --- a/examples/conversions_chaining.php +++ b/examples/conversions_chaining.php @@ -20,7 +20,7 @@ echo "Conversions done. Cost: ${cost}. Total files created: ${count}\n"; -$zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()]); +$zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()], 'any'); $cost = $zipResult->getConversionCost(); $count = count($zipResult->getFiles()); diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 91e36a2..cb7b0be 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -117,7 +117,7 @@ public function testConvertWithMultipleFiles() 'Files' => ['examples/files/test.pdf', 'examples/files/test.pdf'] ]; - $result = ConvertApi::convert('zip', $params); + $result = ConvertApi::convert('zip', $params, 'any'); $this->assertEquals('test.zip', $result->getFile()->getFileName()); } @@ -126,7 +126,7 @@ public function testConvertWithUrl() { $params = ['Url' => 'https://www.convertapi.com']; - $result = ConvertApi::convert('pdf', $params); + $result = ConvertApi::convert('pdf', $params, 'web'); $this->assertInternalType('int', $result->getFile()->getFileSize()); } @@ -139,7 +139,7 @@ public function testChainedConversion() $params = ['Files' => $result->getFiles()]; - $result = ConvertApi::convert('zip', $params); + $result = ConvertApi::convert('zip', $params, 'any'); $this->assertEquals('test.zip', $result->getFile()->getFileName()); } From 3f6099c2b2122a125adc988b96a5fc883198a936 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 21:29:29 +0300 Subject: [PATCH 05/10] Fix API base setting spec --- tests/ConvertApi/ConvertApiTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 3035f26..ec79d32 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -12,6 +12,7 @@ protected function setUp() { // Save original values so that we can restore them after running tests $this->origApiSecret = ConvertApi::getApiSecret(); + $this->origApiBase = ConvertApi::getApiBase(); $this->origUploadTimeout = ConvertApi::$uploadTimeout; ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); @@ -21,6 +22,7 @@ protected function tearDown() { // Restore original values ConvertApi::setApiSecret($this->origApiSecret); + ConvertApi::setApiBase($this->origApiBase); ConvertApi::$uploadTimeout = $this->origUploadTimeout; } @@ -29,7 +31,7 @@ public function testConfigurationAccessors() ConvertApi::setApiSecret('test-secret'); $this->assertEquals('test-secret', ConvertApi::getApiSecret()); - ConvertApi::setApiSecret('https://foo.bar'); + ConvertApi::setApiBase('https://foo.bar'); $this->assertEquals('https://foo.bar', ConvertApi::getApiBase()); } From 83216bf1547179220bd004d294f03dd079c0cc43 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 21:38:02 +0300 Subject: [PATCH 06/10] Replace Travis with GitHub actions --- .github/workflows/main.yml | 23 +++++++++++++++++++++++ .travis.yml | 14 -------------- 2 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..01ee669 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: Build +on: [push,pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: + - '5.6' + - '7.0' + - '7.4' + name: PHP ${{ matrix.php-version }} sample + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + - run: | + curl -s http://getcomposer.org/installer | php + php composer.phar install + - env: + CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_SECRET }} + run: bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 96b33ba..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: php -before_script: -- curl -s http://getcomposer.org/installer | php -- php composer.phar install -script: bin/phpunit -php: -- '5.6' -- '7.0' -- '7.2' -- '7.3' -- '7.4' -env: - global: - secure: mXU0rtRvLdr/hBvsb9igcC+7pVdSDZFxd4UbRBDxdkq3kzqtqNiyZgF10E9O9gTsSL2laysVsBqJfyEPHYtH9X6eSD+O9w4ydN8VfprEjF9jH/UZS1YGz7Ik2yxPhT2TpEc1T8/y+P0/AdpbP7zjrAaYIdTtYUAJeVSx26BBPO6tg0XS/JzAVK3C1y8Bw7Wz6hwOnm449uR8YorjMvW4M8oLsDdXRWtfw/A9GIwu/Wek4LXvuFRdOqpJwT7jUbQpFppEONXAM/NUzFleJSZcuLIvYwIUpportdOxV5mUjSspawWYKEOfdGT+xeDeGo0wyJbKfqlgJbPGmhj9K1J0EHGDTWhJVPwrM3mMAwRT/xi1W1boCiWch08qVlsUPJzgtZZSTZ2tMz+0X5KSbUWKKl+bl33ypdkCJqflxkNUYmpvIk5oDL4xNNkjnnjNMoJCrT3Rs1mLKrx0NJCoNS5JLgvfnSvzhfw9jsP+MWRxvMjK3VuMArgyhPw+TU9tdHpaCvVsVBEbwV3pdyAq2eFxsEun0iMnTtrt72vksdCeduZAWjxeQoODgFBBnX0jXBQfkobQVoNH2VoW9J9uB5/4bYMabzlfcqKkT7IyHiQsHyrvEqGvgSjW2rc+EvuZgi8+bjS4dKlScLl+pIe+iqnY999l744HGJHldf3HpQo1MQo= From 69ba18fbf7518cb6e33705cf7de8aa5bd36634f7 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 21:42:17 +0300 Subject: [PATCH 07/10] Replace badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e3674e..5a58947 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ConvertAPI PHP Client [![PHP version](https://badge.fury.io/ph/convertapi%2Fconvertapi-php.svg)](https://packagist.org/packages/convertapi/convertapi-php) -[![Build Status](https://secure.travis-ci.org/ConvertAPI/convertapi-php.svg)](http://travis-ci.org/ConvertAPI/convertapi-php) +[![Build Status](https://github.com/ConvertAPI/convertapi-php/actions/workflows/main.yml/badge.svg)](https://github.com/ConvertAPI/convertapi-php/actions) ## Convert your files with our online file conversion API From 74776d6858776107490a4691704f94e0c0288032 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 21:06:17 +0300 Subject: [PATCH 08/10] Fix filename with spaces encoding in file uploads --- lib/ConvertApi/Client.php | 2 +- tests/ConvertApi/ConvertApiTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ConvertApi/Client.php b/lib/ConvertApi/Client.php index 4e9dfbc..288d046 100644 --- a/lib/ConvertApi/Client.php +++ b/lib/ConvertApi/Client.php @@ -28,7 +28,7 @@ public function upload($file_or_resource, $fileName) [ 'Content-Type: application/octet-stream', 'Transfer-Encoding: chunked', - "Content-Disposition: attachment; filename*=UTF-8''" . urlencode($fileName), + "Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($fileName), ] ); diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index ec79d32..4429f40 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -96,6 +96,16 @@ public function testConvertWithFileUpload() $this->assertEquals('custom.pdf', $result->getFile()->getFileName()); } + public function testConvertWithFileUploadAndSpaces() + { + $fileUpload = new \ConvertApi\FileUpload('examples/files/test.docx', 'test space ačiū.docx'); + $params = ['File' => $fileUpload]; + + $result = ConvertApi::convert('pdf', $params); + + $this->assertEquals('test space ačiū.pdf', $result->getFile()->getFileName()); + } + public function testConvertWithFileResourceUpload() { $fp = fopen('examples/files/test.docx', 'rb'); From 9f0816510e7bfb65b615fdd23a20c67228c5750c Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 22:15:18 +0300 Subject: [PATCH 09/10] Handle empty API response --- lib/ConvertApi/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ConvertApi/Client.php b/lib/ConvertApi/Client.php index 4e9dfbc..86be6d1 100644 --- a/lib/ConvertApi/Client.php +++ b/lib/ConvertApi/Client.php @@ -137,6 +137,9 @@ private function handleCurlError($ch) private function checkResponse($ch, $response) { + if (empty($response)) + throw new Error\Api('API response is empty'); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 200) From 71a5bcd6bd826fb8b6a28f2b24676060c68fd2a4 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 26 Jun 2022 22:24:07 +0300 Subject: [PATCH 10/10] Bump version --- lib/ConvertApi/ConvertApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ConvertApi/ConvertApi.php b/lib/ConvertApi/ConvertApi.php index 3451184..4ac4f74 100644 --- a/lib/ConvertApi/ConvertApi.php +++ b/lib/ConvertApi/ConvertApi.php @@ -10,7 +10,7 @@ class ConvertApi { // ConvertAPI client version. - const VERSION = '1.5.0'; + const VERSION = '1.6.0'; // @var string The Convert API secret. You can get your secret at https://www.convertapi.com/a public static $apiSecret;