Skip to content

Commit

Permalink
Ensure Leads()->add() post as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
simensen committed Dec 22, 2020
1 parent ebb87dd commit 3dd70c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Http/PipedriveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\RequestOptions;

class PipedriveClient implements Client
{
Expand Down Expand Up @@ -109,6 +110,11 @@ public function post($url, $parameters = [])
$parameters = $this->multipart($parameters);
}

if (isset($parameters['json'])) {
$form = RequestOptions::JSON;
$parameters = array_except($parameters, RequestOptions::JSON);
}

return $this->execute($request, [$form => $parameters]);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Resources/Basics/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ abstract class Resource
*/
protected $disabled = [];

/**
* Should requests to add POST as JSON?
*
* @var bool
*/
protected $addPostedAsJson = false;

/**
* Endpoint constructor.
*
Expand Down Expand Up @@ -72,6 +79,10 @@ public function find($id)
*/
public function add(array $values)
{
if ($this->addPostedAsJson) {
$values['json'] = true;
}

return $this->request->post('', $values);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Leads.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Leads extends Resource
*/
protected $disabled = ['deleteBulk'];

protected $addPostedAsJson = true;

/**
* Get all labels.
*
Expand Down

0 comments on commit 3dd70c4

Please sign in to comment.