Пример #1
0
	def Post( self ):
		logging.debug( "CallbackHandler Post()" )
		logging.debug( "Callback headers: " + str( self.request.headers ) )
		logging.debug( "Callback POST: " + str( self.request.POST ) )
		logging.debug( "Callback body: " + str( self.request.body ) )
		
		# First authenticate that the request was made by facebook
		import hmac
		import hashlib
		
		calculatedSha = "sha1=" + hmac.new( secrets.facebook.APP_SECRET, str( self.request.body ), hashlib.sha1 ).hexdigest()
		receivedSha = self.request.headers[ 'X-Hub-Signature' ]
		
		if calculatedSha == receivedSha:
			logging.debug( "Calculated SHA (" + calculatedSha + ") matches received SHA" )
			
			requestData = stringToJson( self.request.body )
			
			if requestData[ 'object' ] == "user":
				for entry in requestData[ 'entry' ]:
					if "events" in entry[ 'changed_fields' ]:
						fbuid = entry[ 'uid' ]
						
						logging.debug( "Checking subscription data for user: "******"Updating events for user: " + str( fbuid ) )
							
							events.Fetch( fbSub.watchToken, fbuid )
			
			self.response.status = requests.codes.ok
		
		else:
			self.response.status = requests.codes.unauthorized
Пример #2
0
    def WatchInfo(self, params):
        logging.debug("WatchInfo(): " + str(self.request.body))

        # Convert supplied json data to usable object
        watchInfo = stringToJson(self.request.body)
        logging.debug("WatchInfo(): " + str(watchInfo))

        # Store the data for later analysis
        storage.StoreHardwareInfo(self.request.headers["X-User-Token"], watchInfo)

        # Standard success response
        self.response.data = {"status": "success"}
Пример #3
0
	def post( self, pebbleToken ):
		
		if pebbleToken is None or pebbleToken == "undefined":
			self.response.set_status( codes.unauthorized )
			return
		
		logging.debug( "Saving settings for user: "******"Settings JSON: " + str( self.request.body ) )
		
		from json import loads as stringToJson
		data = stringToJson( self.request.body )
		
		fb( data[ "fbev" ], pebbleToken )
		tvst( data[ "tvst" ], pebbleToken )
		
		self.response.set_status( codes.ok )