diff --git a/temba_client/v2/__init__.py b/temba_client/v2/__init__.py index b4b0678..85f6563 100644 --- a/temba_client/v2/__init__.py +++ b/temba_client/v2/__init__.py @@ -8,6 +8,7 @@ Channel, Classifier, Contact, + Export, Field, Flow, FlowStart, @@ -125,6 +126,17 @@ def get_contacts(self, uuid=None, urn=None, group=None, deleted=None, before=Non ) return self._get_query("contacts", params, Contact) + def get_definitions(self, flows=(), campaigns=(), dependencies=None): + """ + Gets an export of specified definitions + :param flows: flow objects or UUIDs to include + :param campaigns: campaign objects or UUIDs to include + :param dependencies: whether to include dependencies + :return: definitions export + """ + params = self._build_params(flow=flows, campaign=campaigns, dependencies=dependencies) + return Export.deserialize(self._get_raw("definitions", params)) + def get_fields(self, key=None): """ Gets all matching contact fields diff --git a/temba_client/v2/tests.py b/temba_client/v2/tests.py index 6b66f40..678144b 100644 --- a/temba_client/v2/tests.py +++ b/temba_client/v2/tests.py @@ -425,6 +425,29 @@ def test_get_contacts(self, mock_request): }, ) + def test_get_definitions(self, mock_request): + mock_request.return_value = MockResponse(200, self.read_json("definitions")) + + # check with all params + definitions = self.client.get_definitions( + flows=["04a4752b-0f49-480e-ae60-3a3f2bea485c", "ffce0fbb-4fe1-4052-b26a-91beb2ebae9a"], + campaigns=[], + dependencies=False, + ) + + self.assertRequest( + mock_request, + "get", + "definitions", + params={ + "flow": ["04a4752b-0f49-480e-ae60-3a3f2bea485c", "ffce0fbb-4fe1-4052-b26a-91beb2ebae9a"], + "campaign": [], + "dependencies": 0, + }, + ) + + self.assertEqual(definitions.version, "10.1") + def test_get_fields(self, mock_request): # check no params mock_request.return_value = MockResponse(200, self.read_json("fields")) diff --git a/temba_client/v2/types.py b/temba_client/v2/types.py index f1af8e5..4b2e131 100644 --- a/temba_client/v2/types.py +++ b/temba_client/v2/types.py @@ -125,6 +125,14 @@ class Contact(TembaObject): last_seen_on = DatetimeField() +class Export(TembaObject): + version = SimpleField() + flows = ListField() + campaigns = ListField() + triggers = ListField() + fields = ListField() + groups = ListField() + class Field(TembaObject): key = SimpleField() name = SimpleField()