add `result` object wrapper for `personalise` calls
The personalise
call returns a JSON payload (in case successful). The current implementation simply passes this JSON (although parsed to a Dictionary
) to the developer code. This makes the developer implementation intertwined with the Primed result format: this is brittle and may cause issues down the line.
To pre-empt this, we should wrap the result Dictionary
in a ResultSet object (composed of ResultRecord objects) that exposes one property for the moment: results
. Each of the ResultRecord objects exposes the target key and target value respectively.
Pseudo (Python) code:
class ResultRecord:
def __init__(self, key, value):
self.key = key # string
self.value = value # dictionary
class ResultSetWrapper:
def __init__(self, results):
self.results = [ResultRecord(t["target"]["key"], t["target"]["value"]) for t in results]
jsondata = personalise(campaign="mycampaign", signals={"signalKey"; "signalValue"}, abvariant="A")
rsw = ResultSetWrapper(jsondata["results"])
# Now we can use the ResultSetWrapper as follows:
for result in rsw.results:
print(result.key, result.value)