Esempio n. 1
0
            #new_object = FlatJSON(new_object,keys)
            print '\n\nalias:',new_object[u'aliases'][0],'is new.'
            # test the new object
            if ValidJSON(object_schema,object_type,object_id,new_object,keys):
            	# post the new object(s). SHOULD HANDLE ERRORS GRACEFULLY
                new_object = CleanJSON(new_object,object_schema,'POST')
                response = new_ENCODE(object_type,new_object,keys)
		#print response['status']
		if response['status'] == 'success':
			object_check = GetENCODE(str(response[u'@graph'][0][u'@id']),keys)
	         #	print object_check
			print 'uuid:', object_check[u'uuid']
                        filename.write(str(new_object['aliases'][0])+'\t'+str(object_check['uuid'])+'\n')
			posted_objects.append(object_check)
                elif response['status'] == 'error':
			new_object.update({'description':response['description']})
			new_object.update({'errors':response['errors']})
			new_object.update({'object_type':object_type})
			error_objects.append(new_object)
                else:
                    sys.exit()    
        # if object is found, check for differences and patch it if needed/valid.
        elif put_status:
            # clean object of unpatchable or nonexistent properties. SHOULD INFORM USER OF ANYTHING THAT DOESN"T GET PUT.
            new_object = CleanJSON(new_object,object_schema,'POST')
            #new_object = FlatJSON(new_object,keys)
            print('Running a put.')
            response = replace_ENCODE(object_id,new_object,keys)
        else:
            # clean object of unpatchable or nonexistent properties. SHOULD INFORM USER OF ANYTHING THAT DOESN"T GET PATCHED.
            new_object = CleanJSON(new_object,object_schema,'PATCH')