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

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

Public Member Functions

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

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

◆ __construct()

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

◆ AddID()

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

◆ AddTag()

URL::AddTag (   $tag)

Adds items to the list of tags.

Parameters
$tagthe tag to add or an array of tags
Returns
the current instance

◆ CompleteURL()

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.

◆ GetCacheTTL()

URL::GetCacheTTL ( )

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

Returns
the TTL for this URL

◆ GetPOSTData()

URL::GetPOSTData ( )

Returns the POST data associated with this URL.

Returns
the POST data or null if none

◆ SetAccessToken()

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.

◆ SetCacheTTL()

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

◆ SetCategory()

URL::SetCategory (   $category)

Sets the method category.

Parameters
$categorythe category of API requests
Returns
the current instance

◆ SetFilter()

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.

◆ SetMethod()

URL::SetMethod (   $method)

Sets the method to invoke.

Parameters
$methodthe name of the method
Returns
the current instance

◆ SetParameter()

URL::SetParameter (   $parameter)

Sets the additional parameter.

Parameters
$parameterthe additional parameter
Returns
the current instance

◆ SetPOSTData()

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.

◆ SetPrefix()

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.

◆ SetQueryStringParameter()

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: