Tripal
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TripalWebService Class Reference
Inheritance diagram for TripalWebService:
Inheritance graph
[legend]

Public Member Functions

 __construct ($base_path)
 
 handleRequest ()
 
 setPath ($path)
 
 setParams ($params)
 
 getVersion ($sanitize=FALSE)
 
 getContext ()
 
 getResponse ()
 
 getServicePath ()
 
 getData ()
 
 setResource ($resource)
 
 setError ($message)
 
 getDocumentation ()
 
 addResourceProperty ($resource, $term, $value, $sanitize=[])
 
 setResourceType ($resource, $term, $sanitize=['spacing'])
 

Static Public Attributes

static $label = 'Base WebService'
 
static $description = 'This is the base class for Tripal web services as is not meant to be used on it\'s own'
 
static $type = 'services'
 

Protected Member Functions

 addDocClass ($details=[], $ops=[], $props=[])
 
 getContextTerm ($term, $sanitize=[])
 
 addContextTerm ($resource, $term, $sanitize=[])
 
 addContextVocab ($resource, $vocab)
 

Protected Attributes

 $resource
 
 $path
 
 $params
 
 $base_path
 
 $documentation
 

Constructor & Destructor Documentation

◆ __construct()

TripalWebService::__construct (   $base_path)

Implements the constructor.

Reimplemented in TripalDocService_v0_1, and TripalContentService_v0_1.

Member Function Documentation

◆ addContextTerm()

TripalWebService::addContextTerm (   $resource,
  $term,
  $sanitize = [] 
)
protected

Adds a term to the '@context' section for a given resource.

Parameters
$resourceA TripalWebServiceResource instance.
$termThe term array.
$santizeAn array of keywords indicating how to santize the key. By default, no sanitizing occurs. The two valid types are 'lowercase', and 'spacing' where 'lowercase' converts the term name to all lowercase and 'spacing' replaces any spaces with underscores.
Returns
The id (the term name but with spaces replaced with underscores).

◆ addContextVocab()

TripalWebService::addContextVocab (   $resource,
  $vocab 
)
protected

Adds a vocabulary to the '@context' section for a given resource.

Parameters
$resourceA TripalWebServiceResource instance.
$vocabThe vocabulary array.

◆ addDocClass()

TripalWebService::addDocClass (   $details = [],
  $ops = [],
  $props = [] 
)
protected

Defines an entity class for the web services.

A class defines a resource including information about its properties and the actions that can be performed. Each class as a unique @id, title, type and description. The $details parameter is used to provide this information. Additionally, a resource may support Create, Read Update and Delete (CRUD) operations. Those are defined using the $ops argument. Finally, resources may have properties (or fields). These properties should be defined using the $props arugment.

Parameters
$details. An array of key/value pairs providing the details for the class. Valid keys include:
  • id: The unique IRI for this class.
  • term: the accession for the term for this class.
  • title: The title for the resource that this Class represents.
  • description: (Optional). A description of the resource.
  • subClassOf: (Optional). If this class is a subclass of another class then the value should be the @id of the parent class. This defaults to hydra:Resource. If no subClass is desired, set it to NULL.
  • type: (Optional). Indicates the type of class. Defaults to hydra:Class
$opsIf the resource supports CRUD functionality then those functions should be defined using this argument. This is an associative array with the following keys: GET, POST, PUT, DELETE. These keys, if provided, indicate that a resource of this type can be retrieved (GET), created (POST), updated (PUT) or deleted (DELETE). The value for each key should be an associative array that supports the following keys: = type: the @id that determines the type of operation. This type should be specific to the resource, and it need not be a term from a real vocabulary. Use the '_:' prefix for the term. For example, for an 'Event' resource with a GET method, an appropriate type would be '_:event_retrieve'.
  • label: A label that describes the operation in the context of the resource.
  • description: A description for the operation. Can be set to NULL for no description.
  • expects: The information expected by the Web API.
  • returns: The @id of a Class that will be returned by the operation. Set to NULL if there is no return value.
  • statusCodes: An array of status codes that could be returned when an error occurs. Each element of the array is an associative array with two key/value pairs: 'code' and 'description'. Set the 'code' to be the HTTP code that can be returned on error and the 'description' to an error message appropriate for the error. For example an HTTP 404 error means "Not Found". You can sepecify this code and provide a description appropriate for the method and class.
$props. Defines the list of properties that the resource provides. This is an array of properties where each property is an associative array containing the following keys:
  • type: The @id of the type of property. Alternatively, this can be an instance of a TripalWebServiceResource when the property must support operations such as a property of type hydra:Link.
  • title: (Optional). The human-readable title of this property. If this key is absent then the title will be set to the term's title.
  • description: (Optional). A short description of this property. If this key is absent then the description will be set to the term's description.
  • required: Set to TRUE to indicate if this property is a required field when creating a new resource.
  • readable: Set to TRUE to indicate that the client can retrieve the property's value? altered by an update.
  • writeable: Set to TRUE if the client can alter the value of the property.
  • domain: the @id of the rdfs:domain.
  • range: the @id of the rdfs:range.

◆ addResourceProperty()

TripalWebService::addResourceProperty (   $resource,
  $term,
  $value,
  $sanitize = [] 
)

Adds a key/value property to the given resource.

