Usage
The Usage module provides functionality for working with user usage reports.
- class Usage(api, user)[source]
Bases:
Base- Parameters:
api (GeoboxClient)
user (User)
- BASE_ENDPOINT = 'usage/'
- __init__(api, user)[source]
Constructs the necessary attributes for the Usage object.
- Parameters:
api (Api) – The API instance.
user (User) – the user usage object.
- __repr__()[source]
Return a string representation of the Usage object.
- Returns:
A string representation of the Usage object.
- Return type:
str
- classmethod get_api_usage(api, resource, scale, param, from_date=None, to_date=None, days_before_now=None, limit=None)[source]
Get the api usage of a user
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
scale (UsageScale) – the scale of the report.
param (UsageParam) – traffic or calls.
from_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.
to_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.
days_before_now (int, optional) – number of days befor now.
limit (int, optional) – Number of items to return. default is 10.
- Raises:
ValueError – one of days_before_now or from_date/to_date parameters must have value
ValueError – resource must be a ‘user’ or ‘apikey’ object
- Returns:
usage report
- Return type:
List
Example
>>> from geobox import GeoboxClient >>> from geobox.usage import Usage >>> client = GeoboxClient() >>> user = client.get_user() # gets current user >>> usage = Usage.get_api_usage(client, ... resource=user, ... scale=UsageScale.Day, ... param=UsageParam.Calls, ... days_before_now=5) or >>> usage = client.get_api_usage(resource=user, ... scale=UsageScale.Day, ... param=UsageParam.Calls, ... days_before_now=5)
- classmethod get_process_usage(api, user_id=None, from_date=None, to_date=None, days_before_now=None)[source]
Get process usage of a user in seconds
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
user_id (int, optional) – the id of the user. leave blank to get the current user report.
from_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.
to_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.
days_before_now (int, optional) – number of days befor now.
- Raises:
ValueError – one of days_before_now or from_date/to_date parameters must have value
- Returns:
process usage of a user in seconds
- Return type:
float
Example
>>> from geobox import GeoboxClient >>> from geobox.usage import Usage >>> client = GeoboxClient() >>> process_usage = Usage.get_process_usage(client, days_before_now=5) or >>> process_usage = client.get_process_usage(days_before_now=5)
- classmethod get_usage_summary(api, user_id=None)[source]
Get the usage summary of a user
- Parameters:
api (GeoboxClient) – The API instance.
user_id (int, optional) – the id of the user. leave blank to get the current user report.
- Returns:
the usage summery of the users
- Return type:
Dict
- Returns:
>>> from geobox import GeoboxClient >>> from geobox.usage import Usage >>> client = GeoboxClient() >>> usage_summary = Usage.get_usage_summary(client) or >>> usage_summary = client.get_usage_summary()
- classmethod update_usage(api, user_id=None)[source]
Update usage of a user
- Parameters:
api (GeoboxClient) – The API instance.
user_id (int, optional) – the id of the user. leave blank to get the current user report.
- Returns:
the updated data
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> from geobox.usage import Usage >>> client = GeoboxClient() >>> Usage.update_usage(client) or >>> client.update_usage()