mickadoo/duolingo-events

PHP API Wrapper for the Duolingo Events API

0.5.0 2021-07-24 17:08 UTC

This package is auto-updated.

Last update: 2024-04-25 00:02:29 UTC


README

This package allows calling the Duolingo Events API.

PHP Composer

Usage

First run composer req mickadoo/duolingo-events in your project.

To get an instance of the API wrapper use

use Mickadoo\DuolingoEvents\ApiFactory;
use Mickadoo\DuolingoEvents\Request\EventsRequest;

$api = ApiFactory::getEventsApi();
// Defaults to any language, events up to 3 days in future 
$events = $api->getEvents(new EventsRequest());

Filter events by specifying language or time

use Mickadoo\DuolingoEvents\ApiFactory;
use Mickadoo\DuolingoEvents\Request\EventsRequest;

$api = ApiFactory::getEventsApi();
// Defaults to any language, events up to 3 days in future
$request = new EventsRequest();
$request->setLanguageCodes(['fr']);
$request->setEndRange(new DateTime('+2 weeks'));
$events = $api->getEvents($request);

Each call will return an array of Event instances.

Fetch a single event

use Mickadoo\DuolingoEvents\ApiFactory;

$api = ApiFactory::getEventsApi();;
$id = 'ac10a8c7-e6e8-4acc-ac0d-5fd0274ab3df';
$event = $api->getEvent($id);

Note: The hosts property of an event is not populated from a collection call, e.g. getEvents, it will only be set on a single event call, i.e. getEvent($id)

Tests

To run the test suite clone this repository, run composer install and from the project directory run

vendor/bin/phpunit