Skip to content

Commit

Permalink
Nullable callback webhook, filter multipart fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlive committed Sep 20, 2024
1 parent 02f0f53 commit b4ae779
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Geocodio.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function uploadList(
string $file,
GeocodeDirection $direction,
string $format,
string $callbackWebhook = '',
?string $callbackWebhook = null,
): array {
if (! file_exists($file)) {
throw GeocodioException::fileNotFound($file);
Expand All @@ -156,7 +156,7 @@ public function uploadInlineList(
string $filename,
GeocodeDirection $direction,
string $format,
string $callbackWebhook = '',
?string $callbackWebhook = null,
): array {
$response = $this->uploadMultipartFile(
$data,
Expand Down Expand Up @@ -295,14 +295,14 @@ protected function uploadMultipartFile(
string $fileContents,
GeocodeDirection $direction,
string $format,
string $callbackWebhook,
?string $callbackWebhook = null,
?string $filename = null
): Response {
if (is_file($fileContents) && ! file_exists($fileContents)) {
throw GeocodioException::fileNotFound($fileContents);
}

$multipart = [
$multipart = array_filter([
[
'name' => 'file',
'contents' => is_file($fileContents) ? fopen($fileContents, 'r') : $fileContents,
Expand All @@ -320,7 +320,7 @@ protected function uploadMultipartFile(
'name' => 'callback',
'contents' => $callbackWebhook,
],
];
], fn ($block) => $block['contents']);

return $this->sendRequest('POST', 'lists', [RequestOptions::MULTIPART => $multipart]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
expect($body)->toContain('name="file"');
expect($body)->toContain('name="direction"');
expect($body)->toContain('name="format"');
expect($body)->toContain('name="callback"');

// Assert specific values
expect($body)->toContain('filename="simple.csv"');
Expand All @@ -75,7 +74,8 @@
$csvData,
'coffee-shops.csv',
GeocodeDirection::Forward,
'{{B}} {{C}} {{D}} {{E}}'
'{{B}} {{C}} {{D}} {{E}}',
'https://example.com/callbacks/file-upload'
);

$history = $http->history();
Expand Down

0 comments on commit b4ae779

Please sign in to comment.