NAME
RT::Client::REST::Object -- base class for RT objects.
SYNOPSIS
# Create a new type
package RT::Client::REST::MyType;
use base qw(RT::Client::REST::Object);
sub _attributes {{
myattribute => {
validation => {
type => SCALAR,
},
},
}}
sub rt_type { "mytype" }
1;
DESCRIPTION
The RT::Client::REST::Object module is a superclass providing a whole bunch of class and object methods in order to streamline the development of RT's REST client interface.
METHODS
- new
-
Constructor
- _generate_methods
-
This class method generates accessors and mutators based on _attributes method which your class should provide. For items that are lists, 'add_' and 'delete_' methods are created. For instance, the following two attributes specified in _attributes will generate methods 'creator', 'cc', 'add_cc', and 'delete_cc':
creator => { validation => { type => SCALAR }, }, cc => { list => 1, validation => { type => ARRAYREF }, },
Note that accessors/mutators working with 'list' attributes accept and return array references, whereas convenience methods 'add_*' and 'delete_*' accept lists of items.
- _mark_dirty($attrname)
-
Mark an attribute as dirty.
- _dirty
-
Return the list of dirty attributes.
- to_form($all)
-
Convert the object to 'form' (used by REST protocol). This is done based on _attributes method. If
$all
is true, create a form from all of the object's attributes, otherwise use only dirty (see _dirty method) attributes. Defaults to the latter. - from_form
-
Set object's attributes from form received from RT server.
- param($name, $value)
-
Set an arbitrary parameter.
- cf([$name, [$value]])
-
Given no arguments, returns the list of custom field names. With one argument, returns the value of custom field
$name
. With two arguments, sets custom field$name
to$value
. - rt
-
Get or set the 'rt' object, which should be of type RT::Client::REST.
DB METHODS
The following are methods that have to do with reading, creating, updating, and searching objects.
- count
-
Takes the same arguments as
search()
but returns the actual count of the found items. Throws the same exceptions. - retrieve
-
Retrieve object's attributes. Note that 'id' attribute must be set for this to work.
- search (%opts)
-
This method is used for searching objects. It returns an object of type RT::Client::REST::SearchResult, which can then be used to process results.
%opts
is a list of key-value pairs, which are as follows:- limits
-
This is a reference to array containing hash references with limits to apply to the search (think SQL limits).
- orderby
-
Specifies attribute to sort the result by (in ascending order).
- reverseorder
-
If set to a true value, sorts by attribute specified by orderby in descending order.
If the client cannot construct the query from the specified arguments, or if the server cannot make it out,
RT::Client::REST::Object::InvalidSearchParametersException
is thrown. - store
-
Store the object. If 'id' is set, this is an update; otherwise, a new object is created and the 'id' attribute is set. Note that only changed (dirty) attributes are sent to the server.
SEE ALSO
RT::Client::REST::Ticket, RT::Client::REST::SearchResult.
AUTHOR
Dmitri Tikhonov <dtikhonov@yahoo.com>