keestash/php-sdk

SDK for interacting with Keestash

0.0.2 2023-06-25 09:21 UTC

This package is auto-updated.

Last update: 2024-10-27 18:04:02 UTC


README

Keestash SDK is a collection of code that makes it easier to interact with Keestash instances. The basic idea is to configure the SDK once and create, update, delete resources on a remote Keestash server easily.

The SDK is still under development. The service classes are added as needed. If you need something, please open a pull request or open a support ticket.

Installation

Use the package manager composer to install Keestash SDK.

composer install keestash/sdk

Usage

First, you need to implement the \Keestash\Sdk\Service\Api\ApiCredentialsInterface interface in order to provide the API URL and credentials to the SDK. The API URL needs to be there for all requests sending to Keestash whereas the user hash and user token are not necessarily need to present.

class ApiCredentialsProvider implements \Keestash\Sdk\Login\Entity\ApiCredentialsInterface {

    public function getApiUrl(): string
    {
        return 'your-keestash.server/api.php';
    }

    public function getUserToken(): ?string
    {
        return <userToken>;
    }

    public function getUserHash(): ?string
    {
        return <userHash>;
    }
}

After providing the URL to your Keestash instance, you can call the login endpoint

$keestashClient = new \Keestash\Sdk\Client\KeestashClient(
    new GuzzleHttp\Client(),
    new ApiCredentialsProvider()
);

$login = new \Keestash\Sdk\Login\Login($keestashClient);
$data = $login->login(<username>, <password>);
var_dump($data);

The login endpoint returns a user hash and token in case of success. You need these for all authenticated requests to Keestash. Make sure that your class implementing \Keestash\Sdk\Service\Api\ApiCredentialsInterface uses the returned values for all subsequent requests.

require __DIR__ . '/vendor/autoload.php';

// create credential
$c = new \Keestash\Sdk\PasswordManager\Entity\Credential(
    'test-password',
    'theusername',
    'topsecret',
    'root',
    'https://keestash.com'
);

$credential = new \Keestash\Sdk\PasswordManager\Credential\Credential($keestashClient);
$credential->create($c);

// create folder
$folder = new \Keestash\Sdk\PasswordManager\Folder\Folder($keestashClient);
$folder->create(new \Keestash\Sdk\PasswordManager\Entity\Folder('test-folder', 'root'));

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

AGPLv3