PHPackages                             enlight/pingping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. enlight/pingping

ActiveLibrary[API Development](/categories/api)

enlight/pingping
================

Easy PingPing API Connector for Laravel

v0.0.1(5y ago)151372[1 issues](https://github.com/bhushan/pingping/issues)MITPHPPHP &gt;=7.2.5

Since Apr 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bhushan/pingping)[ Packagist](https://packagist.org/packages/enlight/pingping)[ RSS](/packages/enlight-pingping/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

PingPing
========

[](#pingping)

This composer package allows us to easily integrate `PingPing` APIs in your `Laravel` project.

> What is PingPing ?
>
> PingPing is the simplest uptime monitoring service in the world to get notified, when your website is down or your certificate becomes invalid. No more, no less.

Installation
------------

[](#installation)

### Step 1: Composer

[](#step-1-composer)

Firstly require this package using following command.

```
composer require enlight/pingping
```

### Step 2: Service Provider (Optional)

[](#step-2-service-provider-optional)

This package support's auto discovery but for any reason you need to add `ServiceProvider`into `providers` array manually then check follow steps below.

Open `config/app.php` and, within the `providers` array, append:

```
Enlight\PingPing\Providers\PingPingServiceProvider::class
```

This will bootstrap the package into Laravel.

### Step 3: Set Up Environment

[](#step-3-set-up-environment)

Check your `.env` file, and ensure that your `PING_PING_API_TOKEN` is set with valid token.

> You can get the token from below link and make sure it is enabled.
>
>

You are all set to use it.

### Step 4: Publish Configuration (Optional)

[](#step-4-publish-configuration-optional)

Optionally, You can publish configuration file, so you can modify defaults values.

To Publish Configuration Run

```
php artisan vendor:publish --provider="Enlight\PingPing\Providers\PingPingServiceProvider" --tag="config"
```

Exported config you can find in `/config` folder as `pingping.php`.

Usage
-----

[](#usage)

All methods and API calls will return `Illuminate\Http\Client\Response` instance. That mean's, you have access to following methods.

```
$response->body() : string;
$response->json() : array|mixed;
$response->collect() : Illuminate\Support\Collection;
$response->status() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->failed() : bool;
$response->serverError() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;
```

### Retrieve all websites (monitors)

[](#retrieve-all-websites-monitors)

```
    use Enlight\PingPing\Client;

    public function index(Client $client)
    {
        $response = $client->monitors();

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

### Retrieve a specific website (monitor)

[](#retrieve-a-specific-website-monitor)

```
    use Enlight\PingPing\Client;

    public function show($id, Client $client)
    {
        $response = $client->monitors((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

### Retrieve statistics from a specific website (monitor)

[](#retrieve-statistics-from-a-specific-website-monitor)

```
    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;

    /**
     * @throws MonitorIDRequiredException
     */
    public function show($id, Client $client)
    {
        $response = $client->statistics((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

### Create a website (monitor)

[](#create-a-website-monitor)

```
    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\ValidUrlRequiredException;

    /**
     * @throws ValidUrlRequiredException
     */
    public function store(Client $client)
    {
        $url = 'https://my-cool-website.test';

        $response = $client->createMonitor($url);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

### Update a website (monitor)

[](#update-a-website-monitor)

```
    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\AliasRequiredException;
    use Enlight\PingPing\Exceptions\ValidUrlRequiredException;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;

    /**
     * @throws AliasRequiredException
     * @throws ValidUrlRequiredException
     * @throws MonitorIDRequiredException
     */
    public function update($id, Client $client)
    {
        $url = 'https://my-cool-website2.test';
        $alias = 'My cool website2';

        $response = $client->updateMonitor((int) $id, $url, $alias);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

### Delete a website (monitor)

[](#delete-a-website-monitor)

```
    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;

    /**
     * @throws MonitorIDRequiredException
     */
    public function destroy($id, Client $client)
    {
        $response = $client->deleteMonitor((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
```

Finally, your updated controllers might look like this now.

```
