def delete_thng_property(thng_id, property_name, timestamp_from=None, timestamp_to=None, api_key=None): """Delete a Property on a Thng.""" assertions.datatype_str('thng_id', thng_id) _delete_property(thng_id, 'thngs', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key)
def list_users(project_id, api_key=None, request_kwargs=None): """List Application Users.""" assertions.datatype_str('project_id', project_id) return utils.request('GET', '/users', api_key=api_key, **(request_kwargs or {}))
def delete_product_property(product_id, property_name, timestamp_from=None, timestamp_to=None, api_key=None): """Delete a Property on a Product.""" assertions.datatype_str('product_id', product_id) _delete_property(product_id, 'products', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key)
def _upsert_property(entity_type, entity_id, key, values, api_key=None, request_kwargs=None): """A helper to wrap common property update functionality.""" assertions.datatype_str('key', key) url = '/{}/{}/properties/{}'.format(entity_type, entity_id, key) return utils.request('PUT', url, data=values, api_key=api_key, **(request_kwargs or {}))
def activate_user(user, activationCode, api_key=None): """Activate an Application User.""" assertions.datatype_str('user', user) assertions.datatype_str('activationCode', activationCode) url = '/auth/evrythng/users/{}/validate'.format(user) data = {'activationCode': activationCode} return utils.request('POST', url, data=data, api_key=api_key)
def delete_place(place, api_key=None, request_kwargs=None): assertions.datatype_str('place', place) url = '/places/{}'.format(place) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def read_collection_actions(collection, type_, api_key=None, request_kwargs=None): """Read Actions for a Collection.""" assertions.datatype_str('collection', collection) assertions.datatype_str('type_', type_) url = '/collections/{}/actions/{}'.format(collection, type_) return utils.request('GET', url, api_key=api_key, **(request_kwargs or {}))
def activate_user(user_id, activationCode, api_key=None): """Activate an Application User.""" assertions.datatype_str('user_id', user_id) assertions.datatype_str('activationCode', activationCode) url = '/auth/evrythng/users/{}/validate'.format(user_id) data = {'activationCode': activationCode} return utils.request('POST', url, data=data, api_key=api_key)
def update_reactor_bundle(project_id, application_id, bundle_bytes, api_key=None): """ Update a Reactor via a bundle of files; A zip file containing main.js, package.json, etc. :param project_id: The ID of the Project. :type project_id: str :param application_id: The ID for the Application that is a child of the Project for which the reactor script will be scoped to. :type application_id: str :param bundle_bytes: The bytes that make up the Zip file containing the bundle of files. :type bundle_bytes: bytes :param api_key: The API key to authorize request against. :type api_key: str :return: """ kwargs = locals() api_key = kwargs.pop('api_key', None) project_id = kwargs.pop('project_id') assertions.datatype_str('project_id', project_id) application_id = kwargs.pop('application_id') assertions.datatype_str('application_id', application_id) assertions.validate_field_specs(kwargs, reactor_bundle_field_specs) url = '/projects/{}/applications/{}/reactorScript'.format( project_id, application_id) files = {'file': bundle_bytes} return utils.request('PUT', url, files=files, api_key=api_key)
def update_reactor_script(project_id, application_id, script, manifest='', type_='simple', api_key=None): """ Update the Reactor with a single script text file and an optional manifest. :param project_id: The ID of the Project. :type project_id: str :param application_id: The ID for the Application that is a child of the Project for which the reactor script will be scoped to. :type application_id: str :param script: The reactor script body. :type script: str :param manifest: The manifest file for running the script. A packages.json file, basically. :type manifest: str :param type_: The reactor script type. Possible values are simple, bundle. Default is simple :type type_: str :param api_key: The API key to authorize request against. :type api_key: str :return: """ kwargs = locals() kwargs['type'] = kwargs.pop('type_') api_key = kwargs.pop('api_key', None) project_id = kwargs.pop('project_id') assertions.datatype_str('project_id', project_id) application_id = kwargs.pop('application_id') assertions.datatype_str('application_id', application_id) assertions.validate_field_specs(kwargs, reactor_script_field_specs) url = '/projects/{}/applications/{}/reactorScript'.format( project_id, application_id) return utils.request('PUT', url, data=kwargs, api_key=api_key)
def delete_location(thng, api_key=None, request_kwargs=None): assertions.datatype_str('thng', thng) url = '/thngs/{}/location'.format(thng) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def delete_device_thng(thng, api_key=None, request_kwargs=None): assertions.datatype_str('thng', thng) url = '/auth/evrythng/thngs/{}'.format(thng) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def update_reactor_bundle(project_id, application_id, bundle_bytes, api_key=None, request_kwargs=None): """ Update a Reactor via a bundle of files; A zip file containing main.js, package.json, etc. :param project_id: The ID of the Project. :type project_id: str :param application_id: The ID for the Application that is a child of the Project for which the reactor script will be scoped to. :type application_id: str :param bundle_bytes: The bytes that make up the Zip file containing the bundle of files. :type bundle_bytes: bytes :param api_key: The API key to authorize request against. :type api_key: str :return: """ kwargs = locals() del kwargs['request_kwargs'] api_key = kwargs.pop('api_key', None) project_id = kwargs.pop('project_id') assertions.datatype_str('project_id', project_id) application_id = kwargs.pop('application_id') assertions.datatype_str('application_id', application_id) assertions.validate_field_specs(kwargs, reactor_bundle_field_specs) url = '/projects/{}/applications/{}/reactorScript'.format( project_id, application_id) files = {'file': bundle_bytes} return utils.request('PUT', url, files=files, api_key=api_key, **(request_kwargs or {}))
def delete_product(product, api_key=None, request_kwargs=None): assertions.datatype_str('product', product) url = '/products/{}'.format(product) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def create_device_thng(thng, thngApiKey, api_key=None, request_kwargs=None): assertions.datatype_str('thng', thng) assertions.datatype_str('thngApiKey', thngApiKey) data = {'thng': thng, 'thngApiKey': thngApiKey} return utils.request( 'POST', '/auth/evrythng/thngs', data=data, api_key=api_key, **(request_kwargs or {}))
def list_product_properties(product, from_date=None, to_date=None, **request_kwargs): """List all Properties on a Product.""" assertions.datatype_str('product', product) url = '/products/{}/properties'.format(product) return utils.request('GET', url, **request_kwargs)
def upsert_product_property(product, key, values, **request_kwargs): """Create/Update a single Property on a Product. POST /products/{$product}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('product', product) return _upsert_property('products', product, key, values, **request_kwargs)
def read_thng(thng, api_key=None, request_kwargs=None): assertions.datatype_str('thng', thng) url = '/thngs/{}'.format(thng) return utils.request('GET', url, api_key=api_key, accept=True, **(request_kwargs or {}))
def read_thng_property(thng, property_name, timestamp_from=None, timestamp_to=None, api_key=None, request_kwargs=None): """Read a Thng Property.""" assertions.datatype_str('thng', thng) return _read_property(thng, 'thngs', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key, request_kwargs=request_kwargs)
def delete_user(user, api_key=None, request_kwargs=None): """Delete a User.""" assertions.datatype_str('user', user) url = '/users/{}'.format(user) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def upsert_thng_property(thng_id, key, values, **request_kwargs): """Create/Update a single Property on a Thng. POST /thngs/{$thng_id}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('thng_id', thng_id) return _upsert_property('thngs', thng_id, key, values, **request_kwargs)
def upsert_product_property(product_id, key, values, **request_kwargs): """Create/Update a single Property on a Product. POST /products/{$product_id}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('product_id', product_id) return _upsert_property('products', product_id, key, values, **request_kwargs)
def create_device_thng(thng, thngApiKey, api_key=None): assertions.datatype_str('thng', thng) assertions.datatype_str('thngApiKey', thngApiKey) data = {'thng': thng, 'thngApiKey': thngApiKey} return utils.request('POST', '/auth/evrythng/thngs', data=data, api_key=api_key)
def read_product_property(product, property_name, timestamp_from=None, timestamp_to=None, api_key=None, request_kwargs=None): """Read a Product Property.""" assertions.datatype_str('product', product) return _read_property(product, 'products', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key, request_kwargs=request_kwargs)
def upsert_thng_property(thng, key, values, **request_kwargs): """Create/Update a single Property on a Thng. POST /thngs/{$thng}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('thng', thng) return _upsert_property('thngs', thng, key, values, **request_kwargs)
def list_product_properties(product_id, api_key=None): """List all Properties on a Product. TODO: add filtering capability. """ assertions.datatype_str('product_id', product_id) url = '/products/{}/properties'.format(product_id) return utils.request('GET', url, api_key=api_key)
def list_thng_properties(thng_id, api_key=None): """List all Properties on a thng. TODO: add filtering capability. """ assertions.datatype_str('thng_id', thng_id) url = '/thngs/{}/properties'.format(thng_id) return utils.request('GET', url, api_key=api_key)
def delete_action(type_, action, api_key=None, request_kwargs=None): """Delete an Action""" assertions.datatype_str('type_', type_) assertions.datatype_str('action', action) url = '/actions/{}/{}'.format(type_, action) return utils.request('DELETE', url, api_key=api_key, **(request_kwargs or {}))
def delete_product_property(product, property_name, timestamp_from=None, timestamp_to=None, api_key=None, request_kwargs=None): """Delete a Property on a Product.""" assertions.datatype_str('product', product) return _delete_property(product, 'products', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key, request_kwargs=request_kwargs)
def delete_thng_property(thng, property_name, timestamp_from=None, timestamp_to=None, api_key=None, request_kwargs=None): """Delete a Property on a Thng.""" assertions.datatype_str('thng', thng) return _delete_property(thng, 'thngs', property_name, timestamp_from=timestamp_from, timestamp_to=timestamp_to, api_key=api_key, request_kwargs=request_kwargs)
def upsert_thng_property(thng, key, values, api_key=None, request_kwargs=None): """Create/Update a single Property on a Thng. POST /thngs/{$thng}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('thng', thng) return _upsert_property('thngs', thng, key, values, api_key=api_key, request_kwargs=request_kwargs)
def authenticate_facebook_user(expires, token, api_key=None): assertions.datatype_str('token', token) data = { 'access': { 'expires': expires, 'token': token, } } return utils.request('POST', '/auth/facebook', data=data, api_key=api_key)
def list_thng_properties(thng, from_date=None, to_date=None, api_key=None, request_kwargs=None): """List all Properties on a thng.""" assertions.datatype_str('thng', thng) url = '/thngs/{}/properties'.format(thng) return utils.request('GET', url, api_key=api_key, **(request_kwargs or {}))
def upsert_product_property(product, key, values, api_key=None, request_kwargs=None): """Create/Update a single Property on a Product. POST /products/{$product}/properties/{$key} {"value": {$value}} """ assertions.datatype_str('product', product) return _upsert_property('products', product, key, values, api_key=api_key, request_kwargs=request_kwargs)
def authenticate_user(email, password, api_key=None): """ Bad HTTP response status meaning: 401 = Wrong password. 403 = User status is not 'active'. 404 = User not found. """ assertions.datatype_str('email', email) assertions.datatype_str('password', password) data = {'email': email, 'password': password} return utils.request('POST', '/auth/evrythng', data=data, api_key=api_key)
def _delete_property(evrythng_id, evrythng_type, property_name, timestamp_from=None, timestamp_to=None, **request_kwargs): """Helper for deleting properties.""" assertions.datatype_str('property_name', property_name) query_params = {} if timestamp_from: assertions.datatype_time('timestamp', timestamp_from) query_params['from'] = timestamp_from if timestamp_to: assertions.datatype_time('timestamp', timestamp_to) query_params['to'] = timestamp_to url = '/{}/{}/properties/{}'.format(evrythng_type, evrythng_id, property_name) return utils.request('DELETE', url, query_params=query_params, **request_kwargs)
def delete_collection(collection_id, api_key=None): """ Delete an existing Collection. :param collection_id: The Collection to delete. :type collection_id: str :param api_key: :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}'.format(collection_id) return utils.request('DELETE', url, api_key=api_key)
def delete_all_collection_thngs(collection_id, api_key=None): """ Delete *ALL* Thngs from a Collection. :param collection_id: The Collection to remove *all* Thngs from. :type collection_id: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}/collections'.format(collection_id) return utils.request('DELETE', url, api_key=api_key, accept=True)
def read_collection(collection, api_key=None): """ Read a Collection. :param collection: The Collection to read. :type collection: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection', collection) url = '/collections/{}'.format(collection) return utils.request('GET', url, api_key=api_key)
def read_collections_from_collection(collection_id, api_key=None): """ Read the Collections of a Collection. :param collection_id: The Collection to read the Collections of. :type collection_id: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}/collections'.format(collection_id) return utils.request('GET', url, api_key=api_key, accept=True)
def list_collection_thngs(collection, api_key=None): """ List a Collection's Thngs. :param collection: The Collection to list Thngs for. :type collection: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection', collection) url = '/collections/{}/thngs'.format(collection) return utils.request('GET', url, api_key=api_key, accept=True)
def delete_all_collections_from_collection(collection, api_key=None): """ Delete *ALL* Collections from a Collection. :param collection: The Collection to remove *all* Collections from. :type collection: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection', collection) url = '/collections/{}/collections'.format(collection) return utils.request('DELETE', url, api_key=api_key, accept=True)
def delete_collection(collection, api_key=None): """ Delete an existing Collection. :param collection: The Collection to delete. :type collection: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection', collection) url = '/collections/{}'.format(collection) return utils.request('DELETE', url, api_key=api_key)
def list_collection_thngs(collection_id, api_key=None): """ List a Collection's Thngs. :param collection_id: The Collection to list Thngs for. :type collection_id: str :param api_key: :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}/thngs'.format(collection_id) return utils.request('GET', url, api_key=api_key, accept=True)
def delete_all_collections_from_collection(collection_id, api_key=None): """ Delete *ALL* Collections from a Collection. :param collection_id: The Collection to remove *all* Collections from. :type collection_id: str :param api_key: :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}/collections'.format(collection_id) return utils.request('DELETE', url, api_key=api_key, accept=True)
def read_collection(collection_id, api_key=None): """ Read a Collection. :param collection_id: The Collection to read. :type collection_id: str :param api_key: :type api_key: str :return :rtype """ assertions.datatype_str('collection_id', collection_id) url = '/collections/{}'.format(collection_id) return utils.request('GET', url, api_key=api_key)
def read_collection(collection, api_key=None, request_kwargs=None): """ Read a Collection. :param collection: The Collection to read. :type collection: str :param api_key: The API key to authorize request against. :type api_key: str :return :rtype """ assertions.datatype_str('collection', collection) url = '/collections/{}'.format(collection) return utils.request('GET', url, api_key=api_key, **(request_kwargs or {}))
def delete_project(project_id, api_key=None): """ Delete a Project. :param project_id: The ID of the Project entity. :type project_id: str :param api_key: The API key to authorize the request against. :type api_key: str :return Blank string. :rtype Response """ assertions.datatype_str('project_id', project_id) url = '/projects/{}'.format(project_id) logger.debug('Deleting Project {}'.format(project_id)) return utils.request('DELETE', url, api_key=api_key, accept=True)
def read_project(project_id, api_key=None): """ Read a Project. :param project_id: The ID of the Project entity. :type project_id: str :param api_key: The API key to authorize the request against. :type api_key: str :return A Project document. :rtype Response """ assertions.datatype_str('project_id', project_id) url = '/projects/{}'.format(project_id) logger.debug('Reading Project {}'.format(project_id)) return utils.request('GET', url, api_key=api_key, accept=True)