Skip to content

Commit

Permalink
Merge pull request #121 from jr-k/patch-3
Browse files Browse the repository at this point in the history
Search for Lead Resource and fix Lead update
  • Loading branch information
IsraelOrtuno authored Nov 7, 2022
2 parents 90afeba + e5c320b commit 39e6490
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function buildEndpoint($options = [])
continue;
}

if (is_object($value)) {
if (isset($value->id)) {
$value = $value->id;
} else {
continue;
}
}

$endpoint = preg_replace("/:{$key}/", $value, $endpoint);
}

Expand Down
28 changes: 28 additions & 0 deletions src/Http/PipedriveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ public function put($url, $parameters = [])
return $this->execute($request, ['form_params' => $parameters]);
}

/**
* Perform a PATCH request.
*
* @param $url
* @param array $parameters
* @return Response
*/
public function patch($url, $parameters = [])
{
$request = new GuzzleRequest('PATCH', $url);
$form = 'form_params';

// If any file key is found, we will assume we have to convert the data
// into the multipart array structure. Otherwise, we will perform the
// request as usual using the form_params with the given parameters.
if (isset($parameters['file'])) {
$form = 'multipart';
$parameters = $this->multipart($parameters);
}

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

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

/**
* Perform a DELETE request.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @method Response get($type, $target, $options = [])
* @method Response post($type, $target, $options = [])
* @method Response put($type, $target, $options = [])
* @method Response patch($type, $target, $options = [])
* @method Response delete($type, $target, $options = [])
*/
class Request
Expand Down Expand Up @@ -143,7 +144,7 @@ public function setToken($token)
*/
public function __call($name, $args = [])
{
if (in_array($name, ['get', 'post', 'put', 'delete'])) {
if (in_array($name, ['get', 'post', 'put', 'patch', 'delete'])) {
$options = !empty($args[1]) ? $args[1] : [];

// Will pass the function name as the request type. The second argument
Expand Down
19 changes: 18 additions & 1 deletion src/Resources/Leads.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Devio\Pipedrive\Http\Response;
use Devio\Pipedrive\Resources\Basics\Resource;
use Devio\Pipedrive\Resources\Traits\Searches;

class Leads extends Resource
{
use Searches;

/**
* Disabled abstract methods.
*
Expand Down Expand Up @@ -60,13 +63,27 @@ public function deleteLabel($id)
* @param array $values
* @return Response
*/
public function update($id, array $values = [])
public function updateLabel($id, array $values = [])
{
$this->request->setResource('leadLabels');

return $this->request->put('/' . $id, $values);
}

/**
* @param $id
* @param array $values
* @return Response
*/
public function update($id, array $values = [])
{
$values['json'] = true;

array_set($values, 'id', $id);

return $this->request->patch(':id', $values);
}

/**
* Get all sources.
*
Expand Down

0 comments on commit 39e6490

Please sign in to comment.