Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

DwApiBase

pritaeas edited this page Apr 25, 2013 · 23 revisions

Base class providing common properties and methods.

Exceptions

The following exceptions can be thrown by all functions.

DwApiException  EX_CONFIGURATION   curl and allow_url_fopen disabled.
DwApiException  EX_INVALID_ARRAY   Invalid parameter, array expected.
DwApiException  EX_INVALID_BOOL    Invalid parameter, bool expected.
DwApiException  EX_INVALID_STRING  Invalid parameter, non-empty string expected.
DwApiException  EX_CURL            curl failed.
DwApiException  EX_FOPEN           file_get_contents failed.
DwApiException  EX_DANIWEB         Invalid request or no data.

Only EX_CURL, EX_FOPEN and EX_DANIWEB are to be expected on a live environment. EX_CURL or EX_FOPEN can occur when communication fails. EX_DANIWEB means the request was rejected by the DaniWeb API, due to invalid parameters (e.g. invalid access token). The other exceptions should only occur when developing as they are either programmatic, or configuration issues.

Public class methods

GetArticleTypes

Returns an alphabetically sorted list of supported article types, to be used as a filter in some methods.

Parameters

None

Return value

Array

Without access token:

- code
- interviews
- news
- reviews
- solved
- threads
- tutorials
- unanswered
- whitepapers

With access token, additionally:

- recommended
- viewed
- watching

GetPostTypes

Returns an alphabetically sorted list of supported post types, to be used as a filter in some methods.

Parameters

None

Return value

Array

- downvoted
- solved
- upvoted

GetRelationTypes

Returns an alphabetically sorted list of supported relation types, to be used as a filter in some methods.

Parameters

None

Return value

Array

- ancestors
- children
- descendants

GetRssArticleTypes

Returns an alphabetically sorted list of RSS article types, to be used as a filter in DwApiRss->GetFeed.

Parameters

None

Return value

Array

- code
- interviews
- news
- reviews
- solved
- threads
- tutorials
- unanswered
- whitepapers

GetSortTypes

Returns an alphabetically sorted list of supported sort types, to be used as a filter in some methods.

Parameters

None

Return value

Array

- firstpost
- lastpost

Code example

include 'DwApiBase.class.php';
$dwApi = new DwApiBase();
try
{
    $articleTypes = $dwApi->GetArticleTypes();
    $postTypes = $dwApi->GetPostTypes();
    $relationTypes = $dwApi->GetRelationTypes();
    $rssArticleTypes = $dwApi->GetRssArticleTypes();
    $sortTypes = $dwApi->GetSortTypes();
}
catch (DwApiException $exception)
{
    die($exception->getMessage());
}