def update_service(self, service_id, service_name, active, message_limit, restricted, users, email_from, reply_to_email_address=None, sms_sender=None): """ Update a service. """ data = { "id": service_id, "name": service_name, "active": active, "message_limit": message_limit, "restricted": restricted, "users": users, "email_from": email_from, "reply_to_email_address": reply_to_email_address, "sms_sender": sms_sender } _attach_current_user(data) endpoint = "/service/{0}".format(service_id) return self.post(endpoint, data)
def create_api_key(self, service_id, key_name, key_type): data = { 'name': key_name, 'key_type': key_type } _attach_current_user(data) key = self.post(url='/service/{}/api-key'.format(service_id), data=data) return key['data']
def delete_service_template(self, service_id, template_id): """ Set a service template's archived flag to True """ endpoint = "/service/{0}/template/{1}".format(service_id, template_id) data = { 'archived': True } _attach_current_user(data) return self.post(endpoint, data=data)
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count): data = { "id": job_id, "template": template_id, "original_file_name": original_file_name, "notification_count": notification_count } _attach_current_user(data) resp = self.post(url='/service/{}/job'.format(service_id), data=data) return resp['data']
def create_invite(self, invite_from_id, service_id, email_address, permissions): data = { 'service': str(service_id), 'email_address': email_address, 'from_user': invite_from_id, 'permissions': permissions } _attach_current_user(data) resp = self.post(url='/service/{}/invite'.format(service_id), data=data) return InvitedUser(**resp['data'])
def create_service(self, service_name, active, message_limit, restricted, user_id, email_from): """ Create a service and return the json. """ data = { "name": service_name, "active": active, "message_limit": message_limit, "user_id": user_id, "restricted": restricted, "email_from": email_from } _attach_current_user(data) return self.post("/service", data)['data']['id']
def update_service( self, service_id, **kwargs ): """ Update a service. """ data = _attach_current_user(kwargs) disallowed_attributes = set(data.keys()) - { 'name', 'message_limit', 'active', 'restricted', 'email_from', 'reply_to_email_address', 'research_mode', 'can_send_letters', 'sms_sender', 'created_by', 'branding', 'organisation' } if disallowed_attributes: raise TypeError('Not allowed to update service attributes: {}'.format( ", ".join(disallowed_attributes) )) endpoint = "/service/{0}".format(service_id) return self.post(endpoint, data)
def delete_service(self, service_id): """ Delete a service. """ endpoint = "/service/{0}".format(service_id) data = _attach_current_user({}) return self.delete(endpoint, data)
def remove_user_from_service(self, service_id, user_id): """ Remove a user from a service """ endpoint = '/service/{service_id}/users/{user_id}'.format( service_id=service_id, user_id=user_id) data = _attach_current_user({}) return self.delete(endpoint, data)
def update_service_template_sender(self, service_id, template_id, reply_to): data = { 'reply_to': reply_to, } data = _attach_current_user(data) return self.post( "/service/{0}/template/{1}".format(service_id, template_id), data)
def delete_service_template(self, service_id, template_id): """ Set a service template's archived flag to True """ endpoint = "/service/{0}/template/{1}".format(service_id, template_id) data = {'archived': True} data = _attach_current_user(data) return self.post(endpoint, data=data)
def create_service_template(self, name, type_, content, service_id, subject=None): """ Create a service template. """ data = { "name": name, "template_type": type_, "content": content, "service": service_id } if subject: data.update({ 'subject': subject }) _attach_current_user(data) endpoint = "/service/{0}/template".format(service_id) return self.post(endpoint, data)
def update_broadcast_message_status(self, status, *, service_id, broadcast_message_id): data = _attach_current_user({ 'status': status, }) self.post( f'/service/{service_id}/broadcast-message/{broadcast_message_id}/status', data=data, )
def update_service_template(self, id_, name, type_, content, service_id, subject=None): """ Update a service template. """ data = { 'id': id_, 'name': name, 'template_type': type_, 'content': content, 'service': service_id } if subject: data.update({ 'subject': subject }) _attach_current_user(data) endpoint = "/service/{0}/template/{1}".format(service_id, id_) return self.post(endpoint, data)
def create_invite(self, invite_from_id, org_id, email_address): data = { 'email_address': email_address, 'invited_by': invite_from_id, 'invite_link_host': self.admin_url, } data = _attach_current_user(data) resp = self.post(url='/organisation/{}/invite'.format(org_id), data=data) return resp['data']
def send_precompiled_letter(self, service_id, filename, file_id, postage, recipient_address): data = { 'filename': filename, 'file_id': file_id, 'postage': postage, 'recipient_address': recipient_address } data = _attach_current_user(data) return self.post(url='/service/{}/send-pdf-letter'.format(service_id), data=data)
def create_invite(self, invite_from_id, org_id, email_address): data = { "email_address": email_address, "invited_by": invite_from_id, "invite_link_host": self.admin_url, } data = _attach_current_user(data) resp = self.post(url="/organisation/{}/invite".format(org_id), data=data) return resp["data"]
def send_notification(self, service_id, *, template_id, recipient, personalisation, sender_id): data = { "template_id": template_id, "to": recipient, "personalisation": personalisation, } if sender_id: data["sender_id"] = sender_id data = _attach_current_user(data) return self.post(url="/service/{}/send-notification".format(service_id), data=data)
def send_notification(self, service_id, *, template_id, recipient, personalisation, sender_id): data = { 'template_id': template_id, 'to': recipient, 'personalisation': personalisation, } if sender_id: data['sender_id'] = sender_id data = _attach_current_user(data) return self.post(url='/service/{}/send-notification'.format(service_id), data=data)
def create_invite(self, invite_from_id, service_id, email_address, permissions): data = { "service": str(service_id), "email_address": email_address, "from_user": invite_from_id, "permissions": permissions, } data = _attach_current_user(data) resp = self.post(url="/service/{}/invite".format(service_id), data=data) return InvitedUser(**resp["data"])
def create_invite(self, invite_from_id, service_id, email_address, permissions): data = { 'service': str(service_id), 'email_address': email_address, 'from_user': invite_from_id, 'permissions': permissions } data = _attach_current_user(data) resp = self.post(url='/service/{}/invite'.format(service_id), data=data) return InvitedUser(**resp['data'])
def create_invite(self, invite_from_id, service_id, email_address, permissions, auth_type): data = { 'service': str(service_id), 'email_address': email_address, 'from_user': invite_from_id, 'permissions': ','.join(sorted(translate_permissions_from_admin_roles_to_db(permissions))), 'auth_type': auth_type, 'invite_link_host': self.admin_url, } data = _attach_current_user(data) resp = self.post(url='/service/{}/invite'.format(service_id), data=data) return InvitedUser(**resp['data'])
def create_service(self, service_name, active, message_limit, restricted, user_id, email_from): """ Create a service and return the json. """ data = { "name": service_name, "active": active, "message_limit": message_limit, "user_id": user_id, "restricted": restricted, "email_from": email_from } data = _attach_current_user(data) return self.post("/service", data)['data']['id']
def create_job(self, job_id, service_id, scheduled_for=None): data = {"id": job_id} if scheduled_for: data.update({'scheduled_for': scheduled_for}) data = _attach_current_user(data) job = self.post(url='/service/{}/job'.format(service_id), data=data) redis_client.set( 'has_jobs-{}'.format(service_id), b'true', ex=cache.TTL, ) return job
def update_provider(self, provider_id, priority, active=None, supports_international=None): data = { "priority": priority, } if active is not None: data['active'] = active if supports_international is not None: data['supports_international'] = supports_international data = _attach_current_user(data) return self.post(url='/provider-details/{}'.format(provider_id), data=data)
def create_service_template(self, name, type_, content, service_id, subject=None): """ Create a service template. """ data = { "name": name, "template_type": type_, "content": content, "service": service_id } if subject: data.update({ 'subject': subject }) data = _attach_current_user(data) endpoint = "/service/{0}/template".format(service_id) return self.post(endpoint, data)
def update_service_template(self, id_, name, type_, content, service_id, subject=None): """ Update a service template. """ data = { 'id': id_, 'name': name, 'template_type': type_, 'content': content, 'service': service_id } if subject: data.update({ 'subject': subject }) data = _attach_current_user(data) endpoint = "/service/{0}/template/{1}".format(service_id, id_) return self.post(endpoint, data)
def update_service(self, service_id, **kwargs): """ Update a service. """ data = _attach_current_user(kwargs) disallowed_attributes = set(data.keys()) - { 'active', 'billing_contact_email_addresses', 'billing_contact_names', 'billing_reference', 'consent_to_research', 'contact_link', 'created_by', 'count_as_live', 'email_branding', 'email_from', 'free_sms_fragment_limit', 'go_live_at', 'go_live_user', 'letter_branding', 'letter_contact_block', 'message_limit', 'name', 'notes', 'organisation_type', 'permissions', 'prefix_sms', 'purchase_order_number', 'rate_limit', 'reply_to_email_address', 'research_mode', 'restricted', 'sms_sender', 'volume_email', 'volume_letter', 'volume_sms', } if disallowed_attributes: raise TypeError( 'Not allowed to update service attributes: {}'.format( ", ".join(disallowed_attributes))) endpoint = "/service/{0}".format(service_id) return self.post(endpoint, data)
def create_broadcast_message( self, *, service_id, template_id, ): data = { "service_id": service_id, "template_id": template_id, "personalisation": {}, } data = _attach_current_user(data) broadcast_message = self.post( f'/service/{service_id}/broadcast-message', data=data, ) return broadcast_message
def create_contact_list( self, *, service_id, upload_id, original_file_name, row_count, template_type, ): data = { "id": upload_id, "original_file_name": original_file_name, "row_count": row_count, "template_type": template_type, } data = _attach_current_user(data) job = self.post(url='/service/{}/contact-list'.format(service_id), data=data) return job
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count, scheduled_for=None): data = { "id": job_id, "template": template_id, "original_file_name": original_file_name, "notification_count": notification_count } if scheduled_for: data.update({'scheduled_for': scheduled_for}) data = _attach_current_user(data) job = self.post(url='/service/{}/job'.format(service_id), data=data) stats = self.__convert_statistics(job['data']) job['data']['notifications_sent'] = stats['delivered'] + stats['failed'] job['data']['notifications_delivered'] = stats['delivered'] job['data']['notifications_failed'] = stats['failed'] job['data']['notifications_requested'] = stats['requested'] return job
def create_job(self, job_id, service_id, scheduled_for=None): data = {"id": job_id} if scheduled_for: data.update({"scheduled_for": scheduled_for}) data = _attach_current_user(data) job = self.post(url="/service/{}/job".format(service_id), data=data) redis_client.set( "has_jobs-{}".format(service_id), b"true", ex=cache.TTL, ) stats = self.__convert_statistics(job["data"]) job["data"]["notifications_sent"] = stats["delivered"] + stats["failed"] job["data"]["notifications_delivered"] = stats["delivered"] job["data"]["notifications_failed"] = stats["failed"] job["data"]["notifications_requested"] = stats["requested"] return job
def create_job(self, job_id, service_id, scheduled_for=None): self.redis_client.set( 'has_jobs-{}'.format(service_id), b'true', ex=cache.TTL, ) data = {"id": job_id} if scheduled_for: data.update({'scheduled_for': scheduled_for}) data = _attach_current_user(data) job = self.post(url='/service/{}/job'.format(service_id), data=data) stats = self.__convert_statistics(job['data']) job['data']['notifications_sent'] = stats['delivered'] + stats['failed'] job['data']['notifications_delivered'] = stats['delivered'] job['data']['notifications_failed'] = stats['failed'] job['data']['notifications_requested'] = stats['requested'] return job
def create_service_template(self, name, type_, content, service_id, subject=None, process_type='normal', parent_folder_id=None): """ Create a service template. """ data = { "name": name, "template_type": type_, "content": content, "service": service_id, "process_type": process_type, } if subject: data.update({ 'subject': subject }) if parent_folder_id: data.update({ 'parent_folder_id': parent_folder_id }) data = _attach_current_user(data) endpoint = "/service/{0}/template".format(service_id) return self.post(endpoint, data)
def cancel_invited_user(self, org_id, invited_user_id): data = {'status': 'cancelled'} data = _attach_current_user(data) self.post(url='/organisation/{0}/invite/{1}'.format( org_id, invited_user_id), data=data)
def remove_user_from_organisation(self, org_id, user_id): endpoint = '/organisations/{}/users/{}'.format( org_id=org_id, user_id=user_id) data = _attach_current_user({}) return self.delete(endpoint, data)
def cancel_invited_user(self, service_id, invited_user_id): data = {'status': 'cancelled'} _attach_current_user(data) self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id), data=data)
def revoke_api_key(self, service_id, key_id): data = _attach_current_user({}) return self.post(url='/service/{0}/api-key/revoke/{1}'.format( service_id, key_id), data=data)
def cancel_invited_user(self, service_id, invited_user_id): data = {"status": "cancelled"} data = _attach_current_user(data) self.post(url="/service/{0}/invite/{1}".format(service_id, invited_user_id), data=data)
def update_service_template_postage(self, service_id, template_id, postage): return self.post( "/service/{0}/template/{1}".format(service_id, template_id), _attach_current_user({'postage': postage}))
def redact_service_template(self, service_id, id_): return self.post( "/service/{}/template/{}".format(service_id, id_), _attach_current_user({'redact_personalisation': True}), )
def update_provider(self, provider_id, priority): data = { "priority": priority } data = _attach_current_user(data) return self.post(url='/provider-details/{}'.format(provider_id), data=data)
def revoke_api_key(self, service_id, key_id): data = _attach_current_user({}) return self.post( url='/service/{0}/api-key/revoke/{1}'.format(service_id, key_id), data=data)
def update_service_with_properties(self, service_id, properties): _attach_current_user(properties) endpoint = "/service/{0}".format(service_id) return self.post(endpoint, properties)
def update_provider(self, provider_id, priority): data = {"priority": priority} data = _attach_current_user(data) return self.post(url="/provider-details/{}".format(provider_id), data=data)
def create_api_key(self, service_id, key_name, key_type): data = {'name': key_name, 'key_type': key_type} data = _attach_current_user(data) key = self.post(url='/service/{}/api-key'.format(service_id), data=data) return key['data']