-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from Kovah/dev
v0.0.12
- Loading branch information
Showing
13 changed files
with
251 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
branches: | ||
only: | ||
- master | ||
|
||
language: php | ||
php: | ||
- '7.1.3' | ||
- '7.2' | ||
- '7.3' | ||
|
||
install: | ||
- cp .env.example .env | ||
- composer install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Helper; | ||
|
||
use GuzzleHttp\Client; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
/** | ||
* Class WaybackMachine | ||
* | ||
* @package App\Helper | ||
*/ | ||
class WaybackMachine | ||
{ | ||
/** @var string */ | ||
public static $base_url = 'https://web.archive.org'; | ||
|
||
/** | ||
* Save an URL to the Wayback Machine | ||
* | ||
* @param string $url | ||
* @return bool | ||
*/ | ||
public static function saveToArchive(string $url): bool | ||
{ | ||
if (!filter_var($url, FILTER_VALIDATE_URL)) { | ||
// Abort if provided string is not an URL | ||
return false; | ||
} | ||
|
||
$archive_url = self::$base_url . '/save/' . $url; | ||
|
||
try { | ||
|
||
$client = new Client(); | ||
$client->request('GET', $archive_url, [ | ||
'http_errors' => false, | ||
]); | ||
|
||
} catch (\GuzzleHttp\Exception\GuzzleException $e) { | ||
Log::warning($e); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Get the link to the Wayback Machine archive for a specific URL | ||
* | ||
* @param string $url | ||
* @return null|string | ||
*/ | ||
public static function getArchiveLink(string $url): ?string | ||
{ | ||
if (!filter_var($url, FILTER_VALIDATE_URL)) { | ||
// Abort if provided string is not an URL | ||
return null; | ||
} | ||
|
||
return self::$base_url . '/web/*/' . $url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Helper; | ||
|
||
use App\Models\Link; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* Class HelperFunctionsTest | ||
* | ||
* @package Tests\Unit\Helper | ||
*/ | ||
class HelperFunctionsTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
use DatabaseTransactions; | ||
|
||
/** @var User */ | ||
private $user; | ||
|
||
/** @var Link */ | ||
private $link; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = factory(User::class)->create(); | ||
$this->link = factory(Link::class)->create(); | ||
} | ||
|
||
/** | ||
* Test the saveToArchive() helper funtion with a valid URL. | ||
* Should return true. | ||
* | ||
* @return void | ||
*/ | ||
public function testValidWaybackLink(): void | ||
{ | ||
$expected = 'https://web.archive.org/web/*/' . $this->link->url; | ||
|
||
$link = waybackLink($this->link); | ||
|
||
$this->assertEquals($expected, $link); | ||
} | ||
|
||
/** | ||
* Test the saveToArchive() helper funtion with an invalid URL. | ||
* Will return false. | ||
* | ||
* @return void | ||
*/ | ||
public function testInvalidWaybackLink(): void | ||
{ | ||
$url = 'not an URL'; | ||
|
||
$link = waybackLink($url); | ||
|
||
$this->assertNull($link); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.