Skip to content

Latest commit

 

History

History
53 lines (44 loc) · 1.7 KB

README.md

File metadata and controls

53 lines (44 loc) · 1.7 KB

Lyyti API PHP wrapper

Wrapper for Lyyti API to make it simpler to use

Currently supported api resources:

events                         -> getEvents()
events/{event_id}/participants -> getParticipants($event)
standard_questions             -> getStandardQuestions(?$event)

Examples expect you to have imported the namespace by using

use Lyyti\API\v2\Client as LyytiApi;

Client memory caches responses for 10 minutes by default (does not persist if the Client object is deallocated). You can configure this behavior by passing Cache object to the Client.

// Client(private_key, public_key, cache)
// Cache(?int lifetime_minutes = 10, ?string file)
// Example with 5 minute cache that is stored in a file to make it persistent
$lyyti_api = new LyytiApi\Client("private_key", "public_key", new LyytiApi\Cache(1, "cachefile.json"));

Responses come as Response objects that contain http status code and depending if the API request succeeded data and error.

$lyyti_api = new LyytiApi\Client("private_key", "public_key");
$response = $lyyti_api->getEvents();

// Events list if the request was successful (Dynamic type. In this case type = ?array)
$data = $response->data;
// Http code for the response (type = int)
$http_code = $response->http_code;
// Error text if the request failed (type = ?string)
$error = $response->error;

Basic usage example:

// Init LyytiApi object
$lyyti_api = new LyytiApi\Client("private_key", "public_key");

// Get events from API
$events = $lyyti_api->getEvents()->data;

// Use the events
foreach ($events as $event) {
    $first_event_language = $event->language[0];
    $event_name = $event->name->$first_event_language;
    echo $event_name."\n";
}