Skip to content

Commit e13cdab

Browse files
committed
Update updateCardCustomField to handle params as body
1 parent 9938003 commit e13cdab

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ All Notable changes to `trello-php` will be documented in this file
1111
- Nothing
1212

1313
### Fixed
14-
- Fixed path mapping for updateCardCustomField method
14+
- Update path mapping for updateCardCustomField method
1515

1616
### Removed
1717
- Nothing

src/Http.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
use GuzzleHttp\Client as HttpClient;
44
use GuzzleHttp\ClientInterface as HttpClientInterface;
55
use GuzzleHttp\Exception\RequestException;
6+
use GuzzleHttp\Psr7;
67
use GuzzleHttp\Psr7\Request;
78
use Psr\Http\Message\RequestInterface;
89

910
class Http
1011
{
12+
const HTTP_DELETE = 'DELETE';
13+
const HTTP_GET = 'GET';
14+
const HTTP_POST = 'POST';
15+
const HTTP_PUT = 'PUT';
16+
1117
/**
1218
* Multipart resources to include in next request.
1319
*
@@ -64,7 +70,7 @@ protected function createRequest($verb, $path, $parameters = [])
6470
if (isset($parameters['file'])) {
6571
$this->queueResourceAs(
6672
'file',
67-
\GuzzleHttp\Psr7\stream_for($parameters['file'])
73+
Psr7\stream_for($parameters['file'])
6874
);
6975
unset($parameters['file']);
7076
}
@@ -92,7 +98,7 @@ protected function createRequest($verb, $path, $parameters = [])
9298
*/
9399
public function delete($path, $parameters = [])
94100
{
95-
$request = $this->getRequest('DELETE', $path, $parameters);
101+
$request = $this->getRequest(static::HTTP_DELETE, $path, $parameters);
96102

97103
return $this->sendRequest($request);
98104
}
@@ -107,7 +113,7 @@ public function delete($path, $parameters = [])
107113
*/
108114
public function get($path, $parameters = [])
109115
{
110-
$request = $this->getRequest('GET', $path, $parameters);
116+
$request = $this->getRequest(static::HTTP_GET, $path, $parameters);
111117

112118
return $this->sendRequest($request);
113119
}
@@ -202,7 +208,7 @@ protected function getUrlFromPath($path = '/')
202208
*/
203209
public function post($path, $parameters)
204210
{
205-
$request = $this->getRequest('POST', $path, $parameters);
211+
$request = $this->getRequest(static::HTTP_POST, $path, $parameters);
206212

207213
return $this->sendRequest($request);
208214
}
@@ -217,7 +223,24 @@ public function post($path, $parameters)
217223
*/
218224
public function put($path, $parameters)
219225
{
220-
$request = $this->getRequest('PUT', $path, $parameters);
226+
$request = $this->getRequest(static::HTTP_PUT, $path, $parameters);
227+
228+
return $this->sendRequest($request);
229+
}
230+
231+
/**
232+
* Retrieves http response for a request with the put method,
233+
* ensuring parameters are passed as body.
234+
*
235+
* @param string $path
236+
* @param array $parameters
237+
*
238+
* @return object
239+
*/
240+
public function putAsBody($path, $parameters)
241+
{
242+
$request = $this->getRequest(static::HTTP_PUT, $path)
243+
->withBody(Psr7\stream_for(json_encode($parameters)));
221244

222245
return $this->sendRequest($request);
223246
}

src/Traits/ApiMethodsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ trait ApiMethodsTrait
141141
'updateCardLabel' => ['put', 'cards/%s/labels'],
142142
'deleteCardLabel' => ['delete', 'cards/%s/labels/%s'],
143143
'getCardCustomField' => ['get', 'cards/%s/customField/%s'],
144-
'updateCardCustomField' => ['put', 'cards/%s/customField/%s/item'],
144+
'updateCardCustomField' => ['putAsBody', 'cards/%s/customField/%s/item'],
145145
'getCardList' => ['get', 'cards/%s/list'],
146146
'getCardListField' => ['get', 'cards/%s/list/%s'],
147147
'addCardMarkAssociatedNotificationsRead' => ['post', 'cards/%s/markAssociatedNotificationsRead'],

0 commit comments

Comments
 (0)