<?
/*
GovEvents API -- PHP Example and Developer Notes

RESPONSE FORMAT
---------------
Response format implementations are currently XML and JSON. It is specified
by the extension (.xml or .json) or the HTTP Accept header (application/xml
or application/json), in order of precedence.

URL CONSTRUCTION
----------------
Retrieve upcoming events in XML:
http://www.govevents.com/api/events.xml

Retrieve a specific event (using an event ID returned from the event list):
http://www.govevents.com/api/events/123.xml

The events that can be accessed or returned may be dependant upon your API key.

NOTE ON EVENT CONTENT ELEMENT
-----------------------------
The <content> element is a CDATA section in the XML response. It may have HTML
entities which can be displayed in a brower, or to decode the entities in
PHP, you can use html_entity_decode($string, ENT_QUOTES, 'UTF-8').

ERROR HANDLING
--------------
Returns from the API include a "status" element with a value of
either "ok" or "error"

The following is an example of an error returned due to invalid
authentication:

<response>
    <status>error</status>
    <code>401</code>
    <message>You must be authorized to access this content.</message>
</response>

The error code is returned in the response header as well. An error status
of 404 is used in cases where no events are found for the query.
*/

// Specify API Key and password from GovEvents
$api_key    'YOUR_API_KEY';
$api_pass   'YOUR_API_PASSWORD';

// Retrieve upcoming events in XML
$api_url    'http://www.govevents.com/api/events.xml';

$ch curl_init();
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_DIGEST);
curl_setopt($chCURLOPT_USERPWD$api_key ':' $api_pass);
curl_setopt($chCURLOPT_TIMEOUT10);
curl_setopt($chCURLOPT_URL$api_url);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

// $response_body contains the return from the API
$response_body curl_exec($ch);
curl_close($ch);

echo 
$response_body;
?>