Skip to content

Commit

Permalink
PUT and DELETE methods
Browse files Browse the repository at this point in the history
  • Loading branch information
muxx committed Dec 15, 2018
1 parent 4411826 commit 1b05d6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/Redmine/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function requestGet(string $path, ?array $queryParameters = []): ApiRespo
]);
}

public function requestDelete(string $path, ?array $queryParameters = []): ApiResponse
{
return $this->client->makeRequest($path . '.json', [
'method' => Client::METHOD_DELETE,
'query' => $queryParameters,
]);
}

public function requestPost(string $path, array $postData = [], array $queryParameters = []): ApiResponse
{
return $this->client->makeRequest($path . 'json', [
Expand All @@ -33,4 +41,13 @@ public function requestPost(string $path, array $postData = [], array $queryPara
'query' => $queryParameters,
]);
}

public function requestPut(string $path, array $putData = [], array $queryParameters = []): ApiResponse
{
return $this->client->makeRequest($path . 'json', [
'method' => Client::METHOD_PUT,
'postFields' => json_encode($putData),
'query' => $queryParameters,
]);
}
}
12 changes: 11 additions & 1 deletion lib/Redmine/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Client
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';

protected $defaultHeaders;
protected $url;
Expand Down Expand Up @@ -86,7 +88,15 @@ protected function configureRequestOptions(OptionsResolver $resolver): void
'postFields',
'cacheLifetime'
])
->setAllowedValues('method', [static::METHOD_POST, static::METHOD_GET])
->setAllowedValues(
'method',
[
static::METHOD_POST,
static::METHOD_GET,
static::METHOD_PUT,
static::METHOD_DELETE,
]
)
->setAllowedTypes('timeout', 'int')
->setAllowedTypes('headers', 'array')
->setAllowedTypes('query', 'array')
Expand Down

0 comments on commit 1b05d6f

Please sign in to comment.