Skip to content

Commit

Permalink
Implement all nitty gritties of the laravel method
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Singhvi committed Aug 2, 2017
1 parent bcf7f0d commit 9b630e4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"php-opencloud/openstack": "^2.0",
"illuminate/support": "^5.4",
"league/flysystem": "^1.0",
"nimbusoft/flysystem-openstack-swift": "^0.2.0"
"nimbusoft/flysystem-openstack-swift": "^0.2.0",
"nesbot/carbon": "^1.22"
},
"require-dev": {
"phpunit/phpunit": "^5.5",
Expand Down
7 changes: 4 additions & 3 deletions src/OVHSwiftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sausin\LaravelOvh;

use Carbon\Carbon;
use BadMethodCallException;
use OpenStack\ObjectStore\v1\Service;
use OpenStack\Common\Error\BadResponseError;
Expand Down Expand Up @@ -89,18 +90,18 @@ public function getUrlConfirm($path)
* Generate a temporary URL for private containers.
*
* @param string $path
* @param int $expiration
* @param Carbon $expiration
* @param array $options
* @return string
*/
public function getTemporaryUrl($path, $expiration = 60 * 60, $options)
public function getTemporaryUrl($path, $expiration, $options = [])
{
if (! is_array($this->urlVars) || count($this->urlVars) !== 4) {
throw new BadMethodCallException('Insufficient Url Params', 1);
}

// expiry is relative to current time
$expiresAt = (int) (time() + $expiration);
$expiresAt = $expiration instanceof Carbon ? $expiration->timestamp : (int) (time() + 60 * 60);

// get the method
$method = isset($options['method']) ? $options['method'] : 'GET';
Expand Down
3 changes: 2 additions & 1 deletion tests/OVHSwiftAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sausin\LaravelOvh\Tests;

use Mockery;
use Carbon\Carbon;
use League\Flysystem\Config;
use Sausin\LaravelOvh\OVHSwiftAdapter;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function testTemporaryUrlMethod()
$this->object->shouldNotReceive('retrieve');
$this->container->shouldNotReceive('getObject');

$url = $this->adapter->getTemporaryUrl('hello.jpg');
$url = $this->adapter->getTemporaryUrl('hello.jpg', Carbon::now()->addMinutes(10));

$this->assertNotNull($url);
}
Expand Down

0 comments on commit 9b630e4

Please sign in to comment.