Skip to content

Commit 120a3eb

Browse files
committed
Add a new Google Sheet loader
1 parent 21fb418 commit 120a3eb

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/DSL/functions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ function to_google_sheet(
9090
$sheets = google_sheets($auth_config, Sheets::SPREADSHEETS);
9191
}
9292

93-
return (new GoogleSheetLoader($sheets, $spreadsheet_id, $sheet_name, $value_input_option))
94-
->withHeader($with_header);
93+
return (new GoogleSheetLoader($sheets, $spreadsheet_id, $sheet_name))
94+
->withHeader($with_header)
95+
->withInputOption($value_input_option);
9596
}
9697

9798
/**

src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/GoogleSheetLoader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ final class GoogleSheetLoader implements Loader, Loader\Closure
1616

1717
private string $dateTimeFormat = 'Y-m-d H:i:s';
1818

19+
private ValueInputOption $inputOption = ValueInputOption::USER_ENTERED;
20+
1921
private int $loadedRows = 0;
2022

2123
private string $timeFormat = 'H:i';
@@ -26,7 +28,6 @@ public function __construct(
2628
private readonly Sheets $service,
2729
private readonly string $spreadsheetId,
2830
private readonly string $sheetName,
29-
private readonly ValueInputOption $inputOption,
3031
) {
3132
}
3233

@@ -89,6 +90,13 @@ public function withHeader(bool $withHeader) : self
8990
return $this;
9091
}
9192

93+
public function withInputOption(ValueInputOption $inputOption) : self
94+
{
95+
$this->inputOption = $inputOption;
96+
97+
return $this;
98+
}
99+
92100
public function withTimeFormat(string $timeFormat) : self
93101
{
94102
$this->timeFormat = $timeFormat;

src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/RowsNormalizer/EntryNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
{
1313
public function __construct(
1414
private Caster $caster,
15-
private string $dateTimeFormat = \DateTimeInterface::ATOM,
16-
private string $dateFormat = 'Y-m-d',
17-
private string $timeFormat = 'H:i',
15+
private string $dateTimeFormat,
16+
private string $dateFormat,
17+
private string $timeFormat,
1818
) {
1919
}
2020

src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/GoogleSheetLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function test_load_with_headers() : void
2828
$sheetsMock,
2929
'1234567890',
3030
'Sheet',
31-
ValueInputOption::RAW
3231
);
32+
$loader->withInputOption(ValueInputOption::RAW);
3333

3434
$loader->load(
3535
rows(
@@ -52,10 +52,10 @@ public function test_load_without_headers() : void
5252
$loader = new GoogleSheetLoader(
5353
$sheetsMock,
5454
'1234567890',
55-
'Sheet',
56-
ValueInputOption::RAW
55+
'Sheet'
5756
);
5857
$loader->withHeader(false);
58+
$loader->withInputOption(ValueInputOption::RAW);
5959

6060
$loader->load(
6161
rows(

src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/RowsNormalizer/EntryNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function setUp() : void
2727
{
2828
$this->normalizer = new EntryNormalizer(
2929
Caster::default(),
30-
\DateTimeInterface::ATOM,
30+
'Y-m-d H:i:s',
3131
'Y-m-d',
3232
'H:i'
3333
);
@@ -50,7 +50,7 @@ public function test_normalize_datetime_entry() : void
5050

5151
$result = $this->normalizer->normalize($entry);
5252

53-
self::assertEquals($dateTime->format(\DateTimeInterface::ATOM), $result);
53+
self::assertEquals($dateTime->format('Y-m-d H:i:s'), $result);
5454
}
5555

5656
public function test_normalize_default_entry() : void

0 commit comments

Comments
 (0)