diff --git a/README.md b/README.md index 5a58947..7c75549 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ ConvertApi::setApiSecret('your-api-secret'); ### File conversion Convert file to PDF example. All supported formats and options can be found -[here](https://www.convertapi.com). +[here](https://www.convertapi.com/conversions). ```php $result = ConvertApi::convert('pdf', ['File' => '/path/to/my_file.docx']); @@ -96,7 +96,7 @@ $result = ConvertApi::convert( #### Additional conversion parameters ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion -parameters and explanations can be found [here](https://www.convertapi.com). +parameters and explanations can be found [here](https://www.convertapi.com/conversions). ```php $result = ConvertApi::convert( @@ -119,6 +119,14 @@ $info = ConvertApi::getUser(); echo $info['SecondsLeft']; ``` +### Alternative domain + +Use `setApiBase` method to set alternative service domain. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location). + +```php +ConvertApi::setApiBase('https://eu-v2.convertapi.com/'); +``` + ### More examples Find more advanced examples in the [examples/](https://github.com/ConvertAPI/convertapi-php/tree/master/examples) folder. diff --git a/lib/ConvertApi/Task.php b/lib/ConvertApi/Task.php index 6aa07e5..fca394e 100644 --- a/lib/ConvertApi/Task.php +++ b/lib/ConvertApi/Task.php @@ -31,8 +31,9 @@ function run() } $fromFormat = $this->fromFormat ?: $this->detectFormat($params); - $converter = isset($params['converter']) ? "/converter/{$params['converter']}" : ''; - $path = 'convert/' . $fromFormat . '/to/' . $this->toFormat . $converter; + $converter = $this->detectConverter($params); + $converterPath = $converter ? "/converter/{$converter}" : ''; + $path = 'convert/' . $fromFormat . '/to/' . $this->toFormat . $converterPath; $response = ConvertApi::client()->post($path, $params, $readTimeout); @@ -45,12 +46,12 @@ private function normalizedParams() foreach ($this->params as $key => $val) { - switch($key) { - case 'File': + switch(true) { + case $key != 'StoreFile' && preg_match('/File$/', $key): $result[$key] = FileParam::build($val); break; - case 'Files': + case $key == 'Files': $result[$key] = $this->filesBatch($val); break; @@ -91,4 +92,15 @@ private function detectFormat($params) return $detector->run(); } + + private function detectConverter($params) + { + $keys = array_keys($params); + + foreach ($keys as $key) + if (strtolower($key) == 'converter') + return $params[$key]; + + return; + } } diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 4429f40..3cb76f5 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -159,6 +159,18 @@ public function testChainedConversion() $this->assertEquals('test.zip', $result->getFile()->getFileName()); } + public function testCompare() + { + $params = [ + 'File' => 'examples/files/test.docx', + 'CompareFile' => 'examples/files/test.docx' + ]; + + $result = ConvertApi::convert('compare', $params); + + $this->assertEquals('test.docx', $result->getFile()->getFileName()); + } + public function testApiError() { $params = ['Url' => 'https://www.w3.org/TR/PNG/iso_8859-1.txt'];