Eve::HttpResource::Graph - a base class for the Graph API node HTTP resources.
package Eve::HttpResource::SomeGraphResource; use parent qw(Eve::HttpResource::Graph); sub _read { # some object's hash is returned here } sub _get_connections { # some connections hash is returned here } sub _get_fields { # some object fields hash is returned here } sub _get_type { # a required type string is returned here } 1;
Eve::HttpResource::Graph is an HTTP resource based class providing an automation of the Facebook like Graph API node/connection functionality.
Methods _read(), _publish(), _remove(), _get_connections(), _get_fields(), _get_type(), _get_actions() and _get_id_alias_hash() could be overriden by the class derivatives. When not overriden these methods except _get_connections() and _get_fields throw the exception Eve::Exception::Http::405MethodNotAllowed. _get_type throws a Eve::Error::NotImplemented exception which means it must be overridden to be used. Inside the described above methods class attributes _request, _response, _session, _event_map and _dispatcher can be found.
_read()
_publish()
_remove()
_get_connections()
_get_fields()
_get_type()
_get_actions()
_get_id_alias_hash()
_get_fields
Eve::Exception::Http::405MethodNotAllowed
_get_type
Eve::Error::NotImplemented
_request
_response
_session
_event_map
_dispatcher
All methods are passed the list of named matched URI parameters as arguments. The following example illustrates the usage of named arguments in a resource that is bound to the http://example.com/:named/:another pattern URI:
http://example.com/:named/:another
my ($self, %arg_hash) = @_; Eve::Support::arguments(\%arg_hash, my ($named, $another));
If the metadata query string parameter is specified then the metadata section is added to the result. This section always contains the object's type returned by the _get_type method, and if present, the object's connections returned by the _get_connections() method, the object's fields returned by the _get_fields method and the object's actions returned by the _get_actions() method.
metadata
If the request method is POST and the query string is supplied with method=delete then it behaves just like the DELETE method is requested. If other value is passed to the method then the exception Eve::Exception::Http::400BadRequest is thrown.
POST
method=delete
DELETE
method
Eve::Exception::Http::400BadRequest
If Eve::Exception::Privilege is thrown in the user code the exception Eve::Exception::Http::403Forbidden is rethrown.
Eve::Exception::Privilege
Eve::Exception::Http::403Forbidden
Note that the resource must be bound with the id placeholder. The _id attribute is representing it. If _get_id_alias_hash() is redefined you can use ID aliases in URI according to the hash keys.
id
_id
Object deletion requests must use the deleted object's node URI. In case a connection with no public ID is deleted, the request must use the respective object connection URI.
request
an HTTP request object
response
an HTTP response object
session_constructor
a reference to a subroutine accepting the session id argument and returning a session object
dispatcher
an HTTP dispatcher object
json
a JSON encoder object.
This method is called when the graph node or connection is requested with the GET method.
It is expected to return a data hash reference that will be automatically converted to a required textual representation and returned to the client
When a method is used without being overridden in a descendant class.
This method is called when the graph node or connection is requested with the POST method.
This method is called when the graph node or connection is requested with the DELETE method or when the POST method is used in conjunction with a method=delete query string parameter..
This method is called when the metadata parameter is recieved in the request. Overriding this method is optional.
It is expected to return a connection hash reference that will be automatically converted to a required textual representation and returned to the client.
It is expected to return a fields hash reference that will be automatically converted to a required textual representation and returned to the client.
It is expected to return an actions hash reference with action keys as keys and action names as values that will be automatically converted to a required textual representation and returned to the client.
This method is called when the metadata parameter is recieved in the request.
It is expected to return a type string that will be automatically converted to a required textual representation and returned to the client.
This method is called when the graph HTTP resource processes the pattern placeholder matches from a request URI. A hash of aliases for an id can be specified in this method. For example, if an id in the URI is specified as an alias keyword, it can be replaced with a real identifier by returning this hash reference:
alias
return {'alias' => $some_service->get_parameter(name => 'id')};
It is expected to return a reference to a hash of aliases for an identifier.
Copyright 2012 Igor Zinovyev.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Eve, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Eve
CPAN shell
perl -MCPAN -e shell install Eve
For more information on module installation, please visit the detailed CPAN module installation guide.