NAME
Usergrid::Client - Usergrid Perl Client
SYNOPSIS
use Usergrid::Client;
my $client = Usergrid::Client->new(
organization => 'test-organization',
application => 'test-app',
api_url => 'http://localhost:8080'
);
$client->login('johndoe', 'Johndoe123$');
$client->add_entity("books", { name => "Ulysses" });
$client->add_entity("books", { name => "Neuromancer" });
my $books = $client->get_collection("books");
while ($books->has_next_entity()) {
my $book = $books->get_next_entity();
print "Name: " . $book->get('name') . ", ";
print "Author: " . $book->get('author') . "\n";
$book->set("in-stock", 0);
$client->update_entity($book);
}
DESCRIPTION
Usergrid::Client provides an easy to use Perl API for Apache Usergrid.
WHAT IS APACHE USERGRID
Usergrid is an open-source Backend-as-a-Service ("BaaS" or "mBaaS") composed of an integrated distributed NoSQL database, application layer and client tier with SDKs for developers looking to rapidly build web and/or mobile applications. It provides elementary services (user registration & management, data storage, file storage, queues) and retrieval features (full text search, geolocation search, joins) to power common app features.
It is a multi-tenant system designed for deployment to public cloud environments (such as Amazon Web Services, Rackspace, etc.) or to run on traditional server infrastructures so that anyone can run their own private BaaS deployment.
For architects and back-end teams, it aims to provide a distributed, easily extendable, operationally predictable and highly scalable solution. For front-end developers, it aims to simplify the development process by enabling them to rapidly build and operate mobile and web applications without requiring backend expertise.
Source: https://usergrid.incubator.apache.org/docs/
For more information, visit http://www.usergrid.org
ATTRIBUTES
The following attributes are made available via the Usergrid::Request role:
- organization (String)
-
Organization name
- application (String)
-
Application name
- api_url (String)
-
URL of the Usergrid instance
- trace (Boolean)
-
Enable/disable request and response tracing for debugging and troubleshooting (Optional)
METHODS
The following methods are provided in this API for interacting with the Apache Usergrid backend.
Authentication
- login ( $username, $password )
-
Performs application user authentication. Returns the user token for the logged in user. The token is also kept in memory and used for subsequent authentication of requests.
- admin_login ( $username, $password )
-
Performs admin user authentication. Returns the user token for the logged in user. The token is also kept in memory and used for subsequent authentication of requests.
Entities
This section covers some of the entity level methods available in the API. Entities form one of the basic building blocks of Usergrid and is analogous to a row in an RDBMS table.
- add_entity ( $collection, \%entity )
-
Creates a new entity within the specified collection. Returns a Usergrid::Entity for the newly added entity.
- update_entity ( Usergrid::Entity )
-
Saves changes to the given entity. Returns the updated Usergrid::Entity.
- get_entity ( $collection, $id )
-
Returns a Usergrid::Entity identified by either UUID or name. If the entity does not exist, the method returns FALSE.
- delete_entity_by_id ( $collection, $id )
-
Deletes an entity from the collection identified by either UUID or name. Returns a Usergrid::Entity of the deleted entity.
- delete_entity ( Usergrid::Entity )
-
Deletes the specified Usergrid::Entity. Returns an instance of the deleted Usergrid::Entity if successful.
- connect_entities ( Usergrid::Entity, $relationship, Usergrid::Entity )
-
Creates a connection from Entity #1 to Entity #2 signified by the relationship. The first entity in this relationship is identified as the connecting entity and the second as the connected entity. The relationship is a string that signifies the type of connection. This returns a Usergrid::Entity of the connecting entity.
- disconnect_entities ( Usergrid::Entity, $relationship, Usergrid::Entity )
-
Removes the connection between the two entities signified by the relationship. This does not affect the entities in any other way apart from the removal of the connection that is depicted by the relationship. This returns a Usergrid::Entity of the connecting entity with the given relationship removed.
Collections
This section covers the methods related to retrieving and working with collections in the Usergrid API. Collections contains groups of entities and is analogous to a table in an RDBMS.
- get_collection ( $collection, [ $limit ] )
-
Returns a Usergrid::Collection with the list of entities up to the maximum specified limit, which is 10 if not provided.
- update_collection ( $collection, \%attributes, [ $query ], [ $limit ] )
-
Updates all the entities in the specified collection with the provided attributes. Optionally pass in the SQL-like query to narrow the scope of the objects that are affected. This also supports specifying a limit to restrict the maximum number of records that are updated. If not specified, the limit defaults to 10 entities.
- delete_collection ( $collection, [ $query ], [ $limit ] )
-
Batch delete entities in the specified collection. Optionally pass in a SQL-like query to narrow the scope of the objects that are affected and a limit to restrict the maximum number of records that are deleted. If not specified, the limit defaults to 10 entities.
- query_collection ( $collection, $query, [ $limit ] )
-
Queries all the entities in the specified collection using a SQL-like query string. This also supports specifying a limit to restrict the maximum number of records that are returned. If not specified, the limit defaults to 10 entities.
- query_connections ( $entity, $relationship, [ $query ], [ $limit ] )
-
Returns a collection of entities for the given relationship, optionally filtered by a SQL-like query and limited to the maximum number of records specified. If no limit is provided, a default of 10 entities is assumed.
SEE ALSO
Usergrid::Collection, Usergrid::Entity, Usergrid::Request
LICENSE
This software is distributed under the Apache 2 license.
AUTHOR
Anuradha Weeraman <anuradha@cpan.org>