2017 © Pedro Peláez
 

library rest-client

A simple REST cient to interact with Backup Pro installations in a RESTful manner

image

backup-pro/rest-client

A simple REST cient to interact with Backup Pro installations in a RESTful manner

  • Monday, July 25, 2016
  • by mithra62
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Backup Pro REST Client

A simple REST cient to interact with Backup Pro installations., (*1)

Installation

Add backup-pro/rest-client as a requirement to composer.json:, (*2)

$ composer require backup-pro/rest-client

Simple Example

use \mithra62\BpApiClient\Client;

$client = new Client();
$backups = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->get('/backups');

Authentication

Backup Pro uses HMAC-SHA authentication which is a simple key / secret paradigm to create hashed signatures. You can get/set your api key and secret, as well as the API URL endpoint, from your individual Backup Pro installations., (*3)

Error Handling

If anything goes wrong with a request the library will return an ApiProblem object. Here's an example:, (*4)

use \mithra62\BpApiClient\Client;
use \mithra62\BpApiClient\ApiProblem;

$client = new Client();
$backups = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->get('/backups');

if($result instanceof ApiProblem) 
{
    if($result->getStatus() == 403) {
        //authentication issue
    }

    $result->getTitle() //API problem response title
    $result->getDetail() //API problem response details

}

Hal Responses

For all successful responses from the Backup Pro API, the library will return an instance of \mithra62\BpApiClient\Hal object which is a wrapper for \Nocarrier\Hal., (*5)

use \mithra62\BpApiClient\Client;
use \mithra62\BpApiClient\Hal;

$client = new Client();
$backups = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->get('/backups');

if($result instanceof Hal) 
{
    $data = $result->getData();
    $resources = $result->getResources();
}

Examples

Since Backup Pro follows the [Richardson Maturity Model](Richardson Maturity Model) there are helper methods available for each HTTP verb. Below are some simple usecase examples and their implementations, (*6)

Take a Backup

use \mithra62\BpApiClient\Client;

$client = new Client();
$backups = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->post('/backups');

Update Settings

use \mithra62\BpApiClient\Client;

$client = new Client();
$settings = array('working_directory' => '/path/to/working_directory');
$update = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->put('/settings', $settings);

Get Settings

use \mithra62\BpApiClient\Client;

$client = new Client();
$settings = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->get('/settings');

Get Storage Locations

use \mithra62\BpApiClient\Client;

$client = new Client();
$storage_locations = $client->setApiKey($api_key)
                 ->setApiSecret($api_secret)
                 ->setSiteUrl($api_endpoint_url)
                 ->get('/storage');

The Versions

25/07 2016

dev-master

9999999-dev

A simple REST cient to interact with Backup Pro installations in a RESTful manner

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Lamb

25/07 2016

0.1.1

0.1.1.0

A simple REST cient to interact with Backup Pro installations in a RESTful manner

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Lamb

03/05 2016

dev-develop

dev-develop

A simple REST cient to interact with Backup Pro installations in a RESTful manner

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Lamb

03/05 2016

0.1

0.1.0.0

A simple REST cient to interact with Backup Pro installations in a RESTful manner

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Lamb