Skip to content

Commit e573424

Browse files
committed
Take full-page browser screenshots
1 parent 5e8bf69 commit e573424

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"type": "library",
66
"require": {
77
"php": "^7.4",
8-
"laravel/support": "^7.0|^8.0"
8+
"guzzlehttp/guzzle": "^6.5",
9+
"illuminate/http": "^7.0|^8.0",
10+
"illuminate/support": "^7.0|^8.0"
911
},
1012
"require-dev": {
1113
"orchestra/testbench": "^5.2",

config/snapshot.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
22

3-
return [];
3+
return [
4+
'endpoint' => env('SNAPSHOT_ENDPOINT'),
5+
'api_token' => env('SNAPSHOT_API_TOKEN'),
6+
];

src/Contracts/Snapshot.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Soved\Laravel\Snapshot\Contracts;
4+
5+
use GuzzleHttp\Psr7\Stream;
6+
7+
interface Snapshot
8+
{
9+
public function take(string $url): Stream;
10+
}

src/Snapshot.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Soved\Laravel\Snapshot;
4+
5+
use GuzzleHttp\Psr7\Stream;
6+
use Illuminate\Support\Facades\Http;
7+
use Soved\Laravel\Snapshot\Contracts\Snapshot as SnapshotContract;
8+
9+
class Snapshot implements SnapshotContract
10+
{
11+
public function take(string $url): Stream
12+
{
13+
$parameters = [
14+
'url' => $url,
15+
];
16+
17+
$response = Http::withToken(config('snapshot.api_token'))
18+
->post(config('snapshot.endpoint'), $parameters);
19+
20+
// Throw an exception if a client or server error occurred...
21+
$response->throw();
22+
23+
return $response->getBody();
24+
}
25+
}

src/SnapshotServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\ServiceProvider;
66
use Laravel\Lumen\Application as LumenApplication;
77
use Illuminate\Foundation\Application as LaravelApplication;
8+
use Soved\Laravel\Snapshot\Contracts\Snapshot as SnapshotContract;
89

910
class SnapshotServiceProvider extends ServiceProvider
1011
{
@@ -26,6 +27,8 @@ public function register()
2627
{
2728
$this->configure();
2829
$this->offerPublishing();
30+
31+
$this->app->singleton(SnapshotContract::class, Snapshot::class);
2932
}
3033

3134
/**

0 commit comments

Comments
 (0)