Skip to content

Commit

Permalink
Merge pull request #73 from pipedrive/GRAL-3076-get-all-person-fields…
Browse files Browse the repository at this point in the history
…-with-pagination

GRAL-3076 Added pagination support to getAllPersonFields
  • Loading branch information
SpaceOven committed Aug 8, 2022
2 parents f68f905 + 9911657 commit 74690a7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4852,16 +4852,25 @@ $personFields->deleteMultiplePersonFieldsInBulk($ids);
```php
function getAllPersonFields()
```
#### Parameters

| Parameter | Tags | Description |
|-----------|------|-------------|
| start | ``` Optional ``` ``` DefaultValue ``` | Pagination start |
| limit | ``` Optional ``` | Items shown per page |

#### Example Usage

```php
$start = 0;
$collect['start'] = $start;

$personFields->getAllPersonFields();
$limit = 69;
$collect['limit'] = $limit;

$personFields->getAllPersonFields($collect);
```


### <a name="add_a_new_person_field"></a>![Method: ](https://apidocs.io/img/method.png ".PersonFieldsController.addANewPersonField") addANewPersonField

> Adds a new person field. For more information on adding a new custom field, see <a href="https://pipedrive.readme.io/docs/adding-a-new-custom-field" target="_blank" rel="noopener noreferrer">this tutorial</a>.
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BaseController
* User-agent to be sent with API calls
* @var string
*/
const USER_AGENT = 'Pipedrive-SDK-PHP-4.0.0';
const USER_AGENT = 'Pipedrive-SDK-PHP-4.0.3';

/**
* HttpCallBack instance associated with this controller
Expand Down
13 changes: 11 additions & 2 deletions src/Controllers/PersonFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,26 @@ public function deleteMultiplePersonFieldsInBulk(
/**
* Returns data about all person fields
*
* @param integer $options['limit'] (optional) For pagination, the limit of entries to be returned
* @param integer $options['start'] (optional) For pagination, the position that represents the first result for the page
* @return \Pipedrive\Utils\JsonSerializer response from the API call
* @throws APIException Thrown if API call fails
*/
public function getAllPersonFields()
{
public function getAllPersonFields(
$options = array()
) {
//check or get oauth token
OAuthManager::getInstance()->checkAuthorization();

//prepare query string for API call
$_queryBuilder = '/personFields';

//process optional query parameters
APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
'start' => $this->val($options, 'start', 0),
'limit' => $this->val($options, 'limit'),
));

//validate and preprocess url
$_queryUrl = APIHelper::cleanUrl(Configuration::getBaseUri() . $_queryBuilder);

Expand Down
6 changes: 5 additions & 1 deletion src/Utils/CamelCaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ class CamelCaseHelper
{
public static function keysToCamelCase($input)
{
if ($input instanceof \DateTime) {
if (is_null($input)) {
return null;
}

if ($input instanceof \DateTime || is_string($input)) {
return $input;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Controllers/PersonFieldsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ protected function setUp()
*/
public function testTestGetAllPersonFields()
{
// Parameters for the API call
$input = array();
$input['start'] = 0;
$input['limit'] = null;

// Set callback and perform API call
self::$controller->setHttpCallBack($this->httpResponse);
try {
self::$controller->getAllPersonFields();
self::$controller->getAllPersonFields($input);
} catch (APIException $e) {
}

Expand Down

0 comments on commit 74690a7

Please sign in to comment.