The Middlware API Reference¶
Atlas¶
- class
apps.geofencing.middleware.atlas.atlas.
Atlas
[source]¶API wrapper for queries for mongodb Fence database
createActiveTimeWindows
(time_windows)[source]¶Takes a list of time window dictionries and creates a list of time window embedded documents. Below is an example of a time window.
- ::
- [
- {
- “start”: {
- “sec”: 0, “hour”: 0, “min”: 0
}, “end”: {
“sec”: 59, “hour”: 23, “min”: 59}, “tzname”: “Africa/Abidjan”
}
]
Parameters:
- time_windows ([dict]) – list ditcionaries. Each dictionarty should include hour_st, min_st, sec_st, hour_end, min_end and sec_end keys
- tzname (string) –
Returns: list of timewindow embedded documents
createFence
(center, group_id, radius=0, address=None, save=True, reload=False, **kwargs)[source]¶Create a 2D circular geofence object in the geofence databases.
:param geojson center: geojson point object - { type: "Point", coordinates: [ lon, lat ] } :param int group_id: :param float radius: radius in meters. Defaults to 0 if not initialized :param address: AddressComponents embedded document or dictionary of address components. :param [string] labels: :param dict tags: dictionary of tags to add to the geofence .i.e name tag, industry tags etc :param kwargs: :return: newly saved geofence object
createFenceTriggers
(active_time_windows=None, temp_ranges=None, precipitation=None, **kwargs)[source]¶Create an embedded document containing all of the fence trigger parameters.
Parameters:
- active_time_windows ([dict]) –
- temp_range ([dict]) –
- precipitation – dictionary {‘rain’: value, ‘snow’: %, ‘sleet’: %, ‘hail’: %}
- kwargs –
createPolygonalFence
(group_id=None, polygon=None, address=None, **kwargs)[source]¶Accepts a polygon in geojson format to create a polygonal geofence. Example of a geojson polygon is given below.
{ "type": "Polygon", "coordinates": [ [ [ -87.67525, 41.990973 ], [ -87.674799, 41.98331 ], [ -87.689733, 41.990249 ], [ -87.67525, 41.990973 ] ] ] }
Parameters:
- group_id – string value
- polygon – geo-json polygon
- address – dictionary of address information
Returns:
- classmethod
deleteFence
(fence)[source]¶delete a fence given a document id
Keyword Arguments: fence_id – unique id for the fence document: string
getClosestFences
(lat, lon, radius=1000, limit=19, group_ids=None, **kwargs)[source]¶Query the database for the set of fences closest to a location.
Parameters:
- lat (float) – WGS84 latitude coordinate
- lon (float) – WGS84 longitude coordinate
- radius – radial search distance in meters
- limit – max number of fences to be returned
- group_ids ([int]) – list of group ids to be returned
- kwargs – additional keyword arguments to further filter the query by
Returns: base queryset object with the results
getFencesWithinSphere
(group_ids, lat, lon, radius, unit='meter', **kwargs)[source]¶Retrieves geofences within a given radius
Parameters:
- group_ids ([int]) – list of group ids to include in query
- lat –
- lon –
- radius – radial search distance
- unit – feet, miles or meters
- kwargs – additional filter attributes
Returns: mongoengine query object
getGeoFence
(fence_id, deleted=False, type='')[source]¶Grabs a geofence from the DB by the fence_id field
Parameters: fence_id – client facing fence id value Returns: a single geofence object
getGeoFences
(deleted=False, fence_type='', **kwargs)[source]¶Query for all fences matching passed filter parameters
Parameters:
- deleted –
- fence_type (string) – fence or polygonal
- kwargs – key-value pairs of attributes to filter the collection by.
Returns: Mongoengine Base Query set
getGeofencesInGroups
(group_ids, deleted=False, type='', **kwargs)[source]¶Query for all fences matching passed filter parameters and in the campaign groups passed in
Parameters:
- deleted –
- type (string) – fence or polygonal
- kwargs – key-value pairs of attributes to filter the collection by.
Returns: Mongoengine Base Query set
updateContentPool
(fence, pool, delay_save=False)[source]¶Add a content pool to a geofence
Parameters:
- fence – Geofence or fence_id
- pool – Content Pool object to add
Returns: None
Pandora¶
- class
apps.geofencing.middleware.pandora.pandora.
Pandora
[source]¶API wrapper for queries for mongodb Content database
addContentToPool
(pool, content)[source]¶Add a list of content messages to a content pool.
Parameters:
- pool – content Pool object.
- content – list of ContentMessage mongodb document or mongodb reference id objects.
Returns:
createContentMessage
(name, notification_text=None, message_texts=None, media=None, pools=None, **kwargs)[source]¶Creates the Content Message which represents what is sent to the library in response to geofence trigger events.
Parameters:
- name – name of offer or content message
- notification_text (NoteText) – headline notification text.
- message_texts ([MessageText]) – list of message text objects to make up the body of the content message.
- media ([MultiMedia]) – list of multimedia objects
- pools ([Pool]) – list of content pool objects
- kwargs – see database schema for more values
Returns: saved content message object.
createImageMedia
(data, filename, content_type=None, name=None, bucket_name=None, **kwargs)[source]¶Checks that the data is a valid image file by inspecting the file extension and creates an image media document in the content databases.
Parameters:
- data – file like object with the image contents
- filename – name of the file including the extension
- content_type – internet media content type
- name – name or title of image object in the database
- bucket_name – AWS s3 bucket that should be used for storage of the file contents
- kwargs – additional keyword arguments representing database reccord attributes of the document. See schema
for more information :return: Mongoengine mongodb document object representing the newly saved image media document
createMessageText
(name, text, **kwargs)[source]¶Add a message text doc to the content database. Used in specifying text in the body of a content message.
Parameters:
- name –
- text –
- kwargs –
Returns:
createNewS3Bucket
(bucket_name, **kwargs)[source]¶Create’s a new bucket in AWS S3 if it does not already exist or will return the exting one if it already exists.
Parameters:
- bucket_name –
- kwargs –
createNotificationText
(name, text, **kwargs)[source]¶Add a notification text doc to the content database. Used in specifying the headline notification text of a content message/offer.
Parameters:
- name –
- text –
- kwargs –
Returns:
createPool
(name, description=None, **kwargs)[source]¶Creates a new content pool and saves to the database.
Parameters:
- name – name of pool
- description – additional description details.
Returns: Newly saved content pool
createVideoType
(data, filename, content_type=None, name=None, bucket_name=None, **kwargs)[source]¶Checks that the data is a valid video file by inspecting the file extension and creates an video media document in the content databases.
Parameters:
- data – file like object with the video contents
- filename – name of the file including the extension
- content_type – internet media content type
- name – name or title of image object in the database
- bucket_name – AWS s3 bucket that should be used for storage of the file contents
- kwargs – additional keyword arguments representing database record attributes of the document. See schema
for more information :return: Mongoengine mongodb document object representing the newly saved video media document
deleteContentMessage
(contentoffer, cascade=False)[source]¶Delete’s a content message document in the content databases.
Parameters:
- contentoffer –
- cascade – If set to True will also delete composite documents i.e. media, text and pool data.
Returns:
- classmethod
deleteContentPool
(content_pool)[source]¶Delete a Content Pool document in the content databases.
Parameters: content_pool – Returns:
- classmethod
deleteDoc
(doc)[source]¶Delete a Text document in the content databases.
Parameters: doc – MongoDB text document. Returns: None
deleteMediaDoc
(media)[source]¶Handles the proper deletion and de-referencing of Content Media objects in the data layer.
Parameters: media – Returns: None
- classmethod
deleteTextDoc
(textdoc)[source]¶Delete a Text document in the content databases.
Parameters: textdoc – MongoDB text document. Returns: None
- classmethod
dropCollections
()[source]¶Performs a low-level database delete of all documents in the Media, Text, Pool and Content Message collections.
Returns:
getContentMessages
(deleted=False, **kwargs)[source]¶Returns the set of all content objects meeting the criteria of the keyword arguments passed. See schema for more information.
Parameters:
- deleted – default value of false.
- kwargs – keyword value pairs i.e. id, content_id, name etc...
Keyword: name
Returns: mongoengine database query object
getContentMessagesByIDs
(content_ids=None)[source]¶Querys the database for content messages by their content_ids. :param list of content_ids: :return: Query object with the results.
getContentMessagesByPools
(content_pools, deleted=False, **kwargs)[source]¶Returns the list of content documents for a given list of content pool ids
Parameters:
- content_pools –
- deleted –
- kwargs –
Returns:
getContentPoolDocs
(deleted=False, **kwargs)[source]¶Query the content database for content pool objects by filtering the collection based on the passed attributes.
Parameters:
- deleted –
- kwargs –
Returns: Query object containg the results.
getImageContent
(deleted=False, **kwargs)[source]¶Query content database for Image media data.
Parameters:
- deleted – False
- kwargs – see schema.
Returns: Query object with the results.
getMediaContent
(content_id=None, deleted=False, **kwargs)[source]¶Query the content database for both image and video data.
Parameters:
- content_id – content id field. Note this is differnt from the document’s primary key in the DB.
- deleted – default is to not return deleted records.
- kwargs – see schema for more information
Returns: Query object with the results
getMediaContentByIds
(content_ids, deleted=False, **kwargs)[source]¶Query the content database for both image and video data.
Parameters:
- content_ids – List of content_ids to query for.
- deleted – default is to not return deleted records.
- kwargs – see schema for more information
Returns: Query object with the results
getMessageTextDocs
(deleted=False, **kwargs)[source]¶Query the content database for message text objects that meet the passed field-value attributes.
Parameters:
- deleted –
- kwargs –
Returns: Query object containing the results.
getMessageTextDocsByIds
(content_ids=None, deleted=False, **kwargs)[source]¶Query the content database for message text objects that meet the passed field-value attributes.
Parameters:
- content_ids ([string]) – list of message text content ids
- deleted –
- kwargs –
Returns: Query object containing the results.
getNotificationTextDocs
(deleted=False, **kwargs)[source]¶Query the content database for notification text objects that meet the passed field-value attributes.
Parameters:
- deleted –
- kwargs –
Returns: Query object containing the results.
getTextDocs
(deleted=False, **kwargs)[source]¶Query the content database for notification text objects that meet the passed field-value attributes.
Parameters:
- deleted –
- kwargs –
Returns: Query object containing the results.
getVideoContent
(deleted=False, **kwargs)[source]¶Query the content database for Video media data.
Parameters:
- deleted –
- kwargs –
Returns: Query object with the results.
removeContentFromPool
(pool, content)[source]¶Remove a content message or list of content messages from a content pool.
Parameters:
- pool –
- content –
Returns:
Themis¶
Zeus¶
- class
apps.geofencing.middleware.zeus.account.
AccountApi
[source]¶
create
(user=None, name=None, permission=None, **kwargs)[source]¶Creates an Account DB Reccord :param User user: SQL Alchemy DB object :param AdminPermission permission: SQL Alchemy DB object :param string name: account name :keyword bucket_name: AWS S3 bucket name for the account. If none the account name used to generate one. :return:
get
(delete_flag=None, **kwargs)[source]¶Query the accounts datbase table by the key value pairs passed in.
Parameters:
- delete_flag –
- kwargs –
Returns: a single account object.