Constants

API_ACCOUNT_PREFIX

API_ACCOUNT_PREFIX

Accounts prefix.

API_SECRET

API_SECRET

API secret token.

Type: string Default: null

API_KEY

API_KEY

API key token.

Type: string Default: null

API_ACCOUNT_ID

API_ACCOUNT_ID

API account ID.

Type: string Default: null

Properties

$identifierName

$identifierName : string

The unique key field for the resource

Type

string

$resourceName

$resourceName : string

The name of the resource URI - defaults to the lowercase name of the Resource class

Type

string

$connectionName

$connectionName : string

The connection name to use for this resource

Type

string

$creds

$creds : array

Type

array

$singularName

$singularName : 

Type

$pluralName

$pluralName : 

Type

$_plural

$_plural : 

Plural form of the element name

Type

$_singular

$_singular : 

Singular form of the element name

Type

$resourceIdentifier

$resourceIdentifier : 

Type

$attributes

$attributes : 

Type

$dirty

$dirty : 

Type

$dependentResources

$dependentResources : 

Type

$response

$response : \VivialConnect\Resources\Response

Type

\VivialConnect\Resources\Response

$error

$error : \VivialConnect\Resources\Error

Type

\VivialConnect\Resources\Error

Methods

__construct()

__construct(  $data = null) 

Parameters

$data

getId()

getId() : mixed|null

Get the ID of the resource

Returns

mixed|null

getIdentifierName()

getIdentifierName() : string

Get the identifier property name (defaults to "id")

Returns

string

getResourceName()

getResourceName() : null|string

Get VivialConnect resource name.

Returns

null|string

getResourceUri()

getResourceUri() : string

Get the full resource URI

Returns

string

getResponse()

getResponse() : \VivialConnect\Resources\Response|null

Get the Response object

Returns

\VivialConnect\Resources\Response|null

getError()

getError() : \VivialConnect\Resources\Error|null

Get the error object

Returns

\VivialConnect\Resources\Error|null

save()

save(array  $queryParams = array(), array  $headers = array(),   $isSubresource = False) : boolean

Save the entity

Parameters

array $queryParams
array $headers
$isSubresource

Returns

boolean

destroy()

destroy(array  $queryParams = array(), array  $headers = array(),   $isSubresrouce = False) : boolean

Destroy (delete) the resource

Parameters

array $queryParams
array $headers
$isSubresrouce

Returns

boolean

fill()

fill(array  $data) 

Mass assign properties with an array of key/value pairs

Parameters

array $data

includesMany()

includesMany(string  $model, array  $data) : \VivialConnect\Resources\Collection

Build a Collection of included resources in response payload.

Parameters

string $model
array $data

Returns

\VivialConnect\Resources\Collection

includesOne()

includesOne(string  $model,   $data) : Resource

Build a single instance of an included resource in response payload.

Parameters

string $model
$data

Returns

Resource

through()

through(Resource|string  $resource) 

Set dependent resources to prepend to URI. You can call this method multiple times to prepend additional dependent resources.

For example, if the API only allows you create a new comment on a post through the post's URI: POST /posts/1234/comment

$comment = new Comment; $comment->through('posts/1234'); $comment->body = "This is a comment"; $comment->save();

OR

$post = Post::find(1234); $comment = new Comment; $comment->through($post); $comment->body = "This is a comment"; $comment->save();

Parameters

Resource|string $resource

__get()

__get(  $property) : mixed|null

Magic getter

Parameters

$property

Returns

mixed|null

__set()

__set(  $property,   $value) 

Magic setter

Parameters

$property
$value

original()

original(  $property) : mixed|null

Get the original value of a property (before it was modified).

Parameters

$property

Returns

mixed|null

reset()

reset() : void

Reset all modified properties, reset response, reset error

toArray()

toArray() : array

Returns

array

toJson()

toJson() : string

Returns

string

find()

