issetbv/alfredo-laravel
Alfredo for Laravel
This package is merely an Alfredo wrapper written for Laravel. It will ease a lot of the tasks provided from the Alfredo client.
Table of Contents
- Create payload
- Add source to payload
- Create payload with converter type
- Create payload with callback url for queues
- Create payload with sources
- Convert a payload
- Stream a payload or converted payload
- Queue a payload
- Check if a queued payload has been converted
- Get converted payload from queue
- Stream converted payload from queue
```json
"issetbv/alfredo-laravel": "dev-master"
```
-
Update dependencies
composer update -
Publish configuration file
php artisan config:publish issetbv/alfredo-laravel -
Add Service Provider to the
providersarray inapp/config/app.php'IssetBv\AlfredoLaravel\AlfredoServiceProvider', -
Add Facade to the
facadesarray inapp/config/app.php'Alfredo' => 'IssetBv\AlfredoLaravel\Facade', -
Add API keys to the configuration file in
app/config/packages/issetbv/alfredo-laravel/config.php
Available: addHtml, addPdf, addUrl
$payload = Alfredo::makePayload();
$payload->addUrl('http://isset.nl');
**Create payload with converter type**
```php
$payload = Alfredo::makePayloadWithConverter('htmltopdfjava');
```
**Create payload with callback url for queues**
```php
$payload = Alfredo::makePayloadWithCallback('http://example.com/callback_url');
```
**Create payload with sources**
Available: html, pdf, url
$payload = Alfredo::makePayloadWithSources(array(
array('url', 'http://isset.nl'),
array('html', '<html><thead></thead><tbody>Create payload with sources!</tbody></html>')
));
**Convert a payload**
```php
$payload = Alfredo::makePayload();
$payload->addHtml('Converting a payload!');
$pdf = Alfredo::convert($payload);
```
**Stream a payload or converted payload**
Stream a payload:
$payload = Alfredo::makePayload();
$payload->addHtml('<html><thead></thead><tbody>Streaming a payload!</tbody></html>');
$response = Alfredo::stream($payload); // returns a Response object
Stream a converted payload:
$payload = Alfredo::makePayload();
$payload->addHtml('<html><thead></thead><tbody>Streaming a converted payload!</tbody></html>');
$pdf = Alfredo::convert($payload);
$response = Alfredo::stream($pdf); // returns a Response object
**Queue a payload**
When using the queue, its necessary to set the callback url.
$payload = Alfredo::makePayloadWithCallback('http://example.com/callback_url');
$payload->addHtml('<html><thead></thead><tbody>Queueing a payload!</tbody></html>');
$response = Alfredo::queue($payload); // returns a JSON response
{
"response":"Queued",
"identifier":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
**Check if a queued payload has been converted**
```php
if (Alfredo::checkQueuedPayload('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')) { // returns a boolean
// Payload has been converted and is ready to be downloaded
}
```
**Get converted payload from queue**
```php
$pdf = Alfredo::getQueuedPayload('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
```
**Stream converted payload from queue**
```php
$pdf = Alfredo::getQueuedPayload('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$response = Alfredo::stream($pdf);
```
License
MIT