Skip to content

Commit 7a351ca

Browse files
authored
Clearer version number support, updates (anvilco#45)
* Really fix changelog * Update cast api call, cli, docs * Add additional variables for `createEtchPacket` mutation * Add missing webhookURL on ForgeSubmit * Add forgeSubmit example
1 parent bf5d983 commit 7a351ca

10 files changed

Lines changed: 95 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1.8.0 (2022-01-10)
1+
# 1.8.0 (2023-01-10)
22

33
- Added support for multipart uploads on `CreateEtchPacket` requests.
44
- New example for multipart uploads in `examples/create_etch_upload_file_multipart.py`

docs/api_usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ casts, but this can be changed with the `fields` argument.
119119

120120
* `eid` - The eid of the Cast
121121
* `fields` - (Optional) list of fields you want from the Cast instance.
122+
* `version_number` - (Optional) Version number of the cast to fill out. If this is not provided, the latest published
123+
version will be used.
122124

123125
### Anvil.get_welds
124126

examples/fill_pdf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ def main():
3838
# to a file.
3939
res = anvil.fill_pdf('abc123', data)
4040

41+
# Version number support
42+
# ----------------------
4143
# A version number can also be passed in. This will retrieve a specific
4244
# version of the PDF to be filled if you don't want the current version
4345
# to be used.
44-
# You can also use the constant `Anvil.VERSION_LATEST` to fill a PDF that has not
45-
# been published yet. Use this if you'd like to fill out a draft version of
46-
# your template/PDF.
46+
#
47+
# You can also use the constant `Anvil.VERSION_LATEST` to fill a PDF with
48+
# your latest, unpublished changes. Use this if you'd like to fill out a
49+
# draft version of your template/PDF.
4750
#
4851
# res = anvil.fill_pdf('abc123', data, version_number=Anvil.VERSION_LATEST)
4952

examples/forge_submit.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
3+
from python_anvil.api import Anvil
4+
from python_anvil.api_resources.payload import ForgeSubmitPayload
5+
6+
API_KEY = os.environ.get("ANVIL_API_KEY")
7+
# or set your own key here
8+
# API_KEY = 'my-api-key'
9+
10+
11+
def main():
12+
anvil = Anvil(api_key=API_KEY)
13+
14+
# Your ForgeSubmit payload.
15+
# In this example, we have a basic Webform containing a name and email field.
16+
# For both fields, we are using the field's eid which can be found in the
17+
# weld or forge GraphQL query.
18+
# More info here: https://www.useanvil.com/docs/api/graphql/reference/#definition-Forge
19+
payload = ForgeSubmitPayload(
20+
forge_eid="myForgeEidHere",
21+
payload=dict(
22+
forge16401fc09c3e11ed85f5a91873b464b4="FirstName LastName",
23+
forge1b57aeb09c3e11ed85f5a91873b464b4="[email protected]",
24+
),
25+
)
26+
27+
# Submit the above payload
28+
res = anvil.forge_submit(payload)
29+
print(res)
30+
31+
32+
if __name__ == '__main__':
33+
main()

python_anvil/api.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,37 @@ def generate_pdf(self, payload: Union[AnyStr, Dict, GeneratePDFPayload], **kwarg
146146
"generate-pdf", data=data.dict(by_alias=True, exclude_none=True), **kwargs
147147
)
148148

149-
def get_cast(self, eid: str, fields=None, **kwargs):
149+
def get_cast(
150+
self,
151+
eid: str,
152+
fields: Optional[List[str]] = None,
153+
version_number: Optional[int] = None,
154+
cast_args: Optional[List[str]] = None,
155+
**kwargs,
156+
):
157+
150158
if not fields:
151159
# Use default fields
152160
fields = ['eid', 'title', 'fieldInfo']
153161

162+
if not cast_args:
163+
cast_args = []
164+
165+
cast_args.append(('eid', f'"{eid}"'))
166+
167+
# If `version_number` isn't provided, the API will default to the
168+
# latest published version.
169+
if version_number:
170+
cast_args.append(("versionNumber", str(version_number)))
171+
172+
arg_str = ""
173+
if len(cast_args):
174+
joined_args = [(":".join(arg)) for arg in cast_args]
175+
arg_str = f"({','.join(joined_args)})"
176+
154177
res = self.query(
155178
f"""{{
156-
cast(eid: "{eid}") {{
179+
cast {arg_str} {{
157180
{" ".join(fields)}
158181
}}
159182
}}""",

python_anvil/api_resources/cast.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

python_anvil/api_resources/mutations/create_etch_packet.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
$replyToName: String,
5757
$replyToEmail: String,
5858
$data: JSON,
59+
$enableEmails: JSON,
60+
$createCastTemplatesFromUploads: Boolean,
61+
$duplicateCasts: Boolean=false,
5962
) {{
6063
createEtchPacket (
6164
name: $name,
@@ -71,7 +74,10 @@
7174
webhookURL: $webhookURL,
7275
replyToName: $replyToName,
7376
replyToEmail: $replyToEmail,
74-
data: $data
77+
data: $data,
78+
enableEmails: $enableEmails,
79+
createCastTemplatesFromUploads: $createCastTemplatesFromUploads,
80+
duplicateCasts: $duplicateCasts
7581
)
7682
{query}
7783
}}
@@ -82,7 +88,7 @@ class CreateEtchPacket(BaseQuery):
8288
mutation = CREATE_ETCH_PACKET
8389
mutation_res_query = DEFAULT_RESPONSE_QUERY
8490

85-
def __init__(
91+
def __init__( # pylint: disable=too-many-locals
8692
self,
8793
name: Optional[str] = None,
8894
signature_email_subject: Optional[str] = None,
@@ -98,6 +104,9 @@ def __init__(
98104
reply_to_name: Optional[str] = None,
99105
reply_to_email: Optional[str] = None,
100106
merge_pdfs: Optional[bool] = None,
107+
enable_emails: Optional[Union[bool, List[str]]] = None,
108+
create_cast_templates_from_uploads: Optional[bool] = None,
109+
duplicate_casts: Optional[bool] = None,
101110
):
102111
# `name` is required when `payload` is not present.
103112
if not payload and not name:
@@ -120,6 +129,9 @@ def __init__(
120129
self.reply_to_name = reply_to_name
121130
self.reply_to_email = reply_to_email
122131
self.merge_pdfs = merge_pdfs
132+
self.enable_emails = enable_emails
133+
self.create_cast_templates_from_uploads = create_cast_templates_from_uploads
134+
self.duplicate_casts = duplicate_casts
123135

124136
@classmethod
125137
def create_from_dict(cls, payload: Dict) -> 'CreateEtchPacket':
@@ -268,6 +280,9 @@ def create_payload(self) -> Tuple[CreateEtchPacketPayload, List]:
268280
reply_to_email=self.reply_to_email,
269281
reply_to_name=self.reply_to_name,
270282
merge_pdfs=self.merge_pdfs,
283+
enable_emails=self.enable_emails,
284+
create_cast_templates_from_uploads=self.create_cast_templates_from_uploads,
285+
duplicate_casts=self.duplicate_casts,
271286
)
272287

273288
return payload, file_refs

python_anvil/api_resources/mutations/forge_submit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
$groupArrayId: String,
4949
$groupArrayIndex: Int,
5050
$errorType: String,
51+
$webhookURL: String,
5152
) {{
5253
forgeSubmit (
5354
forgeEid: $forgeEid,
@@ -60,7 +61,8 @@
6061
timezone: $timezone,
6162
groupArrayId: $groupArrayId,
6263
groupArrayIndex: $groupArrayIndex,
63-
errorType: $errorType
64+
errorType: $errorType,
65+
webhookURL: $webhookURL
6466
) {query}
6567
}}
6668
"""

python_anvil/api_resources/payload.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ class CreateEtchPacketPayload(BaseModel):
230230
webhook_url: Optional[str] = Field(None, alias="webhookURL")
231231
reply_to_name: Optional[Any] = None
232232
reply_to_email: Optional[Any] = None
233+
enable_emails: Optional[Union[bool, List[str]]] = None
234+
create_cast_templates_from_uploads: Optional[bool] = None
235+
duplicate_casts: Optional[bool] = None
233236

234237

235238
class ForgeSubmitPayload(BaseModel):

python_anvil/cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,19 @@ def weld(ctx, eid, list_all):
125125
@click.option(
126126
"-a", "--all", "list_all", help="List all casts, even non-templates", is_flag=True
127127
)
128+
@click.option("--version_number", help="Get the specified version of this cast")
128129
@click.argument("eid", default="")
129130
@click.pass_context
130-
def cast(ctx, eid, list_all, list_templates):
131+
def cast(ctx, eid, version_number, list_all, list_templates):
131132
"""Fetch Cast data given a Cast eid."""
132-
anvil = ctx.obj["anvil"]
133+
anvil = ctx.obj["anvil"] # type: Anvil
133134
debug = ctx.obj["debug"]
134135

135136
if not eid and not (list_templates or list_all):
136137
raise AssertionError("Cast eid or --list/--all option required")
137138

138139
if list_all or list_templates:
139-
res = anvil.get_casts(debug=debug, show_all=list_all)
140+
res = anvil.get_casts(show_all=list_all, debug=debug)
140141

141142
if contains_headers(res):
142143
res, headers = process_response(res)
@@ -149,7 +150,7 @@ def cast(ctx, eid, list_all, list_templates):
149150

150151
if eid:
151152
click.echo(f"Getting cast with eid '{eid}' \n")
152-
res = anvil.get_cast(eid, debug=debug)
153+
res = anvil.get_cast(eid, version_number=version_number, debug=debug)
153154

154155
if contains_headers(res):
155156
res, headers = process_response(res)

0 commit comments

Comments
 (0)