Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #105 from ste93cry/fix/no-post-params-in-querystring
Browse files Browse the repository at this point in the history
Prevent the request body parameters to be put in the query string
  • Loading branch information
mavimo committed Mar 4, 2019
2 parents 7ed2b8a + cebd888 commit acbb899
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/Api/CallActivityApi.php
Expand Up @@ -94,7 +94,7 @@ public function get(string $id, array $fields = []): CallActivity
*/
public function create(CallActivity $activity): CallActivity
{
$response = $this->client->post($this->prepareUrlForKey('add-call'), $activity->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-call'), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new CallActivity($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/ContactApi.php
Expand Up @@ -89,7 +89,7 @@ public function get(string $id, array $fields = []): Contact
*/
public function create(Contact $contact): Contact
{
$response = $this->client->post($this->prepareUrlForKey('add-contact'), $contact->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-contact'), [], $contact->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Contact($responseData);
Expand All @@ -108,7 +108,7 @@ public function update(Contact $contact): Contact

$contact->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-contact', ['id' => $id]), $contact->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-contact', ['id' => $id]), [], $contact->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Contact($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/CustomFieldApi.php
Expand Up @@ -87,7 +87,7 @@ public function get(string $id, array $fields = []): CustomField
*/
public function create(CustomField $customField): CustomField
{
$response = $this->client->post($this->prepareUrlForKey('create-custom-field'), $customField->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('create-custom-field'), [], $customField->jsonSerialize());
$responseData = $response->getDecodedBody();

return new CustomField($responseData);
Expand All @@ -106,7 +106,7 @@ public function update(CustomField $customField): CustomField

$customField->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-custom-field', ['id' => $id]), $customField->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-custom-field', ['id' => $id]), [], $customField->jsonSerialize());
$responseData = $response->getDecodedBody();

return new CustomField($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/EmailActivityApi.php
Expand Up @@ -92,7 +92,7 @@ public function get(string $id, array $fields = []): EmailActivity
*/
public function create(EmailActivity $activity): EmailActivity
{
$response = $this->client->post($this->prepareUrlForKey('add-email'), $activity->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-email'), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new EmailActivity($responseData);
Expand All @@ -111,7 +111,7 @@ public function update(EmailActivity $activity): EmailActivity

$activity->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-email', ['id' => $id]), $activity->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-email', ['id' => $id]), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new EmailActivity($responseData);
Expand Down
6 changes: 3 additions & 3 deletions src/Api/LeadApi.php
Expand Up @@ -97,7 +97,7 @@ public function create(Lead $lead): Lead
{
$this->validateLeadForPost($lead);

$response = $this->client->post($this->prepareUrlForKey('add-lead'), $lead->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-lead'), [], $lead->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Lead($responseData);
Expand All @@ -116,7 +116,7 @@ public function update(Lead $lead): Lead

$lead->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-lead', ['id' => $id]), $lead->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-lead', ['id' => $id]), [], $lead->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Lead($responseData);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function merge(Lead $source, Lead $destination): void
throw new InvalidParamException('You need to specify two already existing leads in order to merge them');
}

$this->client->post($this->prepareUrlForKey('merge-leads'), [
$this->client->post($this->prepareUrlForKey('merge-leads'), [], [
'destination' => $destination->getId(),
'source' => $source->getId(),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/LeadStatusApi.php
Expand Up @@ -90,7 +90,7 @@ public function get(string $id, array $fields = []): LeadStatus
*/
public function create(LeadStatus $leadStatus): LeadStatus
{
$response = $this->client->post($this->prepareUrlForKey('add-status'), $leadStatus->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-status'), [], $leadStatus->jsonSerialize());
$responseData = $response->getDecodedBody();

return new LeadStatus($responseData);
Expand All @@ -109,7 +109,7 @@ public function update(LeadStatus $leadStatus): LeadStatus

$leadStatus->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-status', ['id' => $id]), $leadStatus->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-status', ['id' => $id]), [], $leadStatus->jsonSerialize());
$responseData = $response->getDecodedBody();

return new LeadStatus($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/NoteActivityApi.php
Expand Up @@ -91,7 +91,7 @@ public function get(string $id, array $fields = []): NoteActivity
*/
public function create(NoteActivity $activity): NoteActivity
{
$response = $this->client->post($this->prepareUrlForKey('add-note'), $activity->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-note'), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new NoteActivity($responseData);
Expand All @@ -110,7 +110,7 @@ public function update(NoteActivity $activity): NoteActivity

$activity->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-note', ['id' => $id]), $activity->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-note', ['id' => $id]), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new NoteActivity($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/OpportunityApi.php
Expand Up @@ -97,7 +97,7 @@ public function get(string $id, array $fields = []): Opportunity
*/
public function create(Opportunity $opportunity): Opportunity
{
$response = $this->client->post($this->prepareUrlForKey('add-opportunity'), $opportunity->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-opportunity'), [], $opportunity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Opportunity($responseData);
Expand All @@ -116,7 +116,7 @@ public function update(Opportunity $opportunity): Opportunity

$opportunity->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-opportunity', ['id' => $id]), $opportunity->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-opportunity', ['id' => $id]), [], $opportunity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Opportunity($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/OpportunityStatusApi.php
Expand Up @@ -91,7 +91,7 @@ public function get(string $id, array $fields = []): OpportunityStatus
*/
public function create(OpportunityStatus $opportunityStatus): OpportunityStatus
{
$response = $this->client->post($this->prepareUrlForKey('add-status'), $opportunityStatus->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-status'), [], $opportunityStatus->jsonSerialize());
$responseData = $response->getDecodedBody();

return new OpportunityStatus($responseData);
Expand All @@ -110,7 +110,7 @@ public function update(OpportunityStatus $opportunityStatus): OpportunityStatus

$opportunityStatus->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-status', ['id' => $id]), $opportunityStatus->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-status', ['id' => $id]), [], $opportunityStatus->jsonSerialize());
$responseData = $response->getDecodedBody();

return new OpportunityStatus($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/SmsActivityApi.php
Expand Up @@ -91,7 +91,7 @@ public function get(string $id, array $fields = []): SmsActivity
*/
public function create(SmsActivity $activity): SmsActivity
{
$response = $this->client->post($this->prepareUrlForKey('add-sms'), $activity->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-sms'), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new SmsActivity($responseData);
Expand All @@ -110,7 +110,7 @@ public function update(SmsActivity $activity): SmsActivity

$activity->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-sms', ['id' => $id]), $activity->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-sms', ['id' => $id]), [], $activity->jsonSerialize());
$responseData = $response->getDecodedBody();

return new SmsActivity($responseData);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/TaskApi.php
Expand Up @@ -89,7 +89,7 @@ public function get(string $id, array $fields = []): Task
*/
public function create(Task $task): Task
{
$response = $this->client->post($this->prepareUrlForKey('add-task'), $task->jsonSerialize());
$response = $this->client->post($this->prepareUrlForKey('add-task'), [], $task->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Task($responseData);
Expand All @@ -108,7 +108,7 @@ public function update(Task $task): Task

$task->setId(null);

$response = $this->client->put($this->prepareUrlForKey('update-task', ['id' => $id]), $task->jsonSerialize());
$response = $this->client->put($this->prepareUrlForKey('update-task', ['id' => $id]), [], $task->jsonSerialize());
$responseData = $response->getDecodedBody();

return new Task($responseData);
Expand Down
18 changes: 9 additions & 9 deletions src/Client.php
Expand Up @@ -102,33 +102,33 @@ public function getHttpClient(): HttpClientInterface
/**
* {@inheritdoc}
*/
public function get(string $endpoint, array $params = []): CloseIoResponse
public function get(string $endpoint, array $queryParams = []): CloseIoResponse
{
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_GET, $endpoint, $params));
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_GET, $endpoint, $queryParams));
}

/**
* {@inheritdoc}
*/
public function post(string $endpoint, array $params = []): CloseIoResponse
public function post(string $endpoint, array $queryParams = [], array $bodyParams = []): CloseIoResponse
{
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_POST, $endpoint, $params));
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_POST, $endpoint, $queryParams, $bodyParams));
}

/**
* {@inheritdoc}
*/
public function put(string $endpoint, array $params = []): CloseIoResponse
public function put(string $endpoint, array $queryParams = [], array $bodyParams = []): CloseIoResponse
{
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_PUT, $endpoint, $params));
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_PUT, $endpoint, $queryParams, $bodyParams));
}

/**
* {@inheritdoc}
*/
public function delete(string $endpoint, array $params = []): CloseIoResponse
public function delete(string $endpoint, array $queryParams = []): CloseIoResponse
{
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_DELETE, $endpoint, $params));
return $this->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_DELETE, $endpoint, $queryParams));
}

/**
Expand All @@ -138,7 +138,7 @@ public function sendRequest(CloseIoRequest $request): CloseIoResponse
{
$requestBody = null;

if (!empty($request->getBodyParams())) {
if (!empty($request->getBodyParams()) && \in_array($request->getMethod(), [RequestMethodInterface::METHOD_POST, RequestMethodInterface::METHOD_PUT], true)) {
$params = $request->getBodyParams();

foreach ($params as $name => $value) {
Expand Down
26 changes: 14 additions & 12 deletions src/ClientInterface.php
Expand Up @@ -43,58 +43,60 @@ public function getHttpClient(): HttpClientInterface;
/**
* Sends a GET request to Close.io REST API and returns the result.
*
* @param string $endpoint The REST endpoint for the request
* @param array $params The parameters to send with the request
* @param string $endpoint The REST endpoint for the request
* @param array $queryParams The parameters to send in the query string
*
* @return CloseIoResponse
*
* @throws CloseIoException If an error happens while processing the request
* @throws CloseIoResponseException If the response errored
* @throws JsonException If the response body could not be parsed as JSON
*/
public function get(string $endpoint, array $params = []): CloseIoResponse;
public function get(string $endpoint, array $queryParams = []): CloseIoResponse;

/**
* Sends a POST request to Close.io REST API and returns the result.
*
* @param string $endpoint The REST endpoint for the request
* @param array $params The parameters to send with the request
* @param string $endpoint The REST endpoint for the request
* @param array $queryParams The parameters to send in the query string
* @param array $bodyParams The parameters to send as body of the request
*
* @return CloseIoResponse
*
* @throws CloseIoException If an error happens while processing the request
* @throws CloseIoResponseException If the response errored
* @throws JsonException If the response body could not be parsed as JSON
*/
public function post(string $endpoint, array $params = []): CloseIoResponse;
public function post(string $endpoint, array $queryParams = [], array $bodyParams = []): CloseIoResponse;

/**
* Sends a PUT request to Close.io REST API and returns the result.
*
* @param string $endpoint The REST endpoint for the request
* @param array $params The parameters to send with the request
* @param string $endpoint The REST endpoint for the request
* @param array $queryParams The parameters to send in the query string
* @param array $bodyParams The parameters to send as body of the request
*
* @return CloseIoResponse
*
* @throws CloseIoException If an error happens while processing the request
* @throws CloseIoResponseException If the response errored
* @throws JsonException If the response body could not be parsed as JSON
*/
public function put(string $endpoint, array $params = []): CloseIoResponse;
public function put(string $endpoint, array $queryParams = [], array $bodyParams = []): CloseIoResponse;

/**
* Sends a DELETE request to Close.io REST API and returns the result.
*
* @param string $endpoint The REST endpoint for the request
* @param array $params The parameters to send with the request
* @param string $endpoint The REST endpoint for the request
* @param array $queryParams The parameters to send in the query string
*
* @return CloseIoResponse
*
* @throws CloseIoException If an error happens while processing the request
* @throws CloseIoResponseException If the response errored
* @throws JsonException If the response body could not be parsed as JSON
*/
public function delete(string $endpoint, array $params = []): CloseIoResponse;
public function delete(string $endpoint, array $queryParams = []): CloseIoResponse;

/**
* Sends a request to the server and returns the response.
Expand Down

0 comments on commit acbb899

Please sign in to comment.