Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,25 @@ This example exports all the available data from a specific room in your DocuSig
This example adds a standard real estate related form to a specific room in your DocuSign Rooms account.
1. **How to search for rooms with filters.**
[Source.](./app/rooms/examples/eg005_get_rooms_with_filters/controller.py)
This example demonstrates how to return rooms that have had their field data,
updated within the time period between <b>Start date</b> and <b>End date</b>.
1. **Create an external form fillable session.**
[Source.](./app/rooms/examples/eg006_create_external_form_fill_session/controller.py)
<!--
This example demonstrates how to create an
<a href="https://developers.docusign.com/rooms-api/guides/forms" target="_blank">external form fill session</a>
using the Rooms API:</br>
the result of this code example is the URL for the form fill session, which you can embed
in your integration or send to the user.
1. **Create a form group**
[Source.](./app/rooms/examples/eg007_create_form_group/controller.py)
This example demonstrates creating a DocuSign Form Group.
1. **Grant office access to a form group**
[Source.](./app/rooms/examples/eg008_grant_office_access_to_form_group/controller.py)
This example demonstrates how to grant Office access to a Form Group.
1. **Assign a form to a form group**
[Source.](./app/rooms/examples/eg009_assign_form_to_form_group/controller.py)
This example demonstrates how to assign a form to a form group.
<!--
## Click API

1. **Create a clickwrap.**
Expand Down
3 changes: 3 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
app.register_blueprint(rooms_examples.eg004)
app.register_blueprint(rooms_examples.eg005)
app.register_blueprint(rooms_examples.eg006)
app.register_blueprint(rooms_examples.eg007)
app.register_blueprint(rooms_examples.eg008)
app.register_blueprint(rooms_examples.eg009)
# elif EXAMPLES_API_TYPE["Click"]:
# app.register_blueprint(click_examples.eg001)
# app.register_blueprint(click_examples.eg002)
Expand Down
3 changes: 3 additions & 0 deletions app/rooms/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
from .eg004_add_forms_to_room import eg004
from .eg005_get_rooms_with_filters import eg005
from .eg006_create_external_form_fill_session import eg006
from .eg007_create_form_group import eg007
from .eg008_grant_office_access_to_form_group import eg008
from .eg009_assign_form_to_form_group import eg009
1 change: 1 addition & 0 deletions app/rooms/examples/eg007_create_form_group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .views import eg007
37 changes: 37 additions & 0 deletions app/rooms/examples/eg007_create_form_group/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from docusign_rooms import FormGroupForCreate, FormGroupsApi
from flask import session, request

from app.rooms import create_rooms_api_client


class Eg007Controller:
@staticmethod
def get_args():
"""Get required session and request arguments"""
return {
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
"form_group_name": request.form.get("form_group_name"),
}

@staticmethod
def worker(args):
"""
1. Create an API client with headers
2. Create FormGroupForCreate object
3. POST the form using SDK
"""

# Step 1. Create an API with headers
api_client = create_rooms_api_client(access_token=args["access_token"])

# Step 2. Create FormGroupForCreate object
form = FormGroupForCreate(name=args["form_group_name"])

# Step 3. Post the form object using SDK
form_groups_api = FormGroupsApi(api_client)
response = form_groups_api.create_form_group(
body=form, account_id=args["account_id"]
)

return response
57 changes: 57 additions & 0 deletions app/rooms/examples/eg007_create_form_group/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import json
from os import path

from docusign_rooms.client.api_exception import ApiException
from flask import Blueprint, render_template, current_app

from app.docusign import authenticate
from app.error_handlers import process_error
from .controller import Eg007Controller

eg = "eg007" # reference (and URL) for this example
eg007 = Blueprint(eg, __name__)


@eg007.route("/eg007", methods=["POST"])
@authenticate(eg=eg)
def create_form_group():
"""
1. Get required arguments
2. Call the worker method
3. Render the response
"""

# 1. Get required arguments
args = Eg007Controller.get_args()

try:
# 2. Call the worker method to create a new form group
results = Eg007Controller.worker(args)
form_id = results.form_group_id
current_app.logger.info(
f"""Form Group "{args['form_group_name']}" has been created!
Form Group ID: {form_id}"""
)
except ApiException as err:
return process_error(err)

# 3. Render the response
return render_template(
"example_done.html",
title="Creating a form group",
h1="Creating a form group",
message=f"""The Form Group "{args['form_group_name']}" has been created!<br/>
Room ID: {form_id}.""",
json=json.dumps(json.dumps(results.to_dict(), default=str))
)


@eg007.route("/eg007", methods=["GET"])
@authenticate(eg=eg)
def get_view():
"""responds with the form for the example"""
return render_template(
"eg007_create_form_group.html",
title="Creating a form group",
source_file=path.basename(path.dirname(__file__)) + "/controller.py"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .views import eg008
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from docusign_rooms import (
FormGroupsApi,
FormGroupSummaryList,
OfficesApi,
OfficeSummaryList,
)
from flask import session, request

from app.rooms import create_rooms_api_client


class Eg008Controller:
@staticmethod
def get_args():
"""Get required session and request arguments"""
return {
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
"form_group_id": request.form.get("form_group_id"),
"office_id": request.form.get("office_id")
}

@staticmethod
def get_form_groups(args):
"""
1. Create an API Client with headers
2. GET Form Groups via FormGroupsAPI
"""

# Step 1. Create an API with headers with headers
api_client = create_rooms_api_client(access_token=args["access_token"])

# Step 2. GET Form Groups via FormGroupsAPI
form_groups_api = FormGroupsApi(api_client)
response = form_groups_api.get_form_groups(account_id=args["account_id"]) # type: FormGroupSummaryList

return response.form_groups

@staticmethod
def get_offices(args):
"""
1. Create an API Client with headers
2. Get Offices via OfficesAPI
"""

# Step 1. Create an API with headers with headers
api_client = create_rooms_api_client(args["access_token"])

# Step 2. GET offices via OfficesAPI
offices_api = OfficesApi(api_client=api_client)
response = offices_api.get_offices(account_id=args["account_id"]) # type: OfficeSummaryList

return response.office_summaries

@staticmethod
def worker(args):
"""
1. Create an API client with headers
2. Grant office access to a form group via FormGroups API
"""

# Step 1. Create an API client with headers
api_client = create_rooms_api_client(access_token=args["access_token"])

# Step 2. Grant office access to a form group via FormGroups API
form_groups_api = FormGroupsApi(api_client)

form_groups_api.grant_office_access_to_form_group(
form_group_id=args["form_group_id"], office_id=args["office_id"],
account_id=args["account_id"]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from docusign_rooms.client.api_exception import ApiException
from flask import Blueprint, render_template, current_app

from app.docusign import authenticate
from app.error_handlers import process_error
from .controller import Eg008Controller

eg = "eg008" # reference (and URL) for this example
eg008 = Blueprint(eg, __name__)


@eg008.route("/eg008", methods=["POST"])
@authenticate(eg=eg)
def assign_office_to_form_group():
"""
1. Get required arguments
2. Call the worker method
3. Render the response
"""

args = Eg008Controller.get_args()

try:
# 2. Call the worker method to assign office to form group
Eg008Controller.worker(args)
current_app.logger.info(
f"""Office {args['office_id']} has been assigned to Form Group
{args['form_group_id']}!"""
)
except ApiException as err:
return process_error(err)

# 3. Render the response
return render_template(
"example_done.html",
title="Assign office to a form group",
h1="Assign office to a form group",
message=f"""Office "{args['office_id']}" has been assigned to
Form Group "{args['form_group_id']}" """,
)


@eg008.route("/eg008", methods=["GET"])
@authenticate(eg=eg)
def get_view():
"""
1. Get required arguments
2. Get Form Groups
3. Get Offices
4. Render the response
"""

# 1. Get required arguments
args = Eg008Controller.get_args()

# 2. Get Form Groups
form_groups = Eg008Controller.get_form_groups(args)

# 3. Get offices
offices = Eg008Controller.get_offices(args)

# 4. Render the response
return render_template(
"eg008_grant_office_access_to_form_group.html",
offices=offices,
form_groups=form_groups
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .views import eg009
91 changes: 91 additions & 0 deletions app/rooms/examples/eg009_assign_form_to_form_group/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from docusign_rooms import (
FormGroupsApi,
FormGroupSummaryList,
FormLibrariesApi,
FormGroupFormToAssign,
)
from docusign_rooms import FormSummaryList
from flask import session, request

from app.rooms import create_rooms_api_client


class Eg009Controller:
@staticmethod
def get_args():
"""Get required session and request arguments"""
return {
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
"form_group_id": request.form.get("form_group_id"),
"form_id": request.form.get("form_id")
}

@staticmethod
def get_form_groups(args):
"""
1. Create an API Client with headers
2. GET Form Groups via FormGroupsAPI
"""

# Step 1. Create an API with headers with headers
api_client = create_rooms_api_client(access_token=args["access_token"])

# Step 2. GET Form Groups via FormGroupsAPI
form_groups_api = FormGroupsApi(api_client)
response = form_groups_api.get_form_groups(
account_id=args["account_id"]
) # type: FormGroupSummaryList

return response.form_groups

@staticmethod
def get_forms(args):
"""
1. Create an API client with headers
2. Get first form library id
3. Get forms
"""

# Step 1. Create an API client with headers
api_client = create_rooms_api_client(access_token=args["access_token"])

# Step 2. Get first form library id
form_libraries_api = FormLibrariesApi(api_client)
form_libraries = form_libraries_api.get_form_libraries(
account_id=args["account_id"]
)

first_form_library_id = form_libraries.forms_library_summaries[0].forms_library_id

# Step 3. Get forms
form_library_forms = form_libraries_api.get_form_library_forms(
form_library_id=first_form_library_id, account_id=args["account_id"]
) # type: FormSummaryList

return form_library_forms.forms

@staticmethod
def worker(args):
"""
1. Create an API Client with headers
2. Create FormGroupFormToAssign Object
3. Assign form to a form group via FormGroups API
"""

# Step 1. Create an API client with headers
api_client = create_rooms_api_client(access_token=args["access_token"])
form_groups_api = FormGroupsApi(api_client)

# Step 2. Create FormGroupFormToAssign Object
form_group_to_assign = FormGroupFormToAssign(
form_id=args["form_id"], is_required=True
)

# Step 3. Assign form to a form group via FormGroups API
response = form_groups_api.assign_form_group_form(
form_group_id=args["form_group_id"], account_id=args["account_id"],
body=form_group_to_assign
) # type: FormGroupFormToAssign

return response
Loading