Easily Integrate PingPing APIs in your Laravel Project

Overview

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

Step 1: Composer

Firstly require this package using following command.

composer require enlight/pingping

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

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.

https://pingping.io/account/settings

You are all set to use it.

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

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)

    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)

    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)

    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)

    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)

    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)

    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.



declare(strict_types=1);

namespace App\Http\Controllers;

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

class MonitorController extends Controller
{
    /** @var Client */
    private $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

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

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

        return $response->json();
    }

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

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

        return $response->json();
    }

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

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

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

        return $response->json();
    }

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

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

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

        return $response->json();
    }

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

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

        return $response->json();
    }
}


declare(strict_types=1);

namespace App\Http\Controllers;

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

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

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

        return $response->json();
    }
}

Contributors

This package is inspired by the Steve's blog post on Working with third party services in Laravel . I highly recommend you to read it.

Thank You :)

Happy Coding.

Issues
Please see the Diglactic fork.

Update: 18 October 2020 There is now an official fork of Laravel Breadcrumbs: https://github.com/diglactic/laravel-breadcrumbs Blog post: https://news

Dave James Miller 2.4k Jun 17, 2021
Inertia.js Events for Laravel Dusk

Inertia.js Events for Laravel Dusk Requirements PHP 7.4+ Vue Laravel 8.0 and higher Support We proudly support the community by developing Laravel pac

Protone Media 9 Jun 14, 2021
Laravel Stats Tracker

Laravel Stats Tracker Tracker gathers a lot of information from your requests to identify and store: Sessions Page Views (hits on routes) Users (logge

Antonio Carlos Ribeiro 2.6k Jun 13, 2021
A web installer for Laravel

Laravel Web Installer | A Web Installer Package About Requirements Installation Routes Usage Contributing Help Screenshots License About Do you want y

Rachid Laasri 1.7k Jun 13, 2021
Awes.io // boilerplate based on Vue, Nuxt, TailwindCSS plus Laravel as a backend. 🤟

Platform for Interactive Business Applications 10x faster to create than the traditional way • 3x increase application experiences • 60% decrease in d

Awes.io 640 Jun 15, 2021
jQuery DataTables API for Laravel 4|5|6|7|8

jQuery DataTables API for Laravel 4|5|6|7|8 This package is created to handle server-side works of DataTables jQuery Plugin via AJAX option by using E

Arjay Angeles 3.9k Jun 14, 2021
A sample application with a multistep form built with Livewire.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

David Grzyb 5 Jun 2, 2021
Simple user messaging package for Laravel

Laravel Messenger This package will allow you to add a full user messaging system into your Laravel application. Leave some feedback How are you using

Chris Gmyr 2k Jun 14, 2021
Laravel Backend for Learnbot app

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Mobile & Backend developer 4 May 18, 2021
Laravel Ban simplify blocking and banning Eloquent models.

Laravel Ban Introduction Laravel Ban simplify management of Eloquent model's ban. Make any model bannable in a minutes! Use case is not limited to Use

cybercog 614 Jun 4, 2021
A simple API documentation package for Laravel using OpenAPI and Stoplight Elements

Laravel Stoplight Elements Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install

Steve McDougall 8 May 28, 2021
Talk is a real-time users messaging and chatting system Laravel.

Laravel-Talk Talk is a Laravel 5 based user conversation (inbox) system with realtime messaging. You can easily integrate this package with any Larave

Nahid Bin Azhar 1.4k Jun 14, 2021
Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.

Laravel Uuid Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for versio

Christoph Kempen 1.7k Jun 16, 2021
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 918 Jun 8, 2021