Snuze  0.8.1
snuze\Request\Request Class Reference
Inheritance diagram for snuze\Request\Request:

Public Member Functions

 addHeader (string $name, string $value)
 
 getHeaders ()
 
 addParameter (string $name, $value=null)
 
 getParameter (string $name)
 
 getParameters ()
 
 getApiUri ()
 
 getEndpointPath ()
 
 getVerb ()
 
 getRequiresAuthentication ()
 
 getMandatoryParameters ()
 
 validate ()
 
- Public Member Functions inherited from snuze\SnuzeObject
 __construct (array $args=null)
 
 _getSnuzeId ()
 
 _getSnuzeClass ()
 
 _ident ()
 

Static Public Member Functions

static getValidParameters ()
 
static getValidVerbs ()
 

Public Attributes

const API_URIS
 
const VERB_GET = 'GET'
 
const VERB_POST = 'POST'
 
const VERB_DELETE = 'DELETE'
 

Protected Member Functions

 setApiUri (string $apiUri)
 
 setEndpointPath (string $endpointPath)
 
 setVerb (string $verb)
 
 setRequiresAuthentication (bool $requiresAuthentication)
 
- Protected Member Functions inherited from snuze\SnuzeObject
 debug (string $message, bool $echo=false)
 
 info (string $message, bool $echo=false)
 
 warning (string $message, bool $echo=false)
 
 error (string $message, bool $echo=false)
 

Protected Attributes

 $parameters = []
 
 $mandatoryParameters = []
 
- Protected Attributes inherited from snuze\SnuzeObject
 $_snuzeId = null
 
 $_snuzeClass = null
 

Private Attributes

 $apiUri = self::API_URIS['authenticated']
 
 $endpointPath = null
 
 $verb = self::VERB_GET
 
 $requiresAuthentication = true
 
 $headers = []
 

Detailed Description

Request represents the common features of any request that will be sent to the Reddit API. The target URI, HTTP verb, and any headers or parameters (query string or POST fields) are all stored in this object.

You can't instantiate a generic Request; instead, you should create and use the various subtypes.


This file is part of Snuze, a PHP client for the Reddit API. Copyright 2019 Shaun Cummiskey shaun.nosp@m.@sha.nosp@m.unc.c.nosp@m.om https://shaunc.com/ Repository: https://github.com/snuze/snuze/ Documentation: https://snuze.shaunc.com/

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Member Function Documentation

◆ addHeader()

snuze\Request\Request::addHeader ( string  $name,
string  $value 
)

Add an HTTP header to this request.

Parameters
string$nameThe name of the header, e.g. 'Connection'
string$valueThe value of the header, e.g. 'Close'
Returns
Request This object

◆ addParameter()

snuze\Request\Request::addParameter ( string  $name,
  $value = null 
)

Add a parameter to the query string or POST data for this Request.

If the parameter already exists, it will be overwritten with the new value. If $value is empty, the parameter will be unset.

Parameters
string$nameThe name of the parameter, e.g. 'link_fullname'
scalar | null$valueThe value of the parameter, e.g. 't3_chungus'
Returns
Request This object
Exceptions

References snuze\Request\Request\getValidParameters().

◆ getApiUri()

snuze\Request\Request::getApiUri ( )

Get the API base URI for this type of Request

Returns
string The API base URI

◆ getEndpointPath()

snuze\Request\Request::getEndpointPath ( )

Get the API endpoint path for this type of Request

Returns
string The API endpoint path e.g. "/api/foo/bar"

◆ getHeaders()

snuze\Request\Request::getHeaders ( )

Get the array of HTTP headers configured for this Request.

Returns
array An array of HTTP header key/value pairs

◆ getMandatoryParameters()

snuze\Request\Request::getMandatoryParameters ( )

Get an array containing the list of parameter names that must be defined when sending a Request of this type.

Returns
array The parameter names that are required for this Request type

◆ getParameter()

snuze\Request\Request::getParameter ( string  $name)

Get the value of a single parameter, by name; or null if it's not set

Parameters
string$nameThe name of the parameter to retrieve
Returns
scalar|null Whatever value has been set for this parameter

◆ getParameters()

snuze\Request\Request::getParameters ( )

Get the array of parameters configured for this Request.

Returns
array An array of parameter key/value pairs

◆ getRequiresAuthentication()

snuze\Request\Request::getRequiresAuthentication ( )

Get whether or not this type of Request requires authentication.

Returns
bool Whether or not this Request type requires authentication

◆ getValidParameters()

static snuze\Request\Request::getValidParameters ( )
static

Get an array of valid outgoing parameter names for this Request type.

Returns
array The Request child object's PARAM_ constants and their values

◆ getValidVerbs()

static snuze\Request\Request::getValidVerbs ( )
static

Get an array of supported HTTP verbs.

Returns
array Request's VERB_ constants and their values

◆ getVerb()

snuze\Request\Request::getVerb ( )

Get the HTTP verb configured for this Request type

Returns
string The HTTP verb e.g. "GET" or "DELETE"

◆ setApiUri()

snuze\Request\Request::setApiUri ( string  $apiUri)
protected

Set the base URI to which this request will be sent.

Parameters
string$apiUriThe base URI for this type of Request
Returns
Request This object
Exceptions

◆ setEndpointPath()

snuze\Request\Request::setEndpointPath ( string  $endpointPath)
protected

Set the API endpoint path to which this request will be posted.

Parameters
string$endpointPathThe API endpoint path e.g. "/api/foo/bar"
Returns
Request This object
Exceptions

◆ setRequiresAuthentication()

snuze\Request\Request::setRequiresAuthentication ( bool  $requiresAuthentication)
protected

Set whether or not this type of Request requires authentication.

Parameters
bool$requiresAuthenticationWhether this Request type requires authentication
Returns
Request This object

◆ setVerb()

snuze\Request\Request::setVerb ( string  $verb)
protected

Set the HTTP verb that will be used for this Request type

Parameters
string$verbOne of the self::VERB_ constants
Returns
$this
Exceptions

References snuze\Request\Request\getValidVerbs().

◆ validate()

snuze\Request\Request::validate ( )

Returns true if the mandatory properties for this request type are all set. Child classes of Request should override this method, performing any additional checks specific to their Request type.

Returns
bool Whether or not the Request is ready to send to the API
Exceptions

Member Data Documentation

◆ API_URIS

const snuze\Request\Request::API_URIS
Initial value:
= [
'unauthenticated' => "https://www.reddit.com",
'authenticated' => "https://oauth.reddit.com",
]

The base URIs to which API requests are sent. Requests to obtain an authorization token must be made to the "unauthenticated" URI. Most other requests are generally made to the "authenticated" URI.

Don't edit these values unless you have a phenomenally good reason.

◆ VERB_DELETE

const snuze\Request\Request::VERB_DELETE = 'DELETE'

Define the HTTP DELETE verb as valid

◆ VERB_GET

const snuze\Request\Request::VERB_GET = 'GET'

Define the HTTP GET verb as valid

◆ VERB_POST

const snuze\Request\Request::VERB_POST = 'POST'

Define the HTTP POST verb as valid


The documentation for this class was generated from the following file: