Skip to content

Commit

Permalink
Take full-page browser screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
sander3 committed Nov 14, 2020
1 parent 5e8bf69 commit e573424
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"type": "library",
"require": {
"php": "^7.4",
"laravel/support": "^7.0|^8.0"
"guzzlehttp/guzzle": "^6.5",
"illuminate/http": "^7.0|^8.0",
"illuminate/support": "^7.0|^8.0"
},
"require-dev": {
"orchestra/testbench": "^5.2",
Expand Down
5 changes: 4 additions & 1 deletion config/snapshot.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php

return [];
return [
'endpoint' => env('SNAPSHOT_ENDPOINT'),
'api_token' => env('SNAPSHOT_API_TOKEN'),
];
10 changes: 10 additions & 0 deletions src/Contracts/Snapshot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Soved\Laravel\Snapshot\Contracts;

use GuzzleHttp\Psr7\Stream;

interface Snapshot
{
public function take(string $url): Stream;
}
25 changes: 25 additions & 0 deletions src/Snapshot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Soved\Laravel\Snapshot;

use GuzzleHttp\Psr7\Stream;
use Illuminate\Support\Facades\Http;
use Soved\Laravel\Snapshot\Contracts\Snapshot as SnapshotContract;

class Snapshot implements SnapshotContract
{
public function take(string $url): Stream
{
$parameters = [
'url' => $url,
];

$response = Http::withToken(config('snapshot.api_token'))
->post(config('snapshot.endpoint'), $parameters);

// Throw an exception if a client or server error occurred...
$response->throw();

return $response->getBody();
}
}
3 changes: 3 additions & 0 deletions src/SnapshotServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;
use Illuminate\Foundation\Application as LaravelApplication;
use Soved\Laravel\Snapshot\Contracts\Snapshot as SnapshotContract;

class SnapshotServiceProvider extends ServiceProvider
{
Expand All @@ -26,6 +27,8 @@ public function register()
{
$this->configure();
$this->offerPublishing();

$this->app->singleton(SnapshotContract::class, Snapshot::class);
}

/**
Expand Down

0 comments on commit e573424

Please sign in to comment.