'''
resources = {"m2m:ae", "m2m:cnt", "m2m:cin", "m2m:sub",
- "m2m:acp", "m2m:nod", "m2m:grp"}
+ "m2m:acp", "m2m:nod", "m2m:grp", "m2m:cb", "ch"}
payload_map = {1: acp_payload, 2: ae_payload, 3: con_payload,
4: cin_payload, 14: nod_payload, 23: sub_payload}
-def find_key(response, key):
+def find_key(response, key, first=None):
"""Deserialize response, return value for key or None."""
dic = response.json()
key1 = list(dic.keys())
raise ValueError("The response should be json object")
if key1[0] not in resources:
raise ValueError("The resource is not recognized")
- return dic.get(key1[0], None).get(key, None)
+ if first is True:
+ return dic.get(key1[0], None)
+ else:
+ return dic.get(key1[0], None).get(key, None)
+
+
+def childResource(response):
+ """Return child resources from the response."""
+ return find_key(response, "ch")
+
+
+def childResourceFirst(response):
+ """Return child resources from the response."""
+ return find_key(response, "ch", True)
def name(response):
return find_key(response, "lt")
+def stateTag(response):
+ """Return the state tag from the response."""
+ return find_key(response, "st")
+
+
def resid(response):
"""Return the resource id in the response."""
return find_key(response, "ri")
return find_key(response, "rty")
+def currentNumberOfInstances(response):
+ """Return current number of instances from the response."""
+ return find_key(response, "cni")
+
+
+def currentByteSize(response):
+ """Return current byte size from the response."""
+ return find_key(response, "cbs")
+
+
+def maxNumberOfInstances(response):
+ """Return max number of instances from the response."""
+ return find_key(response, "mni")
+
+
+def maxByteSize(response):
+ """Return max byte size from the response."""
+ return find_key(response, "mbs")
+
+
def status(response):
"""Return the protocol status code in the response."""
try:
# and until a proper defaulting initializer is in place
# are hard-coded.
'content-type': 'application/vnd.onem2m-res+json',
- 'X-M2M-Origin': '//localhost:10000',
+ 'X-M2M-Origin': 'iotdm-robot-tests',
'X-M2M-RI': '12345',
'X-M2M-OT': 'NOW'
}