Skip to content

Commit

Permalink
Update updateCardCustomField to handle params as body
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Mar 27, 2018
1 parent 9938003 commit e13cdab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All Notable changes to `trello-php` will be documented in this file
- Nothing

### Fixed
- Fixed path mapping for updateCardCustomField method
- Update path mapping for updateCardCustomField method

### Removed
- Nothing
Expand Down
33 changes: 28 additions & 5 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\ClientInterface as HttpClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;

class Http
{
const HTTP_DELETE = 'DELETE';
const HTTP_GET = 'GET';
const HTTP_POST = 'POST';
const HTTP_PUT = 'PUT';

/**
* Multipart resources to include in next request.
*
Expand Down Expand Up @@ -64,7 +70,7 @@ protected function createRequest($verb, $path, $parameters = [])
if (isset($parameters['file'])) {
$this->queueResourceAs(
'file',
\GuzzleHttp\Psr7\stream_for($parameters['file'])
Psr7\stream_for($parameters['file'])
);
unset($parameters['file']);
}
Expand Down Expand Up @@ -92,7 +98,7 @@ protected function createRequest($verb, $path, $parameters = [])
*/
public function delete($path, $parameters = [])
{
$request = $this->getRequest('DELETE', $path, $parameters);
$request = $this->getRequest(static::HTTP_DELETE, $path, $parameters);

return $this->sendRequest($request);
}
Expand All @@ -107,7 +113,7 @@ public function delete($path, $parameters = [])
*/
public function get($path, $parameters = [])
{
$request = $this->getRequest('GET', $path, $parameters);
$request = $this->getRequest(static::HTTP_GET, $path, $parameters);

return $this->sendRequest($request);
}
Expand Down Expand Up @@ -202,7 +208,7 @@ protected function getUrlFromPath($path = '/')
*/
public function post($path, $parameters)
{
$request = $this->getRequest('POST', $path, $parameters);
$request = $this->getRequest(static::HTTP_POST, $path, $parameters);

return $this->sendRequest($request);
}
Expand All @@ -217,7 +223,24 @@ public function post($path, $parameters)
*/
public function put($path, $parameters)
{
$request = $this->getRequest('PUT', $path, $parameters);
$request = $this->getRequest(static::HTTP_PUT, $path, $parameters);

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

/**
* Retrieves http response for a request with the put method,
* ensuring parameters are passed as body.
*
* @param string $path
* @param array $parameters
*
* @return object
*/
public function putAsBody($path, $parameters)
{
$request = $this->getRequest(static::HTTP_PUT, $path)
->withBody(Psr7\stream_for(json_encode($parameters)));

return $this->sendRequest($request);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/ApiMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ trait ApiMethodsTrait
'updateCardLabel' => ['put', 'cards/%s/labels'],
'deleteCardLabel' => ['delete', 'cards/%s/labels/%s'],
'getCardCustomField' => ['get', 'cards/%s/customField/%s'],
'updateCardCustomField' => ['put', 'cards/%s/customField/%s/item'],
'updateCardCustomField' => ['putAsBody', 'cards/%s/customField/%s/item'],
'getCardList' => ['get', 'cards/%s/list'],
'getCardListField' => ['get', 'cards/%s/list/%s'],
'addCardMarkAssociatedNotificationsRead' => ['post', 'cards/%s/markAssociatedNotificationsRead'],
Expand Down

0 comments on commit e13cdab

Please sign in to comment.