anper/jsonbox

PHP wrapper for https://jsonbox.io

v0.6.0 2021-01-07 15:36 UTC

This package is auto-updated.

Last update: 2022-05-07 18:50:47 UTC


README

Software License Latest Version on Packagist Build Status

PHP wrapper / Client SDK for jsonbox

Install

$ composer require anper/jsonbox

Usage

use Anper\Jsonbox\Jsonbox;

$jsonbox = Jsonbox::factory('box-id');

Create

// Create a record
$response = $jsonbox->create(['name' => 'Arya Stark']);

// Create multiple records
$response = $jsonbox->create([
    ['name' => 'Daenerys Targaryen'],
    ['name' => 'Arya Stark'],
]);

// Create a collection
$response = $jsonbox->colletion('users')
    ->create(/* like one record or multiple records */);   

Read

// Read a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')->read();

// Read a collection
$response = $jsonbox->collection('users')->read();

// Read all
$response = $jsonbox->read();

Filtering

$filter = new \Anper\Jsonbox\Filter();
$filter->equalTo('name', 'Arya Stark');

// Filter all
$response = $jsonbox->read($filter);

// Filter collection
$response = $jsonbox->collection('users')->read($filter);

Update

// Update a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')
    ->update(['name' => 'Arya Stark']);

// Update multiple records (async request for every record)
$response = $jsonbox->update([
    '5d776b75fd6d3d6cb1d45c52' => ['name' => 'Daenerys Targaryen'],
    '5d776b75fd6d3d6cb1d45c53' => ['name' => 'Arya Stark'],
]);

Delete

// Delete a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')->delete();

// Delete multiple records (async request for every record)
$response = $jsonbox->delete([
    '5d776b75fd6d3d6cb1d45c52',
    '5d776b75fd6d3d6cb1d45c53',
]);

// Delete by filter
$response = $jsonbox->delete($filter);

Protected Box

// An API-KEY should be a valid GUID/UUID
$protectedJsonbox = $jsonbox->withApiKey('API_KEY');

Test

$ composer test

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.