PHP code example of 20steps / commons-uptime-robot-bundle

1. Go to this page and download the library: Download 20steps/commons-uptime-robot-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

20steps / commons-uptime-robot-bundle example snippets



    

use twentysteps\Commons\UptimeRobotBundle\API;
use twentysteps\Commons\UptimeRobotBundle\Model;
    
class MyService {
    
    /**
     * @var UptimeRobotAPI
     */
    private $uptimeRobotAPI;
	    
    /**
     * inject dependency to uptimeRobotAPI via your services.yml
     * the uptimeRobotAPI is a service itself with the id "twentysteps_commons.uptime_robot.api"
     */
    public function __construct(UptimeRobotAPI $uptimeRobotAPI) {
        $this->uptimeRobotAPI = $uptimeRobotAPI;
    }
    
    /**
     * create a monitor
     * @return \Psr\Http\Message\ResponseInterface|Error|Monitor
     */
    public function createMonitorForMyResource() {
        $parameters = [
            'friendly_name' => 'My Monitor,
            'url' => 'https://my-host.com/my-path'
        ];
        $response = $this->uptimeRobotAPI->monitor()->create($parameters);
        if ($response instanceof MonitorResponse) {
            /**
             * @var $response MonitorResponse
             */
            if ($response->getStat()=='ok') {
                return $response->getMonitor();
            } else {
                return $response->getError();
            }
        }
        return $response;
    }
}


    

$this->uptimeRobotAPI->setApiKey($myApiKey);