Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate getLastResponse...() and request...() in Clients #426

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- New class `Redmine\Http\HttpFactory` to create `Redmine\Http\Request` and `Redmine\Http\Response` instances.

### Deprecated

- `Redmine\Client\Client::requestGet()` is deprecated, use `\Redmine\Client\Client::request()` instead.
- `Redmine\Client\Client::requestPost()` is deprecated, use `\Redmine\Client\Client::request()` instead.
- `Redmine\Client\Client::requestPut()` is deprecated, use `\Redmine\Client\Client::request()` instead.
- `Redmine\Client\Client::requestDelete()` is deprecated, use `\Redmine\Client\Client::request()` instead.
- `Redmine\Client\Client::getLastResponseStatusCode()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getStatusCode()` instead.
- `Redmine\Client\Client::getLastResponseContentType()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getContentType()` instead.
- `Redmine\Client\Client::getLastResponseBody()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getContent()` instead.

## [v2.7.0](https://github.com/kbsali/php-redmine-api/compare/v2.6.0...v2.7.0) - 2024-07-10

### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ like [Guzzle](https://github.com/guzzle/guzzle) for handling http connections
* [mid-level API](docs/usage.md#mid-level-api) e.g.
```php
$client->getApi('issue')->create(['project_id' => 1, 'subject' => 'issue title']);

$response = $client->getApi('issue')->getLastResponse();
```
* [low-level API](docs/usage.md#low-level-api) e.g.
```php
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
},
"scripts": {
"bdt": [
"Composer\\Config::disableProcessTimeout",
"@behat --format=progress --suite=redmine_50103",
"@behat --format=progress --suite=redmine_50009",
"@behat --format=progress --suite=redmine_40210"
Expand Down
24 changes: 24 additions & 0 deletions src/Redmine/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,60 @@ public function stopImpersonateUser(): void;

/**
* Create and send a GET request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestGet(string $path): bool;

/**
* Create and send a POST request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestPost(string $path, string $body): bool;

/**
* Create and send a PUT request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestPut(string $path, string $body): bool;

/**
* Create and send a DELETE request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestDelete(string $path): bool;

/**
* Returns status code of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseStatusCode(): int;

/**
* Returns content type of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseContentType(): string;

/**
* Returns the body of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseBody(): string;
}
38 changes: 38 additions & 0 deletions src/Redmine/Client/NativeCurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,57 +111,95 @@ public function stopImpersonateUser(): void

/**
* Create and send a GET request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestGet(string $path): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED);

return $this->runRequest('GET', $path);
}

/**
* Create and send a POST request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestPost(string $path, string $body): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED);

return $this->runRequest('POST', $path, $body);
}

/**
* Create and send a PUT request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestPut(string $path, string $body): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED);

return $this->runRequest('PUT', $path, $body);
}

/**
* Create and send a DELETE request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*/
public function requestDelete(string $path): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED);

return $this->runRequest('DELETE', $path);
}

/**
* Returns status code of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseStatusCode(): int
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

return $this->lastResponseStatusCode;
}

/**
* Returns content type of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseContentType(): string
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

return $this->lastResponseContentType;
}

/**
* Returns the body of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Http\HttpClient::request()
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseBody(): string
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

return $this->lastResponseBody;
}

Expand Down
35 changes: 35 additions & 0 deletions src/Redmine/Client/Psr18Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ public function stopImpersonateUser(): void
/**
* Create and send a GET request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*
* @throws ClientException If anything goes wrong on the request
*
* @return bool true if status code of the response is not 4xx oder 5xx
*/
public function requestGet(string $path): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED);

$response = $this->runRequest('GET', $path);

return $response->getStatusCode() < 400;
Expand All @@ -132,12 +137,17 @@ public function requestGet(string $path): bool
/**
* Create and send a POST request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*
* @throws ClientException If anything goes wrong on the request
*
* @return bool true if status code of the response is not 4xx oder 5xx
*/
public function requestPost(string $path, string $body): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED);

$response = $this->runRequest('POST', $path, $body);

return $response->getStatusCode() < 400;
Expand All @@ -146,12 +156,17 @@ public function requestPost(string $path, string $body): bool
/**
* Create and send a PUT request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*
* @throws ClientException If anything goes wrong on the request
*
* @return bool true if status code of the response is not 4xx oder 5xx
*/
public function requestPut(string $path, string $body): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED);

$response = $this->runRequest('PUT', $path, $body);

return $response->getStatusCode() < 400;
Expand All @@ -160,22 +175,32 @@ public function requestPut(string $path, string $body): bool
/**
* Create and send a DELETE request.
*
* @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*
* @throws ClientException If anything goes wrong on the request
*
* @return bool true if status code of the response is not 4xx oder 5xx
*/
public function requestDelete(string $path): bool
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED);

$response = $this->runRequest('DELETE', $path);

return $response->getStatusCode() < 400;
}

/**
* Returns status code of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseStatusCode(): int
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

if (null === $this->lastResponse) {
return 0;
}
Expand All @@ -185,9 +210,14 @@ public function getLastResponseStatusCode(): int

/**
* Returns content type of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseContentType(): string
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

if (null === $this->lastResponse) {
return '';
}
Expand All @@ -197,9 +227,14 @@ public function getLastResponseContentType(): string

/**
* Returns the body of the last response.
*
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
* @see \Redmine\Api\AbstractApi::getLastResponse()
*/
public function getLastResponseBody(): string
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);

if (null === $this->lastResponse) {
return '';
}
Expand Down
Loading
Loading