Parameters
$resourceA TripalWebServiceResource instance.
$termThe term array for the key.
$valueThe value to add.
$santizeAn array of keywords indicating how to santize the key. By default, no sanitizing occurs. The two valid types are 'lowercase', and 'spacing' where 'lowercase' converts the term name to all lowercase and 'spacing' replaces any spaces with underscores.
Returns
$key The key (the term name but with spaces replaced with underscores).

◆ getContext()

TripalWebService::getContext ( )

Retrieves the context section of the response.

The JSON-LD response constists of two sections the '@context' section and the data section. This function only returns the context section of the response.

Returns
An associative array containing the context section of the response.

◆ getContextTerm()

TripalWebService::getContextTerm (   $term,
  $sanitize = [] 
)
protected

Converts a term array into an value appropriate for an @id or @type.

Parameters
$termThe term array.
$santizeAn array of keywords indicating how to santize the key. By default, no sanitizing occurs. The two valid types are 'lowercase', and 'spacing' where 'lowercase' converts the term name to all lowercase and 'spacing' replaces any spaces with underscores.
Returns
The id (the term name but with spaces replaced with underscores).

◆ getData()

TripalWebService::getData ( )

Retrieves the data section of the response.

The JSON-LD response constists of two sections the '@context' section and the data section. This function only returns the data section of the response.

Returns
An associative array containing the data section of the response.

◆ getDocumentation()

TripalWebService::getDocumentation ( )

Retrieves an array contining the supported classes.

Supported classe are resources provided by this web services and the operations supported by those classes.

Returns
An array of TripalWebServiceResource objects that follow the Hydra documentation for documenting supported classes.

Reimplemented in TripalContentService_v0_1.

◆ getResponse()

TripalWebService::getResponse ( )

Returns the full web service response.

The response includes both the @context and data sections of the JSON-LD response.

Returns
An associative array containing that can be converted to JSON.

◆ getServicePath()

TripalWebService::getServicePath ( )

Retrieves the service URL for this service.

◆ getVersion()

TripalWebService::getVersion (   $sanitize = FALSE)

Retrieves the version number for this web service.

Each web service must have version number built into the name of the class. The version number appears at the end of the class name, begins with a lower-case 'v' and is followed by two numbers (major and minor) that are separated by an underscore. This function identifies the version from the class name and returns it here in a human-readable format.

Parameters
$sanitizeSet to TRUE to convert the period to underscore.
Returns
The version number for this web service.

◆ handleRequest()

TripalWebService::handleRequest ( )

Responds to the request argument provided to the service.

This function should be implemented by a TripalWebService child class.

Reimplemented in TripalDocService_v0_1, and TripalContentService_v0_1.

◆ setError()

TripalWebService::setError (   $message)

Set an error for the service.

Parameters
$messageThe error message to report.

◆ setParams()

TripalWebService::setParams (   $params)

Sets the parameters for the resource.

Parameters
$paramsThe set of paramters provided to the sesrvice. These are the values that would occur in a URL after the question mark in an HTTP GET or the data items of an HTTP POST.

◆ setPath()

TripalWebService::setPath (   $path)

Sets the URL path for the resource being called.

Parameters
$pathAn array containing the elements of the URL path. Each level of the URL appears in a separate element of the array. The service type and version are automatically removed from the array. For example, a URL of the type http://localhost/web-services/content/v0.1/Gene/sequence will result in a $path array containing the following:
array(
'Gene',
'sequence',
);
Parameters
unknown$path

◆ setResource()

TripalWebService::setResource (   $resource)

Sets the resource to be returned by this web service.

Parameters
$resource. An implementation of a TripalWebServiceResource.

◆ setResourceType()

TripalWebService::setResourceType (   $resource,
  $term,
  $sanitize = ['spacing'] 
)

Sets the type for the given resource.

The type exist in the context of the web service.

Parameters
$resourceA TripalWebServiceResource instance.
$typeThe type
$santizeAn array of keywords indicating how to santize the key. By default, no sanitizing occurs. The two valid types are 'lowercase', and 'spacing' where 'lowercase' converts the term name to all lowercase and 'spacing' replaces any spaces with underscores.

Member Data Documentation

◆ $base_path

TripalWebService::$base_path
protected

The URL at which Tripal web services are found. This is used for creating the IRI for resources.

◆ $description

TripalWebService::$description = 'This is the base class for Tripal web services as is not meant to be used on it\'s own'
static

A bit of text to describe what this service provides.

◆ $documentation

TripalWebService::$documentation
protected

The list of documented classes used by this service. For the web service to be discoverable all of the entity classes and their collections must be defined.

◆ $label

TripalWebService::$label = 'Base WebService'
static

The human-readable label for this web service.

◆ $params

TripalWebService::$params
protected

The set of paramters provided to the sesrvice. These are the values that would occur in a URL after the question mark in an HTTP GET or the data items of an HTTP POST.

◆ $path

TripalWebService::$path
protected

An array containing the elements of the URL path. Each level of the URL appears in a separate element of the array. The service type and version are automatically removed from the array.

◆ $resource

TripalWebService::$resource
protected

The resource that will be returned by the webservice given the arguments provided. This is a private

◆ $type

TripalWebService::$type = 'services'
static

A machine-readable type for this service. This name must be unique among all Tripal web services and is used to form the URL to access this service.


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