Skip to content

Commit c03d320

Browse files
committed
aAdd function set_api_url to set the Carbone API URL (On-Premise)
1 parent 59e0a6e commit c03d320

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v1.0.8
2+
- Add function `set_api_url` to set the Carbone API URL
3+
14
### v1.0.7
25
- Fix install script https://github.com/carboneio/carbone-sdk-python/issues/7
36
- Add function `get_status` to get the Carbone API status

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import carbone_sdk
2929
# The access token can be passed as an argument to the constructor CarboneSDK
3030
# Or by the environment variable "CARBONE_TOKEN", use the command "export CARBONE_TOKEN=secret-token"
3131
csdk = carbone_sdk.CarboneSDK("secret-token")
32-
# Set API version
32+
# Set API version (default : 4)
3333
csdk.set_api_version("4")
34+
# Set API URL for Carbone On-Premise for example (default: "https://api.carbone.io")
35+
csdk.set_api_url("https://api.carbone.io")
3436

3537
# The template ID, it could be an ODT, DOCX, PPTX, XLSX, ODS file, etc...
3638
template_id = "template"

carbone_sdk/carbone_sdk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ def set_api_version(self, api_version = None):
7777
else:
7878
raise ValueError('Carbone SDK set_api_version error: an argument is invalid: api_version is not a number nor a string')
7979

80+
def set_api_url(self, api_url = None):
81+
if api_url is None:
82+
raise ValueError('Carbone SDK set_api_url error: argument is missing: api_url')
83+
if isinstance(api_url, str):
84+
self._api_url = api_url
85+
else:
86+
raise ValueError('Carbone SDK set_api_url error: an argument is invalid: api_url is not a string')
87+
8088
def render(self, file_or_template_id = None, json_data = None, payload = ""):
8189
if file_or_template_id is None:
8290
raise ValueError('Carbone SDK render error: argument is missing: file_or_template_id')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="carbone-sdk",
8-
version="1.0.7",
8+
version="1.0.8",
99
author="CarboneIO",
1010
author_email="support@carbone.io",
1111
description="Carbone API Python SDK to generate documents (PDF, docx, xlsx, ods, odt, ...) from a JSON and a template.",

tests/test_carbone_sdk.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def test_set_api_version_error_missing_version(self, csdk):
5454
csdk.set_api_version()
5555
assert e.value.args[0] == 'Carbone SDK set_api_version error: argument is missing: api_version'
5656

57+
def test_set_api_url_error_missing_url(self, csdk):
58+
with pytest.raises(ValueError) as e:
59+
csdk.set_api_url()
60+
assert e.value.args[0] == 'Carbone SDK set_api_url error: argument is missing: api_url'
61+
62+
def test_set_api_url(self, csdk):
63+
new_url = "http://localhost:3000"
64+
csdk.set_api_url(new_url)
65+
assert csdk._api_url == "http://localhost:3000"
66+
5767
class TestRender:
5868
def test_render_a_report_error_file_missing(self, csdk):
5969
with pytest.raises(ValueError) as e:

0 commit comments

Comments
 (0)