Filepath: phork/php/utilities/ApiHelper.class.php

The ApiHelper class is used to called your application's REST API methods internally without incurring the additional overhead of multiple HTTP requests. It does so by backing up the actual request method and request variables and then by temporarily faking them for the duration of the API call. Then instead of using the ApiController to make the call it calls the FooApi methods directly.

Each request can either return an array containing the success flag, the result array and the status code, or can be wrapped in a method to just return part of the result data.

Any API method called using the ApiHelper class can take advantage of an additional internal flag which can be used by the API methods to allow for such things as more permissive actions or to return additional data.

The ApiHelper has the option to work with the UserLogin object in the registry to authenticate users, although it's not required. This is a Phork/it object.

GET Example

list($blnSuccess, $arrEvents, $intStatusCode) = ApiHelper::get('/api/events/filter/by=userid/' . $intUserId . '.json');

POST Example

list($blnSuccess, $arrResult, $intStatusCode) = ApiHelper::post('/api/events/add/status.json', array(
    'status' => 'My ceiling is leaking'

PUT Example

list($blnSuccess, $arrResult, $intStatusCode) = ApiHelper::put('/api/users/connect/friend/' . $strUsername . '.json');

DELETE Example

list($blnSuccess, $arrResult, $intStatusCode) = ApiHelper::delete('/api/events/delete/' . $intEventId . '.json');

Node Example

//retrieve only the first child node within the users node
if ($arrUserRecord = ApiHelper::getResultNode('/api/users/filter/by=username/' . $strUsername . '.json", 'users', true)) {