Python API client for Directory forms .
Project description
directory-forms-api-client
Directory forms API client for headless forms.
Requirements
Installation
pip install directory_forms_api_client
Usage
The api client must be passed into each form instance, so first set the the client settings:
Setting | Notes |
---|---|
DIRECTORY_FORMS_API_BASE_URL | |
DIRECTORY_FORMS_API_API_KEY | Unique to client. Retrieved during the on-boarding process. |
DIRECTORY_FORMS_API_SENDER_ID | Unique to client. Retrieved during the on-boarding process. |
DIRECTORY_FORMS_DEFAULT_TIMEOUT |
Once that is done the forms can be used.
Submit to Zendesk
from directory_forms_api_client import forms
class ZendeskForm(forms.ZendeskAPIForm):
# note that the base form provides `requester_email` email field
title = fields.CharField()
form = ZendeskForm(data={
'name': 'Example Person',
'email': 'three@example.com'
})
assert form.is_valid()
form.save(
email_address=form.cleaned_data['email'],
full_name='Example Person',
subject='Bo in the house',
service_name='Foo Bar',
)
Different subdomain
The default behaviour of Forms API is to use the default configured zendesk subdomain when creating the tickets. To use a different subdomain, provide subdomain
:
form.save(
email_address=form.cleaned_data['email'],
full_name='Example Person',
subject='Some ticket subject',
subdomain='some-other-subdomain',
)
Note that Forms API must first be configured to expect the provided subdomain.
Send as email
Send to a user-submitted email address
from directory_forms_api_client import forms
class EmailForm(forms.ZendeskAPIForm):
title = fields.CharField()
email = fields.EmailField()
form = TestForm(data={'title': 'Example', 'email': 'a@foo.com'})
assert form.is_valid()
form.save(
recipients=[form.cleaned_data['email']],
subject='Some email subject',
reply_to=['reply@example.com'],
service_name='Foo Bar',
)
Send to a pre-defined email address
from directory_forms_api_client import forms
class EmailForm(forms.EmailAPIForm):
title = fields.CharField()
form = TestForm(data={'title': 'Example'})
assert form.is_valid()
form.save(submission_recipients=[settings.FEEDBACK_EMAIL_RECIPIENTS])
Send via gov.uk Notify
from directory_forms_api_client import forms
class GovNotifyForm(forms.GovNotifyAPIForm):
title = fields.CharField()
email = fields.EmailField()
form = TestForm(data={'title': 'Example', 'email': 'a@foo.com'})
assert form.is_valid()
form.save(
template_id='some-template-id-from-gov-notify',
email_address=form.cleaned_data['email'],
)
Development
$ git clone https://github.com/uktrade/directory-forms-api-client
$ cd directory-forms-api-client
# [create your virtual environment and activate it]
$ pip install -e . # install the requirements defined in setup.py
Testing
$ make test
Publish to PyPI
The package should be published to PyPI on merge to master. If you need to do it locally then get the credentials from rattic and add the environment variables to your host machine:
Setting |
---|
DIRECTORY_PYPI_USERNAME |
DIRECTORY_PYPI_PASSWORD |
Then run the following command:
make publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for directory_forms_api_client-3.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51250de35a87c8cd0edfcfaff3417d1d580702dcc23378fb72ab162c8b9df5fe |
|
MD5 | 21f81c50cc5fdd72df101f331037a847 |
|
BLAKE2b-256 | a78be2f16079049cbd3cc1c7c976b44f043ca73a31a73b6578e6fedfc964ab19 |