find(integer|string|null  $id = null, array  $queryParams = array(), array  $headers = array()) : Resource|boolean

Find (GET) a specific resource by its ID (optional)

This method assumes the payload contains a SINGLE resource instance. This method will call the parseFind method on the Resource instance to know where to look in the payload to get the resource data.

Parameters

integer|string|null $id
array $queryParams
array $headers

Throws

\VivialConnect\Common\ResponseException

Returns

Resource|boolean

all()

all(array  $queryParams = array(), array  $headers = array()) : \VivialConnect\Resources\Collection|boolean

Get ALL resources

This method assumes the payload contains an ARRAY of resource instances. This method will call the parseAll method on the Resource instance to know where to look in the payload to get the array of resource data.

Parameters

array $queryParams
array $headers

Throws

\VivialConnect\Common\ResponseException

Returns

\VivialConnect\Resources\Collection|boolean

delete()

delete(  $id, array  $queryParams = array(), array  $headers = array()) : boolean

Delete a resource

Parameters

$id
array $queryParams
array $headers

Throws

\VivialConnect\Common\ResponseException

Returns

boolean

findThrough()

findThrough(Resource|string  $resource, integer|string|null  $id = null, array  $queryParams = array(), array  $headers = array()) : Resource|boolean

Find a single instance *through* a dependent resource. It prepends the resource URI with the given dependent resource URI. For example: API URI: [GET] /posts/1234/comments/5678

$comment = Comment::findThrough('posts/1234', 5678);

OR

$post = Post::find(1234); $comment = Comment::findThrough($post, 5678);

Parameters

Resource|string $resource
integer|string|null $id
array $queryParams
array $headers

Throws

\VivialConnect\Common\ResponseException

Returns

Resource|boolean

allThrough()

allThrough(Resource|string  $resource, array  $queryParams = array(), array  $headers = array()) : \VivialConnect\Resources\Collection|boolean

Find all instances *through* a dependent resource. It prepends the resource URI with the given dependent resource URI. For example:

API URI: [GET] /posts/1234/comments

$comments = Comment::allThrough('posts/1234');

OR

$post = Post::find(1234); $comments = Comment::allThrough($post);

Parameters

Resource|string $resource
array $queryParams
array $headers

Throws

\VivialConnect\Common\ResponseException

Returns

\VivialConnect\Resources\Collection|boolean

setCredentialToken()

setCredentialToken(  $name,   $value) 

Set credentials token.

Parameters

$name
$value

getCredentialToken()

getCredentialToken(  $name) : string

Gets credentials token.

Parameters

$name

Returns

string

init()

init(array  $options = array(),   $connectionName = 'default',   $client = null) 

Initilize HTTP connection object.

Parameters

array $options
$connectionName
$client

getConnectionByName()

getConnectionByName(  $connectionName = 'default') 

Gets a connection by its name.

Parameters

$connectionName

billingStatus()

billingStatus(  $accountId = null, array  $queryParams = array(), array  $headers = array()) 

Parameters

$accountId
array $queryParams
array $headers

isDirty()

isDirty() : integer

Is this entity dirty?

Returns

integer

getDependencies()

getDependencies() : string

Get any resource dependencies

Returns

string

parseFind()

parseFind(  $payload) : mixed

Where to find the single resource data from the response payload.

You should overwrite this method in your model class to suite your needs.

Parameters

$payload

Returns

mixed

parseAll()

parseAll(  $payload) : mixed

Where to find the array of data from the response payload.

You should overwrite this method in your model class to suit your needs.

Parameters

$payload

Returns

mixed

wrapAttributes()

wrapAttributes(  $attributes = array(),   $root = 'object') : array

Wraps attributes into VivialConnect compatible payload.

Parameters

$attributes
$root

Returns

array

hydrate()

hydrate(  $data) : boolean

Hydrate

Parameters

$data

Throws

\VivialConnect\Resources\ResourceException

Returns

boolean