Lamplight API examples - work listing

Any data shown on this page is fictious - this is an example!

The code

Again we're using the php Lamplight_Client class, which makes constructing requests a bit easier. First, set up the client

     $client = new Lamplight_Client('', array(
       'key'     => LAMPLIGHT_APIKEY,
       'lampid'  => LAMPLIGHT_ID,
       'project' => LAMPLIGHT_PROJECT

This gives us an Http Client with the authentication parameters set (we use an include to define the LAMPLIGHT_APIKEY, LAMPLIGHT_ID and LAMPLIGHT_PROJECT constants). We don't need to pass a uri because the Lamplight_Client does it for us.

Next, tell it what we want to fetch. We want some (fetchSome()) work (fetchWork()) records, for the next week. Additional parameters use setParameterGet($key, $value) (as we're making a GET request, the default - setParameterPost for POST requests); we want records after today and before next week. Dates need to be in ISO 8601 YYYY-MM-DD format. And finally make the request(). Note that Lamplight_Client provides a fluent interface so that you can chain your method calls to build the request.

$orgResponse = $client->fetchWork()
                      ->setParameterGet('after', date('Y-m-d'))
                      ->setParameterGet('before', date('Y-m-d', strtotime('+1 week')))

The Zend_Http_Response returned (see Zend Framework API docs has some useful methods: we use isError() and getStatus() to check we've got something back with a 200 response, and then getBody() to retrieve the json encoded data. It's then a simple step to decode it and iterate over the data returned to write out some data.

$workList = json_decode($jsonRecs);

foreach($workList->data as $rec) {
    echo '
  • ' . htmlentities($rec->title, ENT_QUOTES, "UTF-8") . '
  • '; // echo other data we want here... // $rec has properties: id, title, workarea, start_date, end_date // start_date and end_date are date times YYYY-MM-DD hh:mm:ss format }