Skip to content

Commit 0df921f

Browse files
authored
Merge pull request #111 from docusign/DEVDOCS-16547
Devdocs 16547
2 parents 30441a4 + a19b46c commit 0df921f

File tree

7 files changed

+356
-221
lines changed

7 files changed

+356
-221
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ UserData.csv
1111
config/API_ACCOUNT_ID
1212
config/CLICKWRAP_ID
1313
config/ds_access_token.txt
14+
examples/ConnectedFields/__pycache__/

examples/Maestro/eg001TriggerWorkflow.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fi
99

1010
workflow_created=$(cat config/WORKFLOW_ID)
1111
if [ -z "$workflow_created" ]; then
12-
bash ./examples/Maestro/utils.sh
12+
bash ./examples/Maestro/lib/utils.sh
1313
fi
1414

1515
#check that create workflow script ran successfully
@@ -161,6 +161,8 @@ echo ""
161161

162162
instance_url=$(grep '"instance_url":' $response | sed -n 's/.*"instance_url": "\([^"]*\)".*/\1/p')
163163
decoded_instance_url=$(echo $instance_url | sed 's/\\u0026/\&/g')
164+
echo "$decoded_instance_url" > config/INSTANCE_URL
165+
164166
echo ""
165167
echo "Use this URL to complete the workflow steps:"
166168
echo $decoded_instance_url
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# Embed a Maestro workflow instance using the URL returned from triggerWorkflow
3+
4+
# Ensure the script is run in a bash shell
5+
if [[ $SHELL != *"bash"* ]]; then
6+
echo "PROBLEM: Run these scripts from within the bash shell."
7+
fi
8+
9+
#Check that create workflow script ran successfully
10+
workflow_created=$(cat config/WORKFLOW_ID)
11+
if [ -z "$workflow_created" ]; then
12+
echo "please create a worklow before running this example"
13+
exit 0
14+
fi
15+
16+
#Check that the instance URL exists
17+
instance_url=$(cat config/INSTANCE_URL)
18+
if [ -z "$instance_url" ]; then
19+
echo "No instance URL found. Please run the trigger workflow script first."
20+
exit 1
21+
fi
22+
23+
# Launch local server and open in browser
24+
decoded_instance_url=$(echo "$instance_url" | sed 's/\\u0026/\&/g')
25+
26+
27+
host_url="http://localhost:8080"
28+
if which xdg-open &> /dev/null ; then
29+
xdg-open $host_url
30+
elif which open &> /dev/null ; then
31+
open $host_url
32+
elif which start &> /dev/null ; then
33+
start $host_url
34+
fi
35+
php ./examples/Maestro/lib/startServerForEmbeddedWorkflow.php "$decoded_instance_url"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
$PORT = '8080';
4+
$IP = 'localhost';
5+
6+
$state = bin2hex(random_bytes(5));
7+
8+
$triggerUrl = "$argv[1]";
9+
10+
$socket = 'tcp://' . $IP . ':' . $PORT;
11+
12+
$responseOk = "HTTP/1.0 200 OK\r\n"
13+
. "Content-Type: text/html\r\n\r\n"
14+
. "
15+
<!--
16+
#ds-snippet-start:eSign44Step6
17+
-->
18+
<br />
19+
<h2>The document has been embedded using Maestro Embedded Workflow.</h2>
20+
<br />
21+
22+
<!DOCTYPE html>
23+
<html>
24+
<head>
25+
<meta charset=\"utf-8\" />
26+
<title>Example Workflow</title>
27+
<style>
28+
html,
29+
body {
30+
padding: 0;
31+
margin: 0;
32+
font: 13px Helvetica, Arial, sans-serif;
33+
}
34+
</style>
35+
</head>
36+
<body>
37+
#ds-snippet-start:Maestro2Step3
38+
<div>
39+
<iframe src=$triggerUrl width=800 height=600>
40+
</iframe>
41+
</div>
42+
#ds-snippet-end:Maestro2Step3
43+
</body>
44+
</html>
45+
46+
<p><a>Continue</a></p>
47+
48+
<!--
49+
#ds-snippet-end:eSign44Step6
50+
-->";
51+
52+
ini_set('default_socket_timeout', 60 * 5);
53+
$server = stream_socket_server($socket, $errno, $errstr);
54+
if (!$server) {
55+
Log::err('Error starting HTTP server');
56+
return false;
57+
}
58+
do {
59+
$sock = stream_socket_accept($server);
60+
if (!$sock) {
61+
Log::err('Error accepting socket connection');
62+
exit(1);
63+
}
64+
$contentLength = 0;
65+
$headers = [];
66+
$body = null;
67+
while (false !== ($line = trim(fgets($sock)))) {
68+
if ($line === '') break;
69+
$regex = '#^Content-Length:\s*([[:digit:]]+)\s*$#i';
70+
if (preg_match($regex, $line, $matches)) {
71+
$contentLength = (int)$matches[1];
72+
}
73+
$headers[] = $line;
74+
}
75+
if ($contentLength > 0) {
76+
$body = fread($sock, $contentLength);
77+
}
78+
list($method, $url, $httpver) = explode(' ', $headers[0]);
79+
if ($method == 'GET') {
80+
fwrite($sock, $responseOk);
81+
fclose($sock);
82+
return;
83+
}
84+
} while (true);
85+
86+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ if [ -z "$TEMPLATE_ID" ]; then
1717
bash ./examples/eSignature/eg008CreateTemplate.sh
1818
fi
1919

20+
TEMPLATE_ID=$(cat config/TEMPLATE_ID)
21+
if [ -z "$TEMPLATE_ID" ]; then
22+
echo "please create a worklow before running this example"
23+
exit 0
24+
fi
25+
2026
TEMPLATE_ID=$(cat config/TEMPLATE_ID)
2127

2228
echo "Creating a new workflow"

0 commit comments

Comments
 (0)