Show if there's a new version available on the admin dashboard #143

This commit is contained in:
Nabeel Shahzad
2018-01-19 18:44:17 -05:00
parent a1b9894f97
commit 2cd45acbdf
6 changed files with 114 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Facades;
use GuzzleHttp\Client;
use \Illuminate\Support\Facades\Facade;
class Utils extends Facade
@@ -11,6 +12,33 @@ class Utils extends Facade
return 'utils';
}
/**
* Download a URI. If a file is given, it will save the downloaded
* content into that file
* @param $uri
* @param null $file
* @return string
* @throws \RuntimeException
*/
public static function downloadUrl($uri, $file=null)
{
$opts = [];
if($file !== null) {
$opts['sink'] = $file;
}
$client = new Client();
$response = $client->request('GET', $uri, $opts);
$body = $response->getBody()->getContents();
if($response->getHeader('content-type') === 'application/json') {
$body = \GuzzleHttp\json_decode($body);
}
return $body;
}
/**
* Returns a 40 character API key that a user can use
* @return string