Stack.PHP
A simple and easy to use PHP library for the Stack Exchange API.
Public Member Functions | Static Public Member Functions | Static Public Attributes
API Class Reference

Main class which provides access to all sites and routes. More...

List of all members.

Public Member Functions

 Me ($access_token)
 Returns a request for the user that corresponds with the specified access token.

Static Public Member Functions

static EnableDebugMode ($enable_debug=TRUE)
 Enables / disables the debug mode.
static GetVersion ()
 Returns the version of the API that Stack.PHP is using.
static GetRawData ($url, $post_data=null)
 Fetches the raw response from the provided URL.
static GetJSON ($url, $include_total=FALSE)
 Fetches JSON data from the provided URL.
static SetCache ($cache_instance, $cleanup=TRUE)
 Sets the internal cache to the provided instance of a cache class.
static AssociatedUsers ($ids)
 Returns the user accounts that correspond to the specified account IDs.
static DeauthenticateApplication ($access_token)
static Errors ($error=null)
 Returns all errors that can be thrown by the API or simulates a specific error.
static Inbox ($access_token)
 Returns the inbox items for the specified access token.
static InvalidateAccessTokens ($access_token)
 Invalidates the supplied access tokens.
static ReadAccessTokens ($access_token)
 Retrieves information about the specified access tokens.
static Site ($site_domain)
 Creates a Site object for the provided site.
static Sites ()
 Returns a paged response of all Stack Exchange sites.
static GetTotalRequests ()
 Returns the total number of requests made for API data.
static GetAPIRequests ()
 Returns the number of requests actually sent to the API.

Static Public Attributes

static $key = ''
 The API key to use for making requests.
static $cache_ttl = 600
 The TTL value to use when caching requests (in seconds).
static $user_agent = 'Stack.PHP (v0.5 beta 1)'
 The user-agent used to make requests.
static $debug = FALSE
 Whether to enable verbose mode (used for debugging).

Detailed Description

Main class which provides access to all sites and routes.

This class provides static methods for storing and retrieving information needed for requests as well as means for creating instances of the Site class which is used for all other entry points.


Member Function Documentation

static API::AssociatedUsers ( ids) [static]

Returns the user accounts that correspond to the specified account IDs.

Parameters:
$idseither a single account ID or an array of account IDs
Returns:
a PagedResponse object
static API::DeauthenticateApplication ( access_token) [static]
Parameters:
$access_tokeneither a single access token or an array of access tokens
Returns:
a PagedRequest object
static API::EnableDebugMode ( enable_debug = TRUE) [static]

Enables / disables the debug mode.

Parameters:
$enable_debugTRUE to enable debug mode

Enabling the debug mode will produce a lot of extra output. This will simply be sent to STDOUT for a CLI-based application and will be echo'd to the client when used in a web application. If the latter behavior is not desired, you can use PHP's output buffering methods to capture the output instead.

Debug mode also enables additional information in the response by changing one of the default filters that are used.

static API::Errors ( error = null) [static]

Returns all errors that can be thrown by the API or simulates a specific error.

Parameters:
$errora specific error to simulate
Returns:
the current instance
static API::GetAPIRequests ( ) [static]

Returns the number of requests actually sent to the API.

Returns:
the number of requests sent to the API

This number represents the number of requests actually sent to the API servers. In the absence of a cache, this number is identical to API::GetTotalRequests().

static API::GetJSON ( url,
include_total = FALSE 
) [static]

Fetches JSON data from the provided URL.

Parameters:
$urlan instance of the URL class containing the URL to retrieve
$include_totalwhether or not the total number of items is needed in the response
Returns:
JSON-decoded data from the URL

This method retrieves data from an API route and decodes the JSON returned. Invoking this method does not necessarily make an API call if a cache has been set with API::SetCache(). Parameters that do not affect the data returned are removed and the resulting URL is looked up in the cache. If it exists, the data is returned immediately using the cached response.

This method also ensures that the request rate-limit is adhered to. This method will sleep just long enough to ensure that the request does not exceed the rate-limit.

static API::GetRawData ( url,
post_data = null 
) [static]

Fetches the raw response from the provided URL.

Parameters:
$urlthe URL to retrieve
$post_dataan array of data to POST
Returns:
raw data from the URL

All HTTP requests to the API are routed through this method which ensures that the proper encoding header is sent (this also informs curl that we may be expecting compressed data in return). This method also accepts an array of POST values that are converted to a properly encoded string.

static API::GetTotalRequests ( ) [static]

Returns the total number of requests made for API data.

Returns:
the total number of requests

This number technically represents the total number of times that API::GetJSON() has been called. If no cache has been set, this number is equal to the number of API requests actually made.

static API::GetVersion ( ) [static]

Returns the version of the API that Stack.PHP is using.

Returns:
the current API version
static API::Inbox ( access_token) [static]

Returns the inbox items for the specified access token.

Parameters:
$access_tokena valid access token
Returns:
an InboxItemRequest object
static API::InvalidateAccessTokens ( access_token) [static]

Invalidates the supplied access tokens.

Parameters:
$access_tokeneither a single access token or an array of access tokens
Returns:
a PagedRequest object
API::Me ( access_token)

Returns a request for the user that corresponds with the specified access token.

Parameters:
$access_tokena valid access token
Returns:
a UserRequest object
static API::ReadAccessTokens ( access_token) [static]

Retrieves information about the specified access tokens.

Parameters:
$access_tokeneither a single access token or an array of access tokens
Returns:
a PagedRequest object
static API::SetCache ( cache_instance,
cleanup = TRUE 
) [static]

Sets the internal cache to the provided instance of a cache class.

Parameters:
$cache_instancean instance of a class derived from CacheBase
$cleanupwhether to perform cleanup of expired entries in the cache
static API::Site ( site_domain) [static]

Creates a Site object for the provided site.

Parameters:
$site_domaina portion of the site's domain name
Returns:
a Site object
static API::Sites ( ) [static]

Returns a paged response of all Stack Exchange sites.

Returns:
a PagedSiteResponse object

Member Data Documentation

API::$cache_ttl = 600 [static]

The TTL value to use when caching requests (in seconds).

This value determines the duration of time that requests will be cached for when a cache has been set with API::SetCache(). The default is 10 minutes. Note that certain requests will override this value when necessary to comply with the API's best usage policy.

API::$debug = FALSE [static]

Whether to enable verbose mode (used for debugging).

Note: this variable should not be used to enable debug mode. Instead, use API::EnableDebugMode to toggle debug mode.

API::$key = '' [static]

The API key to use for making requests.

This value is not strictly required as the API allows up to 300 requests per day without an API key. However, for any production quailty application, you are highly encouraged to register for one as it increases your daily quota to 10000 requests per day. You also require an API key for authenticated requests.

API::$user_agent = 'Stack.PHP (v0.5 beta 1)' [static]

The user-agent used to make requests.

This value is used by the code that makes HTTP requests. It is recommended that your application explicitly modify this value for identification purposes.


The documentation for this class was generated from the following file:
 All Classes Functions Variables