Skip to content

Commit

Permalink
Adding support to map array params to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmiller committed Feb 26, 2020
1 parent 8742ffd commit 15d2e91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/recurly/pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ public function __construct(\Recurly\BaseClient $client, string $path, ?array $p
{
$this->_client = $client;
$this->_path = $path;
$this->_params = $params;
$this->_params = $this->_mapArrayParams($params);
}

/**
* Maps parameters with array values into csv strings. The API expects these
* values to be csv strings, but an array is a nicer interface for developers.
*
* @param array $params
*
* @return array
*/
private function _mapArrayParams(?array $params = []): ?array
{
if (!is_null($params)) {
array_walk($params, function(&$param, $key) {
if (is_array($param)) {
$param = join(',', $param);
}
});
}
return $params;
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/BaseClient_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function testDeleteResource204(): void
$result = "";
$this->client->addScenario("DELETE", $url, NULL, $result, "204 No Content");
$empty = $this->client->deleteResource("iexist");
$this->assertInstanceOf(\Recurly\EmptyResource::class, $empty);
}

public function testUpdateResource200(): void
Expand Down

0 comments on commit 15d2e91

Please sign in to comment.