Skip to content

Latest commit

 

History

History
175 lines (131 loc) · 4.25 KB

README.md

File metadata and controls

175 lines (131 loc) · 4.25 KB

TrueVault PHP Client Library

This is unofficial TrueVault PHP client library that enables developers to implement a rich set of server-side functionality for accessing TrueVault's API.

Requirements

  • PHP >=5.3.0
  • Curl PHP extension
  • Json PHP extension

Installation

Manual installation

Just copy library and include TrueVault.php file in your project.

Using composer

Create or update a composer.json file in your project root:

{
    "require": {
        "truevault/truevault": "@dev"
    }
}

Examples

define("TRUEVAULT_VAULT_ID", "12345678-1234-1234-1234-123456789012");
define("TRUEVAULT_API_KEY", "12345678-1234-1234-1234-123456789012");
define("TRUEVAULT_ACCOUNT_ID", "12345678-1234-1234-1234-123456789012");

$trueVault = new TrueVault(array(
    "apiKey" => TRUEVAULT_API_KEY,
    "accountId" => TRUEVAULT_ACCOUNT_ID
));

// get all vaults
$vaults = $trueVault->findAllVaults();

$documents = $trueVault->documents(TRUEVAULT_VAULT_ID);
$schemas = $trueVault->schemas(TRUEVAULT_VAULT_ID);
$blobs = $trueVault->blobs(TRUEVAULT_VAULT_ID);

Document methods

Create

  • array create ( mixed $data )

  • Parameters
    $data - Data for document

  • Return Values
    returns array with created document id in document_id key.

  • Example

$response = $documents->create(array("name" => "Don Joe"));
$documentId = $response["document_id"];

Get

  • array get ( string $documentId )

  • Parameters
    $documentId - TrueVault document ID

  • Return Values
    returns TrueVault document data on success

  • Example

$data = $documents->get($documentId);

Update

  • array update ( string $documentId, mixed $data )

  • Parameters
    $documentId - TrueVault document ID
    $data - New data for document

  • Example

$documents->update($documentId, array("name" => "Don John"));

Delete

  • array delete ( string $documentId )

  • Parameters
    $documentId - TrueVault document ID

  • Example

$documents->delete($documentId);

Search

  • Example
$documents->search(array("page" => 1, "per_page"=> 3,"filter" => array("name" => array("type" => "not", "value" => "Susan"));

BLOB methods

Upload

  • array upload ( string $path, $blobId = null )

  • Parameters
    $path - local file path - this file will be uploaded on TrueVault server and blob will be created
    $blobId - if specified existing blob data will be replaced

  • Return Values
    Returns true on success

  • Example

$response = $blobs->upload("input_file_1.bin");
$blobId = $response["blob_id"];
$blobs->upload("input_file_2.bin", $blobId); // replace existing

Download

  • array download ( $blobId, string $path )

  • Parameters
    $blobId - TrueVault Blob ID
    $path - local file path - blob data will be downloaded to specified local file

  • Return Values
    Returns true on success

  • Example

$blobs->download($blobId, "output_file.bin");

Delete

  • array delete ( $blobId )

  • Parameters
    $blobId - TrueVault Blob ID

  • Return Values
    Returns true on success

  • Example

$blobs->delete($blobId);

Schema methods

$schema = $schemas->create(array("name" => "name", "fields" => array(array("name" => "name", "index" => true, "type" => "string"))));
$schemaId = $schema["id"];

$schemas->get($schemaId);
$schemas->update($schemaId, array("name" => "user", "fields" => array(array("name" => "name", "index" => true, "type" => "string"))));
$schemas->get($schemaId);
$schemas->findAll();
$schemas->delete($schemaId);

Resources

TrueVault REST API Documentation

Author

License