Skip to content

Commit

Permalink
Breaking: Rename package to Unikka namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
markusguenther committed Jul 14, 2020
1 parent 4cc5476 commit 8d23751
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
namespace Ttree\FilePreviews\Domain\Model\ThumbnailGenerator;
namespace Unikka\FilePreviews\Domain\Model\ThumbnailGenerator;

/*
* This file is part of the Ttree.FilePreviews package.
* This file is part of the Unikka.FilePreviews package.
*
* (c) ttree ltd - www.ttree.ch
* (c) unikka and ttree ltd
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Ttree\FilePreviews\Service\ApiClient;
use Ttree\FilePreviews\Service\FilePreviewsService;
use Unikka\FilePreviews\Service\ApiClient;
use Unikka\FilePreviews\Service\FilePreviewsService;
use Neos\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
use Neos\Flow\ResourceManagement\ResourceManager;
Expand Down
16 changes: 10 additions & 6 deletions Classes/Service/ApiClient.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace Ttree\FilePreviews\Service;
namespace Unikka\FilePreviews\Service;

/*
* This file is part of the Ttree.FilePreviews package.
* This file is part of the Unikka.FilePreviews package.
*
* (c) ttree ltd - www.ttree.ch
* (c) unikka and ttree ltd
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
Expand All @@ -13,11 +13,10 @@

use Neos\Flow\Annotations as Flow;
use Neos\Media\Exception;
use Psr\Log\LoggerInterface;

/**
* File Previews Service
*
* @api
*/
class ApiClient
{
Expand All @@ -31,6 +30,12 @@ class ApiClient
*/
protected $client;

/**
* @Flow\Inject
* @var LoggerInterface
*/
protected $logger;

/**
* FilePreviewsService constructor
*
Expand Down Expand Up @@ -83,7 +88,6 @@ public function generate($url, array $params = [])

$geometry = '';
$size = array_merge([
'height' => null,
'width' => null
], $size);

Expand Down
65 changes: 50 additions & 15 deletions Classes/Service/Client.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?php
namespace Ttree\FilePreviews\Service;

namespace Unikka\FilePreviews\Service;

/*
* This file is part of the Ttree.FilePreviews package.
* This file is part of the Unikka.FilePreviews package.
*
* (c) ttree ltd - www.ttree.ch
* (c) unikka and ttree ltd
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Guzzle\Http\Client as GuzzleClient;
use Neos\Flow\Annotations as Flow;
use GuzzleHttp\Client as GuzzleClient;
use Psr\Log\LoggerInterface;

/**
* File Previews Client Service
*
* @api
*/
class Client
{
Expand All @@ -31,9 +32,15 @@ class Client
*/
protected $config;

/**
* @Flow\Inject
* @var LoggerInterface
*/
protected $logger;

public function __construct(array $config = [])
{
$this->client = new GuzzleClient($config['api_url']);
$this->client = new GuzzleClient(['base_uri' => $config['api_url']]);
$this->config = $config;
}

Expand Down Expand Up @@ -64,10 +71,17 @@ public function getDefaultHeaders()
*/
public function get($path)
{
$request = $this->client->get($path, $this->getDefaultHeaders());
$request->setAuth($this->config['api_key'], $this->config['api_secret']);
$response = $request->send();
return json_decode($response->getBody(true));
$response = $this->client->request(
'GET',
$path,
[
'headers' => $this->getDefaultHeaders(),
'auth' => [$this->config['api_key'], $this->config['api_secret']]
]
);

$this->logger->debug('GET ' . $path, ['response' => $response]);
return json_decode($response->getBody());
}

/**
Expand All @@ -77,10 +91,31 @@ public function get($path)
*/
public function post($path, $data)
{
$request = $this->client->post($path, $this->getDefaultHeaders(), $data);
$request->setAuth($this->config['api_key'], $this->config['api_secret']);
$response = $request->send();
return json_decode($response->getBody(true));
$this->logger->debug(
'Make POST Request ' . $path,
[
'data' => $data,
'config' => $this->config
]
);
$response = $this->client->request(
'POST',
$path,
[
'headers' => $this->getDefaultHeaders(),
'auth' => [$this->config['api_key'], $this->config['api_secret']],
'body' => $data
]
);

$this->logger->debug(
'POST ' . $path,
[
'data' => $data,
'response' => $response
]
);
return json_decode($response->getBody());
}

}
2 changes: 1 addition & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Neos:
Media:
thumbnailGenerators:
'Ttree\FilePreviews\Domain\Model\ThumbnailGenerator\FilePreviewsThumbnailGenerator':
'Unikka\FilePreviews\Domain\Model\ThumbnailGenerator\FilePreviewsThumbnailGenerator':
apiKey: 'api-key'
apiSecret: 'api-secret'
maximumWaitingTime: 30
Expand Down
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
This package generate thumbnail and extract metadata from different type of document
based on the API of [filepreviews.io].

This package is Composer ready, [PSR-2] and [PSR-4] compliant.

How it work ?
-------------

Expand All @@ -21,7 +19,7 @@ Neos:
Media:
thumbnailGenerator:

'Ttree\FilePreviews\Domain\Model\ThumbnailGenerator\FilePreviewsThumbnailGenerator':
'Unikka\FilePreviews\Domain\Model\ThumbnailGenerator\FilePreviewsThumbnailGenerator':
apiKey: 'api-key'
apiSecret: 'api-secret'
maximumWaitingTime: 30
Expand All @@ -34,20 +32,30 @@ Neos:
- ```supportedExtensions```: check the official documentation of FilePreviews [Supported Formats] and enjoy.
- ```defaultOptions```: check the [API endpoint] documentation.

Acknowledgments
---------------

Development sponsored by [ttree ltd - neos solution provider](http://ttree.ch).
## Contribution

We'd love you to contribute to neos-slick. We try to make it as easy as possible.
We are using semantic versioning to have more time to concentrate on important stuff
instead of struggling in the dependency or release hell.

Therefore the first rule is to follow the [eslint commit message guideline](https://github.com/conventional-changelog-archived-repos/conventional-changelog-eslint/blob/master/convention.md).
It is really easy if you always commit via `yarn commit`. Commitizen will guide you.

All PRs will be merged into the master branch. Travis and semantic release will check the commit messages and start
building a new release when the analysis of the latest commits will trigger that.

If you have questions just ping us on Twitter or Github.

## About

We try our best to craft this package with a lots of love, we are open to sponsoring, support request, ... just contact us.
The package is based on the `Ttree\FilePreviews` package. We thank the [ttree team](https://ttree.ch) for
all the efforts and initial development.

License
-------
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.

The MIT License (MIT). Please see [LICENSE](LICENSE.txt) for more information.

[PSR-2]: http://www.php-fig.org/psr/psr-2/
[PSR-4]: http://www.php-fig.org/psr/psr-4/
[filepreviews.io]: http://filepreviews.io/
[Supported Formats]: https://filepreviews.io/docs/features/
[API endpoint]: https://filepreviews.io/docs/endpoints/
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "ttree/filepreviews",
"name": "unikka/filepreviews",
"type": "neos-package",
"license": "MIT",
"description": "Neos CMS filepreviews.io integration to generate thumbnail and extract metadata",
"description": "Neos CMS integration of filepreviews.io to generate thumbnails",
"require": {
"neos/flow": ">4.0",
"neos/media": ">3.0",
"guzzle/guzzle": "~3.9"
"neos/flow": "~5.3",
"neos/media": "~4.3",
"guzzlehttp/guzzle": "^7.0"
},
"autoload": {
"psr-4": {
"Ttree\\FilePreviews\\": "Classes"
"Unikka\\FilePreviews\\": "Classes"
}
}
}

0 comments on commit 8d23751

Please sign in to comment.