Skip to content

Commit

Permalink
Documented support to import from a CSV file
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Feb 6, 2021
1 parent 40f9f12 commit 9295156
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ This module can be installed using composer:

## Supported import sources

* Bit.ly
* Standard CSV
#### Bit.ly

It imports using the API v4. The only required param is an [access token](https://bitly.is/accesstoken).

#### Standard CSV

It parses a CSV file with the `Long URL` and `Short code` columns. It can optionally contain `Domain`, `Title` and `Tags`, being the latter a pipe-separated list of items (`foo|bar|baz`).

Column names can have spaces and have any combination of upper and lowercase.

## Usage

Expand Down
7 changes: 6 additions & 1 deletion src/Sources/Csv/CsvImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function import(array $rawParams): iterable
yield new ImportedShlinkUrl(
ImportSources::CSV,
$record['longurl'],
array_filter(explode(self::TAG_SEPARATOR, $this->nonEmptyValueOrNull($record, 'tags') ?? '')),
$this->parseTags($record),
$now,
$this->nonEmptyValueOrNull($record, 'domain'),
$record['shortcode'],
Expand Down Expand Up @@ -73,4 +73,9 @@ private function nonEmptyValueOrNull(array $record, string $key): ?string

return $trimmedValue;
}

private function parseTags(array $record): array
{
return array_filter(explode(self::TAG_SEPARATOR, $this->nonEmptyValueOrNull($record, 'tags') ?? ''));
}
}

0 comments on commit 9295156

Please sign in to comment.