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

Provides a means of easily specifying an API resource. More...

List of all members.

Public Member Functions

 __construct ($domain_name=null)
 Constructor for a URL object.
 CompleteURL ($include_key=TRUE, $use_pagination_filter=FALSE)
 Returns the complete URL as a string.
 SetPrefix ($prefix)
 Sets the prefix for the request.
 SetCategory ($category)
 Sets the method category.
 AddID ($id)
 Adds items to the list of IDs.
 SetMethod ($method)
 Sets the method to invoke.
 AddTag ($tag)
 Adds items to the list of tags.
 SetParameter ($parameter)
 Sets the additional parameter.
 SetFilter ($filter, $pagination_filter=null)
 Sets the specified filter for the request.
 SetQueryStringParameter ($key, $value)
 Sets the specified query string parameter to the specified value.
 GetPOSTData ()
 Returns the POST data associated with this URL.
 SetPOSTData ($assoc_array)
 Associates POST data with this URL.
 SetAccessToken ($access_token)
 Adds the specified access token to the request.
 SetCacheTTL ($ttl)
 Indicates the ideal amount of time for which this URL should be cached.
 GetCacheTTL ()
 Returns the amount of time that this URL should be cached for.

Public Attributes

const AutoRequestPrefix = 0
 Instructs Stack.PHP to automatically select the correct prefix for each request.
const StandardRequestPrefix = 1
 Used to perform a standard request using HTTP.
const SecureRequestPrefix = 2
 Used to perform a secure request using HTTP over TLS (HTTPS).

Static Public Attributes

static $default_prefix = self::AutoRequestPrefix
 The default prefix to use for requests.

Detailed Description

Provides a means of easily specifying an API resource.

The URL class simplifies the process of specifying API resources by providing convenience functions that make manipulating the different components of a URL easy and safe. The URL class automatically escapes query string parameters as necessary.

An API URL is divided into the following ordered parts (some of which are optional):


Constructor & Destructor Documentation

URL::__construct ( domain_name = null)

Constructor for a URL object.

Parameters:
$domain_namethe domain name of the URL in the form example.com or example

Member Function Documentation

URL::AddID ( id)

Adds items to the list of IDs.

Parameters:
$idthe ID of the item to add or an array of IDs
Returns:
the current instance
URL::AddTag ( tag)

Adds items to the list of tags.

Parameters:
$tagthe tag to add or an array of tags
Returns:
the current instance
URL::CompleteURL ( include_key = TRUE,
use_pagination_filter = FALSE 
)

Returns the complete URL as a string.

Parameters:
$include_keyTRUE to include the API key in the returned string
$use_pagination_filterwhether to use the pagination filter or not
Returns:
a string representing the complete URL

This method creates a string representation of the URL by combining the parts of the URL.

URL::GetCacheTTL ( )

Returns the amount of time that this URL should be cached for.

Returns:
the TTL for this URL
URL::GetPOSTData ( )

Returns the POST data associated with this URL.

Returns:
the POST data or null if none
URL::SetAccessToken ( access_token)

Adds the specified access token to the request.

Parameters:
$access_tokenthe access token for the request
Returns:
the current instance

Note: the access token is only needed for authenticated methods. Also, calling this method will cuase this request to switch to HTTPS because that is a requirement for all authenticated methods.

URL::SetCacheTTL ( ttl)

Indicates the ideal amount of time for which this URL should be cached.

Parameters:
$ttlthe TTL for this URL
Returns:
the current instance
URL::SetCategory ( category)

Sets the method category.

Parameters:
$categorythe category of API requests
Returns:
the current instance
URL::SetFilter ( filter,
pagination_filter = null 
)

Sets the specified filter for the request.

Parameters:
$filtera filter ID or a Filter object
$pagination_filtera filter ID or a Filter object
Returns:
the current instance

This method accepts two filters. The first is used for requests that do not require access to PagedResponse::Total(). The second (optional) filter will be used when the total number of items is requested.

URL::SetMethod ( method)

Sets the method to invoke.

Parameters:
$methodthe name of the method
Returns:
the current instance
URL::SetParameter ( parameter)

Sets the additional parameter.

Parameters:
$parameterthe additional parameter
Returns:
the current instance
URL::SetPOSTData ( assoc_array)

Associates POST data with this URL.

Parameters:
$assoc_arrayan array of key => value pairs to add
Returns:
the current instance

Note: if a key in $assoc_array matches an existing key in the POST data, then the new value will replace the old one.

URL::SetPrefix ( prefix)

Sets the prefix for the request.

Parameters:
$prefixthe desired prefix for the request
Returns:
the current instance

Note: this value will only be honored if URL::$default_prefix is set to URL::AutoRequestPrefix (the default) - otherwise the value provided will be ignored.

URL::SetQueryStringParameter ( key,
value 
)

Sets the specified query string parameter to the specified value.

Parameters:
$keythe query string parameter to be modified
$valuethe new value for the parameter
Returns:
the current instance

Note: if a value already exists for a parameter, this method will overwrite it.


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