Skip to content

Commit

Permalink
CTOOLS-408: Updated example template (#43)
Browse files Browse the repository at this point in the history
* CTOOLS-408: Updated example template

* CTOOLS-408: Corrected extra white space

* CTOOLS-408: Removing extra space
  • Loading branch information
Matt-Storey-Finbourne authored Nov 25, 2024
1 parent 6a1bdd1 commit 2f87fe1
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions generate/templates/example.mustache
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
```python
{{#asyncio}}import asyncio{{/asyncio}}
from {{{packageName}}}.exceptions import ApiException
from {{{packageName}}}.extensions.configuration_options import ConfigurationOptions
from {{{modelPackage}}} import *
from pprint import pprint
from {{packageName}} import (
ApiClientFactory,
SyncApiClientFactory,
{{{classname}}}
)

{{#asyncio}}async {{/asyncio}}def main():
def main():

with open("secrets.json", "w") as file:
file.write('''
{
"api":
{
"tokenUrl":"<your-token-url>",
"{{#lambda.camelcase}}{{application}}{{/lambda.camelcase}}Url":"https://<your-domain>.lusid.com{{basePathWithoutHost}}",
"username":"<your-username>",
"password":"<your-password>",
"clientId":"<your-client-id>",
"clientSecret":"<your-client-secret>"
}
}''')
"api":
{
"tokenUrl":"<your-token-url>",
"{{#lambda.camelcase}}{{application}}{{/lambda.camelcase}}Url":"https://<your-domain>.lusid.com{{basePathWithoutHost}}",
"username":"<your-username>",
"password":"<your-password>",
"clientId":"<your-client-id>",
"clientSecret":"<your-client-secret>"
}
}''')

# Use the {{packageName}} ApiClientFactory to build Api instances with a configured api client
# Use the {{packageName}} SyncApiClientFactory to build Api instances with a configured api client
# By default this will read config from environment variables
# Then from a secrets.json file found in the current working directory

Expand All @@ -34,36 +33,37 @@ from {{packageName}} import (
# opts.total_timeout_ms = 30_000

# uncomment the below to use an api client factory with overrides
# api_client_factory = ApiClientFactory(opts=opts)
# api_client_factory = SyncApiClientFactory(opts=opts)

api_client_factory = ApiClientFactory()
api_client_factory = SyncApiClientFactory()

# Enter a context with an instance of the ApiClientFactory to ensure the connection pool is closed after use
{{#asyncio}}async {{/asyncio}}with api_client_factory:
# Create an instance of the API class
api_instance = api_client_factory.build({{{classname}}})
{{#allParams}}
{{^isModel}}
{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/isModel}}{{#isModel}}
# Objects can be created either via the class constructor, or using the 'from_dict' or 'from_json' methods
# Change the lines below to switch approach
# {{paramName}} = {{{dataType}}}.from_json("")
# {{paramName}} = {{{dataType}}}.from_dict({})
{{paramName}} = {{{dataType}}}(){{/isModel}}
{{/allParams}}
# Enter a context with an instance of the SyncApiClientFactory to ensure the connection pool is closed after use

# Create an instance of the API class
api_instance = api_client_factory.build({{{classname}}})
{{#allParams}}
{{^isModel}}
{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/isModel}}{{#isModel}}
# Objects can be created either via the class constructor, or using the 'from_dict' or 'from_json' methods
# Change the lines below to switch approach
# {{paramName}} = {{{dataType}}}.from_json("")
# {{paramName}} = {{{dataType}}}.from_dict({})
{{paramName}} = {{{dataType}}}(){{/isModel}}
{{/allParams}}

try:
# uncomment the below to set overrides at the request level
# {{#returnType}}api_response = {{/returnType}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}, {{/allParams}}opts=opts)
try:
# uncomment the below to set overrides at the request level
# {{#returnType}}api_response = {{/returnType}} api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}, {{/allParams}}opts=opts)

{{#summary}}
# {{{.}}}
{{/summary}}
{{#returnType}}api_response = {{/returnType}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
pprint(api_response)
{{/returnType}}
except ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
{{#summary}}
# {{{.}}}
{{/summary}}
{{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
pprint(api_response)
{{/returnType}}

{{#asyncio}}asyncio.run(main()){{/asyncio}}{{^asyncio}}main(){{/asyncio}}
except ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)

main()
```

0 comments on commit 2f87fe1

Please sign in to comment.