EskomCalendar

Client API wrapper for the eskom-calendar service

Constructors

this
this(string calendarServer)

Constructs a new EskomCalendar using the provided custom server

this
this()

Constructs a new EskomCalendar using the default reference server

Members

Functions

getAreas
string[] getAreas()

Get all the areas

getAreas
string[] getAreas(string regex)

Get all areas matching a given regular expression

getSchedules
Schedule[] getSchedules(string area, SysTime startTime, SysTime finishTime)

Get schedules from a given area

getSchedulesFrom
Schedule[] getSchedulesFrom(string area, SysTime startTime)

Gets schedules from a given time

getSchedulesUntil
Schedule[] getSchedulesUntil(string area, SysTime finishTime)

Gets schedules up until a given time

getTodaySchedules
Schedule[] getTodaySchedules(string area)

Gets any schedules in the given area that would be valid for the 24 hours of today's date

Examples

Get the schedules that will occur within today's 24 hours in the western-cape-worscester area

EskomCalendar calendar = new EskomCalendar();

try
{
    Schedule[] schedules = calendar.getTodaySchedules("western-cape-worscester");
    foreach(Schedule schedule; schedules)
    {
        writeln("Today: "~schedule.toString());
    }
}
catch(EskomCalendarException e)
{
    writeln("Crashed with '"~e.toString()~"'");
    assert(false);
}

Get the first 10 areas and then all schedules of each said area

EskomCalendar calendar = new EskomCalendar();

/** 
 * Get all areas available
 * and take a subset of them
 */
string[] areas = calendar.getAreas()[0..10];

/**
 * Get the schedules per-each of them
 */
foreach(string area; areas)
{
    Schedule[] schedules = calendar.getSchedules(area);
}

Get the schedules for the western-cape-worscester area

EskomCalendar calendar = new EskomCalendar();

try
{
    Schedule[] schedules = calendar.getSchedules("western-cape-worscester");
    assert(schedules.length > 5);

    foreach(Schedule schedule; schedules)
    {
        writeln(schedule);
    }
}
catch(EskomCalendarException e)
{
    writeln("Crashed with '"~e.toString()~"'");
    assert(false);
}

Get all areas

EskomCalendar calendar = new EskomCalendar();

try
{
    string[] areas = calendar.getAreas();
    writeln(areas);
    assert(areas.length > 40);
}
catch(EskomCalendarException e)
{
    writeln("Crashed with '"~e.toString()~"'");
    assert(false);
}

Test failing network connection

EskomCalendar calendar = new EskomCalendar("http://sdhjdshkjdas.com");

try
{
    calendar.getAreas();
    assert(false);
}
catch(EskomCalendarException e)
{
    assert(e.getError() == ErrType.NETWORK_ERROR);
}

Meta