@@ -151,7 +151,7 @@ def get(self):
151151 for thing in self .things .get_things ():
152152 description = thing .as_thing_description ()
153153 description ['href' ] = thing .get_href ()
154- description ['forms ' ].append ({
154+ description ['links ' ].append ({
155155 'rel' : 'alternate' ,
156156 'href' : '{}{}' .format (ws_href , thing .get_href ()),
157157 })
@@ -243,7 +243,7 @@ def get(self, thing_id='0'):
243243 )
244244
245245 description = self .thing .as_thing_description ()
246- description ['forms ' ].append ({
246+ description ['links ' ].append ({
247247 'rel' : 'alternate' ,
248248 'href' : '{}{}' .format (ws_href , self .thing .get_href ()),
249249 })
@@ -419,6 +419,36 @@ def get(self, thing_id='0'):
419419 self .set_header ('Content-Type' , 'application/json' )
420420 self .write (json .dumps (thing .get_properties ()))
421421
422+ def put (self , thing_id = '0' ):
423+ """
424+ Handle a PUT request.
425+
426+ thing_id -- ID of the thing this request is for
427+ """
428+ thing = self .get_thing (thing_id )
429+ if thing is None :
430+ self .set_status (404 )
431+ return
432+
433+ try :
434+ properties = json .loads (self .request .body .decode ())
435+ except ValueError :
436+ self .set_status (400 )
437+ return
438+
439+ for property_name , value in properties .items ():
440+ if thing .has_property (property_name ):
441+ try :
442+ thing .set_property (property_name , value )
443+ except PropertyError :
444+ self .set_status (400 )
445+ return
446+ else :
447+ self .set_status (404 )
448+ return
449+
450+ self .set_status (204 )
451+
422452
423453class PropertyHandler (BaseHandler ):
424454 """Handle a request to /properties/<property>."""
@@ -466,8 +496,7 @@ def put(self, thing_id='0', property_name=None):
466496 self .set_status (400 )
467497 return
468498
469- self .set_header ('Content-Type' , 'application/json' )
470- self .write (json .dumps (thing .get_property (property_name )))
499+ self .set_status (204 )
471500 else :
472501 self .set_status (404 )
473502
@@ -570,6 +599,7 @@ def post(self, thing_id='0', action_name=None):
570599 return
571600
572601 # Allow payloads wrapped inside `value` field
602+ #TODO: remove this in the future
573603 if 'value' in input_ :
574604 input_ = input_ ['value' ]
575605
0 commit comments