PHP Class Usps\USPSBase

Since: 1.0
Author: Vincent Gabriel
Show file Open project: vinceg/usps-php-api

Public Properties

Property Type Description
$CURL_OPTS Default options for curl.
$testMode - set whether we are in a test mode or not

Protected Properties

Property Type Description
$apiCodes - different kind of supported api calls by this wrapper
$apiVersion string The api type we are about to call.
$arrayResponse array The response represented as an array.
$errorCode integer the error code if one exists.
$errorMessage string the error message if one exists.
$headers array the headers returned from the call made.
$postFields array All the post fields we will add to the call.
$response string the response message.
$username - the usps username provided by the usps website

Public Methods

Method Description
__construct ( string $username = '' ) Constructor.
convertResponseToArray ( ) : array Return the response represented as string.
getArrayResponse ( ) : array Return the array representation of the last response.
getEndpoint ( )
getErrorCode ( ) : integer Get the error code number.
getErrorMessage ( ) : string Get the error code message.
getHeaders ( ) : array Get the headers.
getPostData ( ) : array Return the post data fields as an array.
getPostFields ( )
getResponse ( ) : mixed Get the response data.
getResponseApiName ( ) : string Response api name.
isError ( ) : boolean Did we encounter an error?
isSuccess ( ) : boolean Was the last call successful.
setApiVersion ( string $version ) : void Set the api version we are going to use.
setArrayResponse ( array $value ) : void Set the array response value.
setErrorCode ( integer $code ) : self Set the error code number.
setErrorMessage ( string $message = '' ) : self Set the error message.
setHeaders ( array $headers = [] ) : self Set the headers.
setResponse ( mixed $response = '' ) : self Set the response.
setTestMode ( boolean $value ) : void Set whether we are in a test mode or not.
setUsername ( string $username ) set the usps api username we are going to user.

Protected Methods

Method Description
doRequest ( resource $ch = null ) : string Makes an HTTP request. This method can be overriden by subclasses if developers want to do fancier things or use something other than curl to make the request.
getValueByKey ( array $array, string $key ) : mixed Find a key inside a multi dim. array.
getXMLString ( ) : string Return the xml string built that we are about to send over to the api.

Method Details

__construct() public method

Constructor.
public __construct ( string $username = '' )
$username string - the usps api username

convertResponseToArray() public method

Return the response represented as string.
public convertResponseToArray ( ) : array
return array

doRequest() protected method

Makes an HTTP request. This method can be overriden by subclasses if developers want to do fancier things or use something other than curl to make the request.
protected doRequest ( resource $ch = null ) : string
$ch resource Optional initialized cURL handle
return string the response text

getArrayResponse() public method

Return the array representation of the last response.
public getArrayResponse ( ) : array
return array

getEndpoint() public method

public getEndpoint ( )

getErrorCode() public method

Get the error code number.
public getErrorCode ( ) : integer
return integer error code number

getErrorMessage() public method

Get the error code message.
public getErrorMessage ( ) : string
return string error code message

getHeaders() public method

Get the headers.
public getHeaders ( ) : array
return array the headers returned from the call

getPostData() public method

Return the post data fields as an array.
public getPostData ( ) : array
return array

getPostFields() abstract public method

abstract public getPostFields ( )

getResponse() public method

Get the response data.
public getResponse ( ) : mixed
return mixed the response data

getResponseApiName() public method

Response api name.
public getResponseApiName ( ) : string
return string

getValueByKey() protected method

Find a key inside a multi dim. array.
protected getValueByKey ( array $array, string $key ) : mixed
$array array
$key string
return mixed

getXMLString() protected method

Return the xml string built that we are about to send over to the api.
protected getXMLString ( ) : string
return string

isError() public method

Did we encounter an error?
public isError ( ) : boolean
return boolean

isSuccess() public method

Was the last call successful.
public isSuccess ( ) : boolean
return boolean

setApiVersion() public method

Set the api version we are going to use.
public setApiVersion ( string $version ) : void
$version string the new api version
return void

setArrayResponse() public method

Set the array response value.
public setArrayResponse ( array $value ) : void
$value array
return void

setErrorCode() public method

Set the error code number.
public setErrorCode ( integer $code ) : self
$code integer the error code number
return self

setErrorMessage() public method

Set the error message.
public setErrorMessage ( string $message = '' ) : self
$message string the error message
return self

setHeaders() public method

Set the headers.
public setHeaders ( array $headers = [] ) : self
$headers array the headers array
return self

setResponse() public method

Set the response.
public setResponse ( mixed $response = '' ) : self
$response mixed The response returned from the call
return self

setTestMode() public method

Set whether we are in a test mode or not.
public setTestMode ( boolean $value ) : void
$value boolean
return void

setUsername() public method

set the usps api username we are going to user.
public setUsername ( string $username )
$username string - the usps api username

Property Details

$CURL_OPTS public static property

Default options for curl.
public static $CURL_OPTS

$apiCodes protected property

- different kind of supported api calls by this wrapper
protected $apiCodes

$apiVersion protected property

The api type we are about to call.
protected string $apiVersion
return string

$arrayResponse protected property

The response represented as an array.
protected array $arrayResponse
return array

$errorCode protected property

the error code if one exists.
protected int $errorCode
return integer

$errorMessage protected property

the error message if one exists.
protected string $errorMessage
return string

$headers protected property

the headers returned from the call made.
protected array $headers
return array

$postFields protected property

All the post fields we will add to the call.
protected array $postFields
return array

$response protected property

the response message.
protected string $response
return string

$testMode public static property

- set whether we are in a test mode or not
public static $testMode

$username protected property

- the usps username provided by the usps website
protected $username