NAME
REST::Neo4p::Agent - LWP client interacting with Neo4j
SYNOPSIS
$agent = REST::Neo4p::Agent->new();
$agent->server('http://127.0.0.1:7474');
unless ($agent->connect) {
print STDERR "Didn't find the server\n";
}
See examples under "METHODS" below.
DESCRIPTION
The agent's job is to encapsulate and connect to the REST service URLs of a running neo4j server. It also stores the discovered URLs for various actions. and provides those URLs as getters from the agent object. The getter names are the keys in the JSON objects returned by the server. See http://docs.neo4j.org/chunked/milestone/rest-api.html for more details.
API and HTTP errors are distinguished and thrown by Exception::Class subclasses. See REST::Neo4p::Exceptions.
REST::Neo4p::Agent
is a subclass of LWP::UserAgent and inherits its capabilities.
METHODS
- new()
-
$agent = REST::Neo4p::Agent->new(); $agent = REST::Neo4p::Agent->new("http://127.0.0.1:7474");
Returns a new agent. Accepts optional server address arg.
- server()
-
$agent->server("http://127.0.0.1:7474");
Sets the server address and port.
- data()
-
$neo4j_data_url = $agent->data();
Returns the base of the Neo4j server API.
- admin()
-
$neo4j_admin_url = $agent->admin();
Returns the Neo4j server admin url.
- node()
- reference_node()
- node_index()
- relationship_index()
- extensions_info
- relationship_types()
- batch()
- cypher()
-
$relationship_type_url = $agent->relationship_types;
These methods get the REST URL for the named API actions. Other named actions may also be available for a given server; these are auto-loaded from self-discovery responses provided by Neo4j. Use
available_actions()
to identify them.You will probably prefer using the "get_{action}()", "put_{action}()", "post_{action}()", and "delete_{action}()" methods to make requests directly.
- neo4j_version()
-
$version = $agent->neo4j_version;
Returns the version of the connected Neo4j server.
- available_actions()
-
@actions = $agent->available_actions();
Returns all discovered actions.
- errmsg()
-
Returns last error message. This is undef if the request was successful.
- location()
-
$agent->post_node(); # create new node $new_node_url = $agent->location;
Returns the value of the "location" key in the response JSON.
- get_{action}()
-
$decoded_response = $agent->get_data(@url_components,\%rest_params) $types_array_ref = $agent->get_relationship_types();
Makes a GET request to the REST endpoint mapped to {action}. Arguments are additional URL components (without slashes). If the final argument is a hashref, it will be sent as key-value form parameters.
- put_{action}()
-
# add a property to an existing node $agent->put_node([13, 'properties'], { name => 'Herman' });
Makes a PUT request to the REST endpoint mapped to {action}. The first argument, if present, must be an array reference of additional URL components. The second argument, if present, is a hashref that will be sent in the request as (encoded) JSON content.
- post_{action}()
-
# create a new node with given properties $agent->post_node({ name => 'Wanda' });
Makes a POST request to the REST endpoint mapped to {action}. The first argument, if present, must be an array reference of additional URL components. The second argument, if present, is a hashref that will be sent in the request as (encoded) JSON content.
- delete_{action}()
-
$agent->delete_node(13); $agent->delete_node_index('myindex');
Makes a DELETE request to the REST endpoint mapped to {action}. Arguments are additional URL components (without slashes). If the final argument is a hashref, it will be sent in the request as (encoded) JSON content.
- decoded_response()
-
$decoded_json = $agent->decoded_response;
Returns the response content of the last agent request, as decoded by JSON. It is generally a reference, but can be a scalar if a bareword was returned by the server.
AUTHOR
Mark A. Jensen
CPAN ID: MAJENSEN
majensen -at- cpan -dot- org
LICENSE
Copyright (c) 2012 Mark A. Jensen. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.