diff --git a/README.md b/README.md index 5aa4ab2..3059a78 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ If you use Composer, these dependencies should be handled automatically. If you ### Configuration -You can get your secret at https://www.convertapi.com/a +You can get your API credentials at https://www.convertapi.com/a ```php use \ConvertApi\ConvertApi; -ConvertApi::setApiSecret('your-api-secret'); +ConvertApi::setApiCredentials('your-api-secret-or-token'); ``` ### File conversion diff --git a/examples/conversions_chaining.php b/examples/conversions_chaining.php index de4593f..8bbebf4 100644 --- a/examples/conversions_chaining.php +++ b/examples/conversions_chaining.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed # https://www.convertapi.com/doc/chaining diff --git a/examples/convert_stream.php b/examples/convert_stream.php index 227b7d9..c3e0481 100644 --- a/examples/convert_stream.php +++ b/examples/convert_stream.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of converting content stream to PDF # https://www.convertapi.com/txt-to-pdf diff --git a/examples/convert_url_to_pdf.php b/examples/convert_url_to_pdf.php index 34c9ff0..aa06962 100644 --- a/examples/convert_url_to_pdf.php +++ b/examples/convert_url_to_pdf.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of converting Web Page URL to PDF file # https://www.convertapi.com/web-to-pdf diff --git a/examples/convert_word_to_pdf_and_png.php b/examples/convert_word_to_pdf_and_png.php index 1ce2ed3..3c83ac8 100644 --- a/examples/convert_word_to_pdf_and_png.php +++ b/examples/convert_word_to_pdf_and_png.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of saving Word docx to PDF and to PNG # https://www.convertapi.com/docx-to-pdf diff --git a/examples/create_pdf_thumbnail.php b/examples/create_pdf_thumbnail.php index a111eb5..4cd271e 100644 --- a/examples/create_pdf_thumbnail.php +++ b/examples/create_pdf_thumbnail.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of extracting first page from PDF and then chaining conversion PDF page to JPG. # https://www.convertapi.com/pdf-to-extract diff --git a/examples/error_handling.php b/examples/error_handling.php index ae0f0c9..16dcf06 100644 --- a/examples/error_handling.php +++ b/examples/error_handling.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); try { $result = ConvertApi::convert('svg', ['File' => 'files/test.docx']); diff --git a/examples/retrieve_user_information.php b/examples/retrieve_user_information.php index 77d0d50..d8db60c 100644 --- a/examples/retrieve_user_information.php +++ b/examples/retrieve_user_information.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Retrieve user information # https://www.convertapi.com/doc/user diff --git a/examples/split_and_merge_pdf.php b/examples/split_and_merge_pdf.php index a8a20b1..69171cf 100644 --- a/examples/split_and_merge_pdf.php +++ b/examples/split_and_merge_pdf.php @@ -3,8 +3,8 @@ use \ConvertApi\ConvertApi; -# set your api secret -ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); +# set your api secret or token +ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of extracting first and last pages from PDF and then merging them back to new PDF. # https://www.convertapi.com/pdf-to-split diff --git a/lib/ConvertApi/Client.php b/lib/ConvertApi/Client.php index 64e2caf..0ec1c42 100644 --- a/lib/ConvertApi/Client.php +++ b/lib/ConvertApi/Client.php @@ -169,12 +169,15 @@ private function parseResponse($response) private function url($path) { - return ConvertApi::$apiBase . $path . '?secret=' . ConvertApi::getApiSecret(); + return ConvertApi::$apiBase . $path; } private function defaultHeaders() { - return ['Accept: application/json']; + return [ + 'Accept: application/json', + 'Authorization: Bearer ' . ConvertApi::getApiCredentials(), + ]; } private function userAgent() diff --git a/lib/ConvertApi/ConvertApi.php b/lib/ConvertApi/ConvertApi.php index 0b0547c..fed6c0b 100644 --- a/lib/ConvertApi/ConvertApi.php +++ b/lib/ConvertApi/ConvertApi.php @@ -12,8 +12,8 @@ class ConvertApi // ConvertAPI client version. const VERSION = '2.0.1'; - // @var string The Convert API secret. You can get your secret at https://www.convertapi.com/a - public static $apiSecret; + // @var string The Convert API credentials. You can get your credentials at https://www.convertapi.com/a + public static $apiCredentials; // @var string The base URL for the Convert API public static $apiBase = 'https://v2.convertapi.com/'; @@ -40,21 +40,21 @@ class ConvertApi private static $_client; /** - * @return string The API secret used for requests. + * @return string The API credentials used for requests. */ - public static function getApiSecret() + public static function getApiCredentials() { - return self::$apiSecret; + return self::$apiCredentials; } /** - * Sets API secret used for requests. + * Sets API secret or token used for requests. * - * @param string $apiSecret + * @param string $apiCredentials */ - public static function setApiSecret($apiSecret) + public static function setApiCredentials($apiCredentials) { - self::$apiSecret = $apiSecret; + self::$apiCredentials = $apiCredentials; } /** diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index cc71731..31f3810 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -11,25 +11,25 @@ class ConvertApiTest extends \PHPUnit\Framework\TestCase protected function setUp(): void { // Save original values so that we can restore them after running tests - $this->origApiSecret = ConvertApi::getApiSecret(); + $this->origApiCredentials = ConvertApi::getApiCredentials(); $this->origApiBase = ConvertApi::getApiBase(); $this->origUploadTimeout = ConvertApi::$uploadTimeout; - ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); + ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); } protected function tearDown(): void { // Restore original values - ConvertApi::setApiSecret($this->origApiSecret); + ConvertApi::setApiCredentials($this->origApiCredentials); ConvertApi::setApiBase($this->origApiBase); ConvertApi::$uploadTimeout = $this->origUploadTimeout; } public function testConfigurationAccessors() { - ConvertApi::setApiSecret('test-secret'); - $this->assertEquals('test-secret', ConvertApi::getApiSecret()); + ConvertApi::setApiCredentials('test-secret'); + $this->assertEquals('test-secret', ConvertApi::getApiCredentials()); ConvertApi::setApiBase('https://foo.bar'); $this->assertEquals('https://foo.bar', ConvertApi::getApiBase());