The mangal class¶
The mangal class is where most of the action happens. Almost all user actions consist in calling various methods of this class.
Documentation¶
- class pymangal.mangal(url='http://mangal.uqar.ca', suffix='/api/v1/', usr=None, key=None)¶
Creates an object of class mangal
This is the main class used by pymangal. When called, it will return an object with all methods and attributes required to interact with the database.
Parameters: - url – The URL of the site with the API (default: http://mangal.uqar.ca)
- suffix – The suffix of the API (default: /api/v1/)
- usr – Your username on the server (default: None)
- key – Your API key on the server (default: None)
Returns: An object of class mangal
- Get(resource='dataset', key='1')¶
Get an object identified by its key (id)
Parameters: - resource – The type of object to get
- key – The unique identifier of the object
Returns: A dict representation of the resource
- List(resource='dataset', filters=None, page=10, offset=0)¶
Lists all objects of a given resource type, according to a filter
Parameters: - resource – The type of resource (default: dataset)
- filters – A string giving the filtering criteria (default: None)
- page – Either an integer giving the number of results to return, or 'all' (default: 10)
- offset – Number of initial results to discard (default: 0)
Returns: A dict with keys meta and objects
Note
The objects key of the returned dictionary is a list of dict, each being a record in the database. The meta key contains the next and previous urls, and the total_count number of objects for the request.
- Post(resource='taxa', data=None)¶
Post a resource to the database
Parameters: - resource – The type of object to post
- data – The dict representation of the object
The data may or may not contain an owner key. If so, it must be the URI of the owner object. If no owner key is present, the value used will be self.owner.
This method converts the fields values to URIs automatically
If the request is successful, this method will return the newly created object. If not, it will print the reply from the server and fail.