Skip to content

Commit 12ffc44

Browse files
committed
fix: improve examples & github readme
1 parent 38b985a commit 12ffc44

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

Client/Client/examples/contexts_provided_by_resolver_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Example of usage of Protection and Deprotection of few RPSValues,
22
using the contexts name instead of objects"""
3+
from Client.context_source import ContextSource
34
from Client.instance.rps_instance import RPSInstance
45
from Client.engine.engine_factory import EngineFactory
56
from Client.request_context import RequestContext
@@ -11,7 +12,7 @@ class ContextsProvidedByResolverExample:
1112
and printing results from RPS Engine
1213
"""
1314

14-
__engine = EngineFactory.get_engine()
15+
__engine = EngineFactory.get_engine(context_source=ContextSource.JSON)
1516

1617
if __name__ == "__main__":
1718

Client/Client/examples/simple_usage_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Simple example of usage of Protection and Deprotection of few RPSValues."""
2+
from Client.context_source import ContextSource
23
from Client.engine.engine_factory import EngineFactory
34
from Client.instance.rps_instance import RPSInstance
45
from Client.engine_context.processing_context import ProcessingContext
@@ -12,7 +13,7 @@ class SimpleUsageExample:
1213
"""Simple example of Protection and Deprotection and
1314
printing results from RPS Engine
1415
"""
15-
__engine = EngineFactory.get_engine()
16+
__engine = EngineFactory.get_engine(context_source=ContextSource.JSON)
1617

1718
if __name__ == "__main__":
1819

Client/Client/examples/usage_with_dependencies_example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example of usage of Protection of RPSValues with Dependencies"""
2+
from Client.context_source import ContextSource
23
from Client.instance.rps_instance import RPSInstance
34
from Client.engine.engine_factory import EngineFactory
45
from Client.value.rps_value import RPSValue
@@ -8,13 +9,13 @@ class UsageWithDependenciesExample:
89
"""Example of Protection of RPSValues with Dependencies,
910
and printing results from RPS Engine"""
1011

11-
__engine = EngineFactory.get_engine()
12+
__engine = EngineFactory.get_engine(context_source=ContextSource.JSON)
1213

1314
if __name__ == "__main__":
1415

1516
print('--- Example of protection with dependencies ---')
1617

17-
# Create RPS Value with dependency
18+
# Create RPS Value with dependency - see https://demo.rpsprod.ch/community/library/rps-value
1819
payment_date = RPSValue(instance=RPSInstance(className='Payment', propertyName='Date'),
1920
originalValue='02.11.2021',
2021
dependencies={

Client/Client/examples/usage_with_related_object_example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Example of usage of Protection of RPSValues received from external file"""
22
import os
3+
from Client.context_source import ContextSource
34
from Client.engine.engine_factory import EngineFactory
45
from Client.instance.rps_instance import RPSInstance
56
from Client.extensions.json_extensions import get_json_from_file
@@ -11,7 +12,7 @@ class UsageWithRelatedObjectExample:
1112
"""Example of Protection of RPSValues received from external file,
1213
and printing results from RPS Engine
1314
"""
14-
__engine = EngineFactory.get_engine()
15+
__engine = EngineFactory.get_engine(context_source=ContextSource.JSON)
1516

1617
__example_json_file_path = os.path.join(
1718
os.path.dirname(__file__),
@@ -38,8 +39,8 @@ class UsageWithRelatedObjectExample:
3839
# Protect Request
3940
request_context: RequestContext = __engine.create_context().with_request_by_context_names(
4041
rps_values=rps_values,
41-
rights_context_name="TransformRegTAX",
42-
processing_context_name="ProtectRegTAX")
42+
rights_context_name="Admin",
43+
processing_context_name="Protect")
4344

4445
request_context.transform_async()
4546

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2-
"Name": "Jonny",
3-
"Date": "3010-10-01"
4-
}
2+
"FirstName": "Jonny",
3+
"LastName": "Silverhand",
4+
"Email": "test@example.com",
5+
"Phone": "123-456-7890",
6+
"ISIN":"DE1234567890",
7+
"BirthDate": "3010-10-01"
8+
}

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ Must be a valid JSON syntax for more complex or nested configuration. Using doub
6868
"clientSecret": "YOUR_CLIENT_SECRET",
6969
"timeout": 30
7070
},
71-
// Specify either the "external_source_files" section or the "rights_contexts" & "processing_contexts", according to the contexts source
71+
// Specify either the "external_source_files" section -> `ContextSource.JSON`
72+
// Or the "rights_contexts" & "processing_contexts" sections -> `ContextSource.SETTINGS`
7273
"external_source_files": {
7374
"rightsContextsFilePath": "path/to/rights_contexts.json",
7475
"processingContextsFilePath": "path/to/processing_contexts.json"
@@ -108,43 +109,40 @@ rps__clientId="YOUR_CLIENT_ID"
108109
rps__clientSecret="YOUR_CLIENT_SECRET"
109110
rps__timeout=30
110111

111-
// One of the followings:
112+
// One of the followings, `ContextSource.JSON`
112113
external_source_files__rightsContextsFilePath=path/to/rights_contexts.json
113114
external_source_files__processingContextsFilePath=path/to/processing_contexts.json
114115

115-
// OR
116+
// or `ContextSource.SETTINGS`
116117
rights_contexts__Admin__evidences__0__name="Role"
117118
rights_contexts__Admin__evidences__0__value="Admin"
118-
119-
processing_contexts__Protect__evidences__0__name=Action
120-
processing_contexts__Protect__evidences__0__value=Protect
121-
processing_contexts__Deprotect__evidences__0__name=Action
122-
processing_contexts__Deprotect__evidences__0__value=Deprotect
119+
processing_contexts__Protect__evidences__0__name="Action"
120+
processing_contexts__Protect__evidences__0__value="Protect"
121+
processing_contexts__Deprotect__evidences__0__name="Action"
122+
processing_contexts__Deprotect__evidences__0__value="Deprotect"
123123
```
124124

125125
## Examples of usage
126126

127127
The examples folder contains several ready-to-run scripts that demonstrate different usage scenarios of the RPS Engine client. Each example is designed to help you understand how to configure, invoke, and extend the client for your own use cases. Below is a brief explanation of each example:
128128

129129
- [`SimpleUsageExample`](Client/Client/examples/simple_usage_example.py)
130-
Demonstrates the most basic workflow: manually creating rights and processing contexts, constructing RPSValue objects, and performing protection and deprotection operations. This is a good starting point for understanding the core API and data flow.
130+
demonstrates the most basic workflow: manually creating rights and processing contexts, constructing RPSValue objects, and performing protection and deprotection operations. This is a good starting point for understanding the core API and data flow.
131131

132132
- [`ContextsProvidedByResolverExample`](Client/Client/examples/contexts_provided_by_resolver_example.py)
133-
shows how to use context names instead of full context objects. The example leverages the context resolver to fetch rights and processing contexts by name, simplifying the request construction process.
133+
shows how to use context names instead of full context objects. The example leverages the context resolver to fetch rights and processing contexts by their names, simplifying the request construction process.
134134

135135
- [`UsageWithDependenciesExample`](Client/Client/examples/usage_with_dependencies_example.py)
136-
Illustrates how to handle RPSValue objects that have dependencies (such as minimum or maximum values). This is useful for scenarios where the transformation logic depends on related data fields.
136+
illustrates how to handle RPSValue objects that have dependencies (such as minimum or maximum values). This is useful for scenarios where the transformation logic depends on related data fields.
137137

138138
- [`UsageWithRelatedObjectExample`](Client/Client/examples/usage_with_related_object_example.py)
139-
Demonstrates how to load data from an external JSON file, convert it into RPSValue objects, and perform protection operations. This example is ideal for batch processing or integrating with external data sources.
139+
demonstrates how to load data from an external JSON file, convert it into RPSValue objects, and perform protection operations. This example is ideal for batch processing or integrating with external data sources.
140140

141141
**Each example is self-contained and can be run directly.** Review and adapt these scripts to accelerate your own integration with the RPS Platform.
142142

143143
```powershell
144144
poetry run python client/examples/usage_with_related_object_example.py
145145
```
146-
---
147-
148146

149147
# Contribute
150148
To add libraries update the **dependencies** section in the ``pyproject.toml``
@@ -165,3 +163,6 @@ To install the dependencies update the peotry.lock with poetry
165163
```
166164
poetry lock
167165
```
166+
167+
# Additional Resources
168+
See [REGDATA RPS Community](https://demo.rpsprod.ch/community/platform) for further integrations and documentation.

0 commit comments

Comments
 (0)