alcohol/php-goanywhere

0.1.1 2017-08-03 13:03 UTC

README

A PHP library providing a client for the REST API of GoAnywhere.

License

Installing

composer require alcohol/php-goanywhere

NOTE: This library does not require a specific HTTP client implementation. Pick one that suits you best. See http://docs.php-http.org/en/latest/httplug/users.html for more details.

Using

<?php

require_once 'vendor/autoload.php';

$endpoint = 'http://localhost:8001/goanywhere/rest/gacmd/v1';
$username = 'foo';
$password = 'bar';

// customizable
$httpClient = (new Alcohol\GoAnywhere\HttpClient\Builder())
    ->withEndpoint($endpoint)
    ->withCredentials($username, $password)
    ->createConfiguredHttpClient();
$apiClient = new Alcohol\GoAnywhere\Client($httpClient);

// convenient shortcut
$apiClient = Alcohol\GoAnywhere\Client::create($endpoint, $username, $password);

try {
    $apiClient->WebUsers()->addUser(['addParameters' => ['template' => 'my-template', 'username' => 'Foo']]);
} catch (Alcohol\GoAnywhere\Exception $exception) {
    // handle errors
}

Disclaimer

The GoAnywhere REST API is not very consistent, nor would I qualify their documentation as "complete"¹. This implementation therefor is made on a best-effort basis only. Should you run into any problems however, we can look into resolving them together. Please open an issue or submit a pull-request.

¹) For example;

  • the keys in JSON payload examples are sometimes shown as camelCase, but the API actually expects them to be lowercase (or vice-versa),
  • the endpoint URLs or JSON payloads are not always very consistent in format/layout, or sometimes just plain wrong,
  • in case of an error, the response body is often merely a short string.