Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Urlbox/Screenshots

## Capture highly accurate webpage screenshots of any site using Urlbox.io in PHP
## Capture highly accurate webpage screenshots of any site using Urlbox.com in PHP

This package uses the [Urlbox.io](https://urlbox.io) screenshot as a service to generate website screenshots.
This package uses the [Urlbox.com](https://urlbox.com) screenshot as a service to generate website screenshots.

## Installation

Expand Down Expand Up @@ -47,11 +47,11 @@ URLBOX_SECRET=YOUR_URLBOX_SECRET
URLBOX_WEBHOOK_SECRET=YOUR_URLBOX_WEBHOOK_SECRET
```

You can find your API Credentials and Webhook Secret [here](https://www.urlbox.io/dashboard/projects)
You can find your API Credentials and Webhook Secret [here](https://www.urlbox.com/dashboard/projects)

## Usage

You will need a [Urlbox](https://urlbox.io) account to use this package. Please signup [here](https://urlbox.io/pricing) and get your API Key and Secret from the Urlbox dashboard once you have logged in.
You will need a [Urlbox](https://urlbox.com) account to use this package. Please signup [here](https://urlbox.com/pricing) and get your API Key and Secret from the Urlbox dashboard once you have logged in.

Here is a sample call to generate a Urlbox screenshot URL:

Expand All @@ -70,7 +70,7 @@ Here is a sample call to generate a Urlbox screenshot URL:

// Create the Urlbox URL
$urlboxUrl = $urlbox->generateSignedUrl( $options );
// $urlboxUrl is now 'https://api.urlbox.io/v1/API_KEY/TOKEN/png?url=example.com'
// $urlboxUrl is now 'https://api.urlbox.com/v1/API_KEY/TOKEN/png?url=example.com'

// Generate a screenshot by loading the Urlbox URL in an img tag:
echo '<img src="' . $urlboxUrl . '" alt="Test screenshot generated by Urlbox">'
Expand All @@ -83,7 +83,7 @@ use Urlbox\Screenshots\Facades\Urlbox;

$options = [ 'url' => 'example.com' ];
$urlboxUrl = Urlbox::generateUrl( $options );
// $urlboxUrl is now 'https://api.urlbox.io/v1/API_KEY/TOKEN/png?url=example.com'
// $urlboxUrl is now 'https://api.urlbox.com/v1/API_KEY/TOKEN/png?url=example.com'
```

You can now use the result (`$urlboxUrl`) by placing it inside an `<img/>` tag as the `src` parameter.
Expand All @@ -92,7 +92,7 @@ When you load the image, a screenshot of example.com will be returned.

## Options

You can find the full list of available options within the [docs](https://urlbox.io/docs/options). Below is a list of the most commonly used options:
You can find the full list of available options within the [docs](https://urlbox.com/docs/options). Below is a list of the most commonly used options:

| Option | Default | Description |
|-----------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down Expand Up @@ -130,18 +130,20 @@ You can find the full list of available options within the [docs](https://urlbox
## Other implementations

* [Node.js](https://github.com/urlbox-io/urlbox-screenshots-node)
* [Ruby](https://github.com/urlbox/urlbox-ruby)
* [Python](https://github.com/urlbox/urlbox-python)

## Contributing

We are open to pull requests.

## Security

If you discover any security related issues, please email services@urlbox.io instead of using the issue tracker.
If you discover any security related issues, please email services@urlbox.com instead of using the issue tracker.

## About Urlbox

Urlbox is a premium Screenshot as a Service API. It lets you render highly accurate screenshots of webpages and display them anywhere you like. [Urlbox.io](https://urlbox.io).
Urlbox is a premium Screenshot as a Service API. It lets you render highly accurate screenshots of webpages and display them anywhere you like. [urlbox.com](https://urlbox.com).

## License

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"authors": [
{
"name": "Chris Roebuck",
"email": "chris@urlbox.io",
"email": "chris@urlbox.com",
"role": "Developer"
}
],
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Urlbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Class Datatables.
*
* @package Urlbox\Screenshots\Facades
* @author Chris Roebuck <chris@urlbox.io>
* @author Chris Roebuck <chris@urlbox.com>
*/
class Urlbox extends Facade
{
Expand Down
21 changes: 14 additions & 7 deletions src/Urlbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Urlbox
{
private string $baseUrl = 'https://api.urlbox.io/v1';
private string $baseUrl = 'https://api.urlbox.com/v1';
private string $apiKey;
private string $apiSecret;
private ?string $webhookSecret;
Expand All @@ -36,6 +36,8 @@ public function __construct( string $apiKey, string $apiSecret, ?string $webhook
}

/**
* Ensure the user has passed an API key and secret.
*
* @param string $apiKey
* @param string $apiSecret
*
Expand All @@ -46,15 +48,17 @@ public function __construct( string $apiKey, string $apiSecret, ?string $webhook
private function ensureIsValidCredentials( string $apiKey, string $apiSecret )
{
if ( empty( $apiKey ) ) {
throw new InvalidArgumentException( 'Requires an api key - https://www.urlbox.io/dashboard/projects' );
throw new InvalidArgumentException( 'Requires an api key - https://www.urlbox.com/dashboard/projects' );
}

if ( empty( $apiSecret ) ) {
throw new InvalidArgumentException( 'Requires an api secret - https://www.urlbox.io/dashboard/projects' );
throw new InvalidArgumentException( 'Requires an api secret - https://www.urlbox.com/dashboard/projects' );
}
}

/**
* Returns a new instance of Urlbox
*
* @param string $apiKey
* @param string $apiSecret
* @param string|null $webhookSecret
Expand All @@ -69,8 +73,9 @@ public static function fromCredentials( string $apiKey, string $apiSecret, ?stri
}

/**
* Calls the Urlbox /sync endpoint
* @param array $options
* @param string|null $saveToDiskPath
* @param string|null $saveToDiskPath - A path to save the image to
*
* @return array{renderUrl: string, size: int, localPath: string}
* @throws GuzzleException
Expand All @@ -89,8 +94,9 @@ public function render( array $options, ?string $saveToDiskPath = null ): array
}

/**
* @param string $endpoint
* @param array $options
* Make a POST request to Urlbox
* @param string $endpoint - The endpoint EG /sync
* @param array $options - The render options
*
* @return array{renderUrl: string, size: int}
* @throws GuzzleException
Expand Down Expand Up @@ -201,6 +207,7 @@ private function encodeURIComponent( string $value ): string
}

/**
* Verifies the signature of an incoming webhook request to ensure its authenticity.
* @param string $header
* @param string $content
*
Expand All @@ -210,7 +217,7 @@ private function encodeURIComponent( string $value ): string
public function verifyWebhookSignature( string $header, string $content ): bool
{
if ( empty( $this->webhookSecret ) ) {
throw new Exception( 'Unable to verify signature as Webhook Secret is not set. You can find your webhook secret inside your project\'s settings - https://www.urlbox.io/dashboard/projects' );
throw new Exception( 'Unable to verify signature as Webhook Secret is not set. You can find your webhook secret inside your project\'s settings - https://www.urlbox.com/dashboard/projects' );
}

if ( empty( $header ) ) {
Expand Down
Loading