|
| 1 | +# Keboola Storage API PHP Client |
| 2 | + |
| 3 | +[](https://packagist.org/packages/keboola/storage-api-client) |
| 4 | +[](https://packagist.org/packages/keboola/storage-api-client) |
| 5 | +[](https://packagist.org/packages/keboola/storage-api-client) |
| 6 | +[](https://github.com/keboola/storage-api-php-client/actions/workflows/tag.yml) |
| 7 | + |
| 8 | +Simple PHP wrapper library for [Keboola Storage API](http://docs.keboola.apiary.io/). |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +Library is available as composer package. |
| 13 | +To start using composer in your project follow these steps: |
| 14 | + |
| 15 | +**Install composer** |
| 16 | + |
| 17 | +```bash |
| 18 | +curl -s http://getcomposer.org/installer | php |
| 19 | +mv ./composer.phar ~/bin/composer # or /usr/local/bin/composer |
| 20 | +``` |
| 21 | + |
| 22 | +**Create composer.json file in your project root folder:** |
| 23 | +```json |
| 24 | +{ |
| 25 | + "require": { |
| 26 | + "php" : ">=8.1", |
| 27 | + "keboola/storage-api-client": "^14.0" |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +**Install package:** |
| 33 | + |
| 34 | +```bash |
| 35 | +composer install |
| 36 | +``` |
| 37 | + |
| 38 | +**Add autoloader in your bootstrap script:** |
| 39 | + |
| 40 | +```php |
| 41 | +require 'vendor/autoload.php'; |
| 42 | +``` |
| 43 | + |
| 44 | +Read more in [Composer documentation](http://getcomposer.org/doc/01-basic-usage.md). |
| 45 | + |
| 46 | +## Usage examples |
| 47 | + |
| 48 | +Table write: |
| 49 | + |
| 50 | +```php |
| 51 | +require 'vendor/autoload.php'; |
| 52 | + |
| 53 | +use Keboola\StorageApi\Client; |
| 54 | +use Keboola\Csv\CsvFile; |
| 55 | + |
| 56 | +$client = new Client([ |
| 57 | + 'token' => 'YOUR_TOKEN', |
| 58 | + 'url' => 'https://connection.keboola.com' |
| 59 | +]); |
| 60 | +$csvFile = new CsvFile(__DIR__ . '/my.csv', ',', '"'); |
| 61 | +$client->writeTableAsync('in.c-main.my-table', $csvFile); |
| 62 | +``` |
| 63 | + |
| 64 | +Table export to file: |
| 65 | + |
| 66 | +```php |
| 67 | +require 'vendor/autoload.php'; |
| 68 | + |
| 69 | +use Keboola\StorageApi\Client; |
| 70 | +use Keboola\StorageApi\TableExporter; |
| 71 | + |
| 72 | +$client = new Client([ |
| 73 | + 'token' => 'YOUR_TOKEN', |
| 74 | + 'url' => 'https://connection.keboola.com' |
| 75 | +]); |
| 76 | + |
| 77 | +$exporter = new TableExporter($client); |
| 78 | +$exporter->exportTable('in.c-main.my-table', './in.c-main.my-table.csv', []); |
| 79 | + |
| 80 | +``` |
| 81 | + |
| 82 | +## License |
| 83 | + |
| 84 | +See [LICENSE](./LICENSE) file. |
0 commit